Figure 10 – On
Battery_Voltage loop where Q1 is turned OFF by setting
its base resistor LOW. The LED is also extinguished. The
routine does an A/D conversion of the battery voltage. If
the voltage is above the full discharge voltage specified by
the constant “fullDischargeVolts” in millivolts, nothing
happens and the firmware loops back to the Test_Battery
_Voltage label. If and when the battery voltage drops to,
or below, the fullDischargeVolts level, the firmware
Figure 11 - On Demand
branches to the Charge_Battery label.
At this point, Q1 is turned ON and several things are
set into motion. First, the LED is illuminated indicating
charging is taking place. At the same time, an “energy
loop” is initiated that guarantees a minimum amount of
charge, C, going into the battery (and maybe also into the
load if one is connected). The energy loop consists of a
60 second time sample coupled with measuring the
current flow into the battery. With it, we want to charge
the battery with at least 0.05C (1/20 C) before exiting the
For example, a constant called “minEnergy” is
established in the first part of the code that represents
0.05C of the battery. For our test battery, this is 122.5
mAh ( 2,450 mAh x 0.05 = 122.5 mAh). You can adjust
this to any level based on your particular battery’s
capacity and/or solar panel output. Because we are using
a 60 second sampling loop, we need to convert mAh into
mAm or milli-Amp-minutes. Since there are 60 minutes to
an hour, we need to multiply the 0.05C value by 60. In
our case, that would be 122.5 x 60 which makes our
minEnergy value = 7,350 mAm. So, every 60 seconds the
code will sample the current, add it to the previous
current sample, and compare this value to minEnergy.
Once the minEnergy value is achieved, the next part of
the algorithm is engaged.
Next we look at the battery voltage at the
Verify_Battery_Charged label. If it is at or above the
fullChargeVolts, then we branch back to the Test_
Battery_Voltage label and the process starts all over again.
However, if the battery is still below the fullChargeVolts
level — maybe due to a heavy load draining it as it tries to
charge — the firmware stays in the Charge_Battery loop
(with Q1 ON) until the fullChargeVolts level is reached (if
ever, depending on the load and the sunlight striking the
solar panel). The LED flashes (toggle instruction) to let you
know that we are in the Verify_Battery_Charged loop.
And that’s it; that’s our “on-demand” battery charging
algorithm that should keep our NiMH battery active
without ever reaching full charge or overcharging, but
always with enough energy to do the job of powering our
load. Of course, you can change any of the constants and
variables to match what YOU want the charger to do, like
apply a deeper charge or change the voltage trip points.
Remember, this is your experiment. I’m only here to give
The Middle Multiply Operator (*/)
Cell Equivalent Circuit
In all the firmware code in all the experiments, I
convert A/D counts directly to millivolts and milliamps.