' Charge Controller ' Ver 2006C ' www.thebackshed.com Start: SYMBOL Amp = b4 ; Measured Battery Amps SYMBOL Volt = b6 ; Measured Battery Volts SYMBOL CVolt = b7 ; Charging Voltage Level SYMBOL LVolt = b8 ; Load Voltage Level SYMBOL LBatt = b9 ; Low Battery Alarm Level EEPROM 0,( $33 ) EEPROM 1,( $32 ) EEPROM 2,( $28 ) EEPROM 3,( $0C ) EEPROM 4,( $06 ) EEPROM 5,( $01 ) EEPROM 6,("V ") EEPROM 9,("A ") EEPROM 16,("CHARGING") EEPROM 24,("ON LOAD ") EEPROM 32,("Set Load Volts") EEPROM 46,("Set Charge Volts") EEPROM 62,("Forced Load") EEPROM 73,("Forced Charge") EEPROM 86,("LOW BATT") EEPROM 94,("Set Low Batt") read 120,CVolt ' read in Charge volt level saved in eeprom read 121,LVolt ' read in Load volt level saved in eeprom read 122,LBatt ' read in Low Battery volt level saved in eeprom FOR b11 = 0 TO 5 ' Initialise the LCD display READ b11,b12 pause 15 GOSUB SendCmdByte NEXT b12=1 ' set controler to charging mode Gosub SendCmdByte b12 = 192 GOSUB SendCmdByte FOR b11 = 16 TO 23 READ b11,b12 GOSUB SendDataByte NEXT gosub Beep low portc 5 high portc 4 if LVolt=0 then DefaultVolt goto main DefaultVolt: ' This routine sets some default voltages if there are no preset values in the eeprom LVolt=40 ' Set default load voltage to 14.0 write 121,LVolt ' save to eeprom CVolt=22 ' Set default charge voltage to 12.2 write 120,CVolt ' save to eeprom LBatt=12 ' Set default low batt voltage to 11.2 write 122,LBatt ' save to eeprom ' ########## Main battery regulating routine Main: nap 10 ' Have a little sleep to save some power. gosub GetValues if pin1 = 1 then menu1 ' Is menu button pressed? if pin6 = 0 then OnLoad ' Is Forced Load switch on? if pin7 = 0 then OnCharge ' Is Forced Charge switch on? sertxd("") ' send the data back via the serial port to the PC for logging. B5 = Volt b12 = 2 Gosub SendCmdByte gosub DisplayVolt FOR b11 = 6 TO 8 ' Display "V" READ b11,b12 GOSUB SendDataByte NEXT gosub DisplayAmp FOR b11 = 9 TO 11 ' Display "A" READ b11,b12 GOSUB SendDataByte NEXT if VoltLVolt then SwitchToLoad 'Battery fully charged, switch windmill to Load. if Volt128 then pamp if Amp<128 then namp if Amp=128 then oamp goto d1 pamp: Amp=Amp-128 goto d1 namp: b12=45 GOSUB SendDataByte Amp=128-Amp goto d1 oamp: Amp=0 goto d1 d1: b5=amp b10=b5/100 b12=b10+48 GOSUB SendDataByte b10=b10*100 b5=b5-b10 b10=b5/10 b12=b10+48 GOSUB SendDataByte b12 = 46 Gosub SendDataByte b10=b10*10 b5=b5-b10 b10=b5 b12=b10+48 GOSUB SendDataByte Return ' ######## Setup menu routine Menu1: 'Set the Charge Voltage "CVolt" GOSUB Beep pause 500 b12 = 1 GOSUB SendCmdByte b12 = 128 GOSUB SendCmdByte FOR b11 = 46 TO 61 'Display "Set Charge Volts" READ b11,b12 GOSUB SendDataByte NEXT b5 = CVolt gosub DisplayVoltLine2 Menu1a: pause 100 if pin1 = 1 then Menu2 if pin2 = 1 then UpChargeVolt if pin3 = 1 then DownChargeVolt goto Menu1a UpChargeVolt: CVolt = CVolt + 1 b5 = CVolt gosub DisplayVoltLine2 write 120,CVolt 'save in eeprom goto Menu1a DownChargeVolt: CVolt = CVolt - 1 b5 = CVolt gosub DisplayVoltLine2 write 120,CVolt 'save in eeprom goto Menu1a Menu2: 'Set the Load Voltage "LVolt" GOSUB Beep pause 500 b12 = 1 GOSUB SendCmdByte b12 = 128 GOSUB SendCmdByte FOR b11 = 32 TO 45 'Display "Set Load Volts" READ b11,b12 GOSUB SendDataByte NEXT b5 = LVolt gosub DisplayVoltLine2 Menu2a: pause 100 if pin1 = 1 then Menu3 if pin2 = 1 then UpLoadVolt if pin3 = 1 then DownLoadVolt goto Menu2a UpLoadVolt: LVolt = LVolt + 1 b5 = LVolt gosub DisplayVoltLine2 write 121,LVolt 'save in eeprom goto Menu2a DownLoadVolt: LVolt = LVolt - 1 b5 = LVolt gosub DisplayVoltLine2 write 121,LVolt 'save in eeprom goto Menu2a Menu3: 'Set the Low Batt alarm voltage "LBatt" GOSUB Beep pause 500 b12 = 1 GOSUB SendCmdByte b12 = 128 GOSUB SendCmdByte FOR b11 = 94 TO 105 'Display "Set Low Batt" READ b11,b12 GOSUB SendDataByte NEXT b5 = LBatt gosub DisplayVoltLine2 Menu3a: pause 100 if pin1 = 1 then Start if pin2 = 1 then UpLBattVolt if pin3 = 1 then DownLBattVolt goto Menu3a UpLBattVolt: LBatt = LBatt + 1 b5 = LBatt gosub DisplayVoltLine2 write 122,LBatt 'save in eeprom goto Menu3a DownLBattVolt: LBatt = LBatt - 1 b5 = LBatt gosub DisplayVoltLine2 write 122,LBatt 'save in eeprom goto Menu3a ' ########## Forced Charge / Load routines. ' The following routines work the same way as the "Main" loop, except that the controler state is fixed. OnLoad: gosub beep OnLoad1: Low portc 4 High portc 5 nap 10 gosub GetValues if pin6 = 1 then Start sertxd("") B5 = Volt b12 = 2 Gosub SendCmdByte gosub DisplayVolt FOR b11 = 6 TO 8 READ b11,b12 GOSUB SendDataByte NEXT gosub DisplayAmp FOR b11 = 9 TO 11 READ b11,b12 GOSUB SendDataByte NEXT ' Display "Forced Load" b12 = 192 GOSUB SendCmdByte FOR b11 = 62 TO 72 READ b11,b12 GOSUB SendDataByte NEXT Goto OnLoad1 OnCharge: gosub beep OnCharge1: low portc 5 high portc 4 nap 10 gosub GetValues if pin7 = 1 then Start sertxd("") B5 = Volt b12 = 2 Gosub SendCmdByte gosub DisplayVolt FOR b11 = 6 TO 8 READ b11,b12 GOSUB SendDataByte NEXT gosub DisplayAmp FOR b11 = 9 TO 11 READ b11,b12 GOSUB SendDataByte NEXT ' Display "Forced Charge" b12 = 192 GOSUB SendCmdByte FOR b11 = 73 TO 85 READ b11,b12 GOSUB SendDataByte NEXT goto OnCharge1 Beep: 'Make a noise for b3=1 to 8 high portc 0 pause 1 low portc 0 pause 1 next return