rem "Charger.BAS" 7/9/2007 rem Up to 1 amp for batteries from 1.4 to 12 volts rem Usually used with gel cel lead-acid batteries rem Needs mod and reloading for different voltages. rem Has output for the Secure Digital Writer. rem Current reduces when charged. #PICAXE 8M init: symbol Phase = bit0 symbol Connected = bit1 symbol Charging = bit2 symbol Cycles = b1 symbol Seconds = b2 symbol Minutes = b3 symbol FileNo = b4 symbol MaxVolts = b5 symbol ADCValue = w6 symbol Amps = b6 symbol Volts = b7 symbol PWMCharging = 310 '14,6V symbol PWMFloating = 287 '13.5 V rem symbol PWMCharging = 120 '4,6V rem PWMFloating = 115 '4.4V symbol PWMPeriod = 80 Data 0,(101) read 0,FileNo pwmout 2,80,PWMCharging looping: if Phase = Pin3 then looping let Phase = Pin3 let Cycles = Cycles + 1 if Cycles < 10 then looping let Cycles = 0 readadc10 4,ADCValue 'amps value,goes negative, 2MA/count if ADCvalue > 10 then AmpsValid if Connected = 0 then looping let Connected = 0 let Charging = 0 goto looping AmpsValid: let ADCValue = 1024 - ADCValue let Amps = ADCValue/5 ' in steps of 10 ma readadc10 1,ADCValue '15V,15mV/count let Volts = ADCValue * 3 / 20 ' in steps of 100 mv if Connected =1 then AlreadyConnected let Connected = 1 let FileNo = FileNo + 1 write 0, FileNo let Charging = 1 let MaxVolts = 0 let Seconds = 0 let Minutes = 0 low 0 pwmout 2,80,PWMCharging AlreadyConnected: if Volts < MaxVolts then Sectest let MaxVolts = Volts goto Update let b11 = Volts - MaxVolts if b11 < 3 then Update let Charging = 0 pwmout 2,80,PWMFloating high 0 Update: if Connected = 0 then Sectest if Seconds = 0 then SDTimeout if Seconds = 1 then Openfile if Seconds = 2 then Writefile if Seconds = 3 then Closefile Sectest: let Seconds = Seconds + 1 if Seconds < 60 then looping let Seconds = 0 let Minutes = Minutes + 1 goto looping Openfile: setfreq m8 sertxd ("O 1 A /P",#FileNo,".CSV",13) setfreq m4 goto Sectest WriteFile: 'Writes the data or heading setfreq m8 sertxd ("W 1 14",13,#Minutes,",",#Volts,",",#Amps,13,10) setfreq m4 goto Sectest Closefile: setfreq m8 sertxd ("C 1",13) setfreq m4 goto Sectest SDTimeout: setfreq m8 sertxd ("S 1 5",13) setfreq m4 goto Sectest