Erik van Gerven
Member
My latest project must run om a Lipo batterywithout internal protection circuit
Charging will be done by a chinese circuit costs €1.50 and has a protection circuit, charging the LiPo to 4.2 volts max.
That's the easy part.
Discharging is a bit more difficult because 3.0 volts is the absolute minimum voltage on a Lipo
The load is behind the protection circuit, so this won't help me. So I need to measure the voltage of the battery
I made a 1.3 volts reference voltage (20M) on pin b.3 by a resistor of 1 K through 2 diodes to ground
A signalling LED is connected to pin b.2
Measuring takes place by comparing VCC to a reference
We will use readadc10 that gives a value of 0-1023 for a voltage from 0-vcc
At VCC =4.1 volts, the value 1 stands for 0.004 volts
At VCC =3.0 volts, the value 1 stands for 0.003 volts
So at readadc10 (where the 1.3 referencevoltage is measured we will see:
at 4.1 volts: 1.3/0.004 = 325
at 3.0 volts: 1.3/0.003 = 433
at 2.95 volts 1,3/0.0028 = 450
For low voltage, I used the higher value (450) in the program
the difference is 125
Finally we get a value from 100 to 0 percent of the remaining available energy in the battery
As we reach zero, the picaxe shuts itself down until it is switched off and on again
shdn will count 100 low battery measurements before the shutdown is performed
Have fun with this.
Regards,
Erik
This goes in your main loop
The shutdown routine:
Charging will be done by a chinese circuit costs €1.50 and has a protection circuit, charging the LiPo to 4.2 volts max.
That's the easy part.
Discharging is a bit more difficult because 3.0 volts is the absolute minimum voltage on a Lipo
The load is behind the protection circuit, so this won't help me. So I need to measure the voltage of the battery
I made a 1.3 volts reference voltage (20M) on pin b.3 by a resistor of 1 K through 2 diodes to ground
A signalling LED is connected to pin b.2
Measuring takes place by comparing VCC to a reference
We will use readadc10 that gives a value of 0-1023 for a voltage from 0-vcc
At VCC =4.1 volts, the value 1 stands for 0.004 volts
At VCC =3.0 volts, the value 1 stands for 0.003 volts
So at readadc10 (where the 1.3 referencevoltage is measured we will see:
at 4.1 volts: 1.3/0.004 = 325
at 3.0 volts: 1.3/0.003 = 433
at 2.95 volts 1,3/0.0028 = 450
For low voltage, I used the higher value (450) in the program
the difference is 125
Finally we get a value from 100 to 0 percent of the remaining available energy in the battery
As we reach zero, the picaxe shuts itself down until it is switched off and on again
shdn will count 100 low battery measurements before the shutdown is performed
Have fun with this.
Regards,
Erik
This goes in your main loop
Code:
;it's good practice to claim all variables used in your program
symbol batt=w1 ;Here comes the ADC reading
symbol shdn=w2 ;a treshold counter to fill
symbol tmp=w3 ;a disposable container for for-next-loops etc
main:
pause 1000 ;here you put your program code
low b.0 ;switch off LED
readadc10 b.3,batt ;measure 1.3v ref to battery
if batt < 450 then ;when using in a loop you can use a counter
shdn=shdn+1
end if
if batt > 449 then
shdn=shdn-1
end if
;calculating a percentage from 'batt'
;next 4 lines can be omitted if not needed
batt=batt-325 ;vcc 4.1v=325 vcc=3.0v=450 (difference=125)
batt=125-batt ;offset to zero
batt=batt*8 ;make it a promillageage (0-1000)
batt=batt/10 ;make it a percentage (0-100%)
; batt is representing a percentage of available energy in the battery here
; it can be used for display purposes
if shdn >200 then ;prevent counting down below zero (65535)
shdn=0
end if
if shdn>100 then ;only after 100 low bat measurements we shut
goto shutdown
end if
debug ;to be omitted in final version
goto main
Code:
shutdown: ;in battery low condition this routine is hit
;to protect the LiPo battery
for tmp=1 to 10 ;slow flash led 10 times
high b.0 ;to indicate shutdown
pause 1000 ;totally useless :-)
low b.0
pause 1000
next tmp
sleep 0 ;processor shutdown, reset by powerflip
; hibernate 0 ;better way on some picaxes
end
Last edited: