After some refinements to the code:
Strangely, it's taking nearly the same amount of time — 204 minutes, but then this is a different kind of LiFePO4 cell. The earlier graph was for the new FE105 cells from DMEX/MDS Enterprises, this graph is for the older FE105C cells from the MuscleGrid battery. I'll retest one of the new cells later on and see if there's any improvement there.
I also changed the way the digital pot was wired up, but first the code:
Code:
Rule1
ON System#Init DO BACKLOG Sensor13 0, 1, 0.0015; Power3 1; Power2 1; Rule2 1; Rule3 0; Teleperiod 10 ENDON
ON INA219-2#Current>46 DO BACKLOG Power1 0; Power2 0; Power2 1; Rule3 0 ENDON
Rule2
ON INA219-1#Voltage>3.6 DO BACKLOG Power1 0; Power2 0; Power3 0; Rule2 0; Rule3 0; Teleperiod 60 BREAK
ON Rules#Timer=1 DO BACKLOG Power1 1; Power2 0; Power2 1; Rule3 1 BREAK
ON Time#Minute DO Rule3 1 ENDON
Rule3
ON INA219-2#Current>36 DO Rule3 0 BREAK
ON INA219-1#Voltage<3.6 DO BACKLOG RuleTimer1 1; Rule3 0 BREAK
A quick summary:
Rule set #1 is for code that needs to be run, no matter under what conditions. So it's setting the Shunt Resistor value (Sensor13), turning on the power (Power3), bringing the increment pin high (Power2), turning on the second rule set, turning off the third rule set, and setting the MQTT update period to 10 seconds for finer granularity in the reporting/graphs. The over-current protection is also in this rule set.
Rule set #2 does three things, and they all need to be disabled if the battery is fully charged. The first is the high voltage cut off and changing the MQTT update period to 60 seconds since there's not much that needs to be recorded after a full charge. The command is extra long because we're turning off all the outputs as a visual aid in the webui that charging is complete. The second is to increment the voltage (thereby the current flow) when Rules#Timer=1 ends. The third is to activate Rule set #3 every minute.
Rule set #3 does two things, the first is nothing at all, stop and do not proceed, if current is over 36A (90% of the rated output). Otherwise, it'll trigger Rules#Timer=1 with a duration of 1 second.
This loop of Rules#Timer=1 between the second and third ruleset is necessary to slow down the incrementation, otherwise it'll increment as fast as the sensor refreshes which may overload the microcontroller or trigger the OCP before feedback is recorded by the INA219 sensor. Without this delay, it'll go through all of the hundred steps of the digital pot in 76 seconds. With this one second delay, it's lengthened to a few minutes.
The proto-prototype:
That's the Wemos D1 mini on a prototyping pcb in a little food container.
These are the two INA219 modules:
The trace of VIN- is cut in one of them and that pin is shorted to ground for easier wiring directly from the 6 pin header to the output of the power supply. This also ties the ground of the power supply with the ground of the ESP8266 module, necessary to measure the voltage.
The other module has the shunt resister removed and the I2C address changed with a solder blob. Tasmota recognises the unmodified module as 1 and the modified one as 2, it can recognize upto four (short A1 instead of A0 for the 3rd and short both A0 and A1 for the 4th).
The 5V relay module is covered in transparent heatshrink for safety, this module has a physical cut in the PCB separating the high side from the low side.
This is the digital pot module, I love this thing:
And the inline resistor to make sure the voltage doesn't exceed the safe maximum (lower the resistor = higher the voltage, so when the digital pot is at 0, the minimum resistance is 150E, which is this resistor):
The digital pot X9C103S is 10k from end to end, with 100 steps. The wiper has a separate resistance of 40E. So each step is 0.1K or 100E. In the previous graph, there were just three increments needed, the last three, so from 97 to 100, to adjust the current flow. That was with three series 510E resisters wired in parallel to the digital pot:
Those last three steps add up to 300E, it would be nice to have more granularity there.
So what I did was tie both ends of the digital pot together, making it appear as if it was two 5k resistors in parallel, this brought the resistance down to 2.5K. So now, the wiper would travel from 0 to 2.5k and back to 0. Each step now is 2500 x 2 / 100 = 50E. A little better, with now 6 steps in a 300E range.
You can see those six steps here as peaks, the dot is one of those six steps:
Then I added a 3.3K resistor in parallel to the wiper and one of the ends, to get the value down to 1.4K. I would like even more steps but this'll do for now.
The CS pin was disconnected from ground and connected to GPIO15 pin. The CS pin, when pulled high, will set a default state for the digital pot. This is needed for calibration since we don't want the voltage going from high to low to high again or vice verse. So I manually toggled the increment pin until I got the lowest voltage and then toggled the GPIO15/CS pin to set that value as the starting point.
I'll revisit this battery charger project later, next is to start making my own Tasmota-based BMS.