;; Smart Battery Charger; Free Project Series; Aztec MCU Prototyping; www.aztecmcu.com; For use with the Smart Battery Charger schematic; This is the code for a Lead Acid type battery charging protocol; This code was written for a PICAXE 20M2;; C.0 is connected to a RED LED; C.1 is connected to a GREEN LED; C.2 is connected to a BLUE LED; C.7 is connected to the Voltage Divider module to detect the voltage on the charger output; B.0 is connected to the Relay Module; B.1 is connected to input B of the Regulator Module; B.2 is connected to input A of the Regulator ModuleGosub Init ; Go initialize the regulatorMain: readadc10 C.7, w1 if w1 < 100 then gosub NoBat if w1 > 99 and w1 < 525 then gosub BadBat if w1 > 524 and w1 < 630 then gosub Charge if w1 > 629 then gosub NoCharge Goto Main;NoBat - It we read under 2 volts, we are going to;assume there is no battery attached. Just blink the;BLUE LEDNoBat: low c.0 low c.1 high c.2 pause 500 ; wait a bit low c.2 pause 500 return ;BadBat- This is a 12V battery charger so, If the;battery is between 2 and 10.5 volts, we assume;it is bad and cannot be charged. Flash all the;LEDs BadBat: high c.0 high c.1 high c.2 pause 200 ; wait a bit low c.0 low c.1 low c.2 pause 200 return;NoCharge - called when the battery does not;need to be charged. Just blink the GREEN LEDNoCharge: low c.0 high c.1 low c.2 pause 500 low c.1 pause 500 return;Charge - Main charging routineCharge: high c.0 ;Turn on the RED LED gosub CCC ;Start the constant current charge readadc10 c.7, w1 if w1 > 100 then gosub CVC ;If the battery is still connected, start the constant voltage charge low c.0 ;Turn off the RED LED, we are done charging readadc10 c.7, w1 if w1 > 100 then gosub Float ;If the battery is still connected, start the float Gosub Init ;We're all done, reinitialize the system. return;CCC - This is the constant current charge mode. Stay;in this mode as long as the battery is attached and;below 14.4VCCC: high c.2 ;Turn on the BLUE LED high b.0 ;Set the regulator to current mode low b.2 ;Turn on the regulator CCC_ChkV: ;Check the battery voltage readadc10 c.7, w1 if w1 < 720 then goto CCC_ChkV ;If battery less than 14.4V, keep checking high b.2 ;Turn off the regulator low c.2 ;Turn off the BLUE LED low b.0 ;Set the regulator back to voltage mode return;CVC - This is the constant voltage topping charge mode.;Stay in this mode for a fixed time. In this case about;3 hoursCVC: high c.1 ;Turn on the GREEN LED b0=180 ;Set the number of minutes LMin: b1=60 ;Set the number of seconds b0=b0-1 ;Decrement the minute counter LSec: b1=b1-1 ;Decrement the seconds counter low b.2 ;Turn on the regulator pause 1000 ;Wait a second high b.2 ;Turn off the regulator readadc10 c.7, w1 ;Test the battery voltage if w1 > 99 and b1 > 0 then goto LSec ;Go another second if it is still connected if w1> 99 and b0 > 0 then goto Lmin ; Go another minute if it is still connected low c.1 ;Turn off the GREEN LED return;Float - This is the float charge mode. The voltage is reduced;to the float level (13.4V). Stay in this mode as long as the;battery is connected.Float: high c.1 ;Turn on the GREEN LED high b.1 ;Set the regulator to float voltage Flt_ChkV: low b.2 ;Turn on the regulator pause 1000 ;wait a second high b.2 ;Turn off the regulator readadc10 c.7, w1 ;Check the battery voltage if w1 > 99 then goto Flt_ChkV ;Keep on Float if the battery is still connected return;Init - Initialize the regulatorInit: low C.0 ;RED LED off low C.1 ;GREEN LED off low C.2 ;BLUE LED off low B.0 ;Set the Regulator to Voltage Mode low B.1 ;Set the Regulator to Charge Voltage high B.2 ;Set the Regulator to off return
Li batteries generally require more sophisticated charging regimens than lead-acidbatteries. You might do some background research on charging Li batteries beforeproceeding.
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16