#REM Li-Ion Battery Management System Simple Slave (Digital) Module by Peter Perkins. Picaxe 08M - PIC12F683 - 111108 - www.150mpg.co.uk - V19 Beta. **************************** General Information ****************************** The BMS modules carry no warranty or guarantee of any kind! They are used at your own risk, and I make no claims as to their suitability for a particular function. Prospective users must evaluate the system before using it, and no liability will be entertained by myself in any shape or form whatsoever. The modules and software have been produced at low cost for the benefit of the EV & electronic community. The software is available free via the internet. Users may modify or adapt the system as they see fit. If you are not fully competent to work on potentially lethal battery systems and high voltages, then do not experiment with or use this system. Be aware that vehicle modifications can lead to invalidated insurance and warranty issues. You the end user remain fully liable for any modifications made to your vehicle. ************************* Slave Picaxe 08M Pinouts **************************** Top _____ (+ Cell Supply) +Ve -1| ^ |8- -Ve (- Cell Supply) (Program In) Rxd -2| 0 |7- Output 0 (Bypass Load Out) (Slave Data Bus Out) Output 4 -3| 8 |6- Input 1 (RefAdc In 1.235V) (Slave Data Bus In) Input 3 -4| M |5- Output 2 (Master Data Bus Out) ----- ************************ Slave Module Specification *************************** Supply/Cell Voltage 1.75 - 5.00V DC (Pic limits) Average Supply Current at 3.35v <1ma Voltage Ref LM 385 1.235V accuracy 1% Supply/Cell Voltage sensing maximum accuracy +/- 20mv Maximum balancing/bypass current with 15R resistor 333ma at 5.00V Maximum serial Bus data rate 4800 baud (Picaxe 08M limit at 8mhz) Maximum cell Capacity 65ah (65,000) (Limit of 16bit Word Master Variable) Maximum 128 Slave Modules per Master Module (Master Pic Scratchpad Ram limit) CPU Speed 31khz - 8mhz with internal resonator (Lower speed used for power saving) Permitted Working Cell Voltage Range 1.75 - 4.30V RefVADC should be 63200 but can be adjusted to compensate for variations. Note Slave Opto's are Sink driven therefore (Pic Output Low = Opto On, High = Opto Off) ********************************************************************************** ***************************** Slave Clock Speeds ********************************* ************ Reducing Speed will Save Power (Untested at present) **************** %00000000 = 31 kHz 19bps %00010000 = 125 kHz 75bps %00100000 = 250 kHz 150bps %00110000 = 500 kHz 300bps %01000000 = 1 MHz 600bps %01010000 = 2 MHz 1200bps %01100000 = 4 MHz 2400bps %01110000 = 8 MHz 4800bps Example = poke $8F,%01100000 'Set clock to 4 MHz ******************************************************************************* ********************** Program Size 95 out of 256 Bytes ********************** ******************************************************************************* #ENDREM `Variables Constants and I/O definitions `Variables 16bit symbol CellV = w0 ;w0 (b0,b1) = Corrected Cell voltage (16bit value) symbol RefADC = w1 ;w1 (b2,b3) = Raw Adc input data variable range 0-1023 10bit symbol CellA = w2 ;w2 (b4,b5) = Cell average voltage last 10 measurements symbol PreV = w3 ;w3 (b6,b7) = Previous cell voltage, preserves Cell V from last loop `Variables 8bit symbol VData = b0 ;b0 = Voltage data byte (8bit value) (Sent to Master via link) symbol CountB = b13 ;b13 = General 0-255 byte ADC loop counter variable `Constants symbol RefVADC = 63200 ;Fixed Ref Voltage Calibration LM385 1.235v * 1023 * 100 / 2 = 63200 symbol CutInV = 360 ;Balancing load/bypass cut in Voltage (This must match value set in Master) symbol CutOutV = 355 ;Balancing load/bypass cut out Voltage (This must match value set in Master) symbol Delay = 10 ;Data delay time in milliseconds (5ms at 8mhz) symbol DLow = 175 ;Cell correction value 175 or 1.75V subtracted from CellVoltage symbol DHigh = 430 ;Cell correction value 430 or 4.30V (If Cell V>430 or <175 then error) `BaudRate constants for 8mhz symbol Baud1200 = N600 ;Baud rate 1200 at 8mhz symbol Baud2400 = N1200 ;Baud rate 2400 at 8mhz symbol Baud4800 = N2400 ;Baud rate 4800 at 8mhz `Pins used for I/O and designations `*** Digital high/low Outputs *** symbol Load = 0 ;2W 15R Transistor driven load/bypass resistor & optional led indicator on Output 0 symbol MasterBus = 2 ;Master Data Bus Output Baud4800 on Output 2 symbol SlaveBusIn = 3 ;Slave Data Bus Input Baud4800 on Input 3 symbol SlaveBusOut = 4 ;Slave Data Bus Output Baud4800 on Output 4 & optional led indicator `*** Analogue ADC Inputs *** symbol RefInput = 1 ;LM385 1.235V RefAdc on Input 1 `******************************************************************************* `******************************************************************************* Start: ;Main program start high SlaveBusOut ;Turn off interrupt signal for next Slave (SlaveBusOut) low Load ;Turn off load (and load indicator led if fitted) disablebod ;Disable Pic Chip Brown Out Detection to function at lower supply V setfreq m8 ;Setfreq CPU Freq to 8mhz (Allows Baud4800 Comms if set) setint %00001000,%00001000 ;Activate interrupt when pin3 goes high `******************************************************************************* `******************************************************************************* Main: ;Main program loop label CellA = 0 ;Set Cell Average word variable to 0 (Zero) for CountB = 1 to 10 ;10x ADC Oversampling loop counter readadc10 RefInput, RefADC ;Measure ADC voltage reference CellA = CellA + RefADC ;Add latest ADC reading to running total next CountB ;Repeat loop until 10 ADC readings obtained CellA = CellA / 10 ;Calculate average ADC reading for last 10 readings CellV = RefVADC / CellA * 2 ;Calculate Cell Voltage from the average ADC LM385 VRef 1.235v reading if CellV > CutInV then ;If Cell V > CutInV then high Load ;Turn on load (and load indicator led If fitted) endif if CellV < CutOutV then ;If Cell V < CutOutV then low Load ;Turn off load (and load indicator led if fitted) endif PreV = CellV ;Preserves CellV to prevent interrupt errors goto Main ;Goto start of Main loop `******************************************************************************* `Note Slave Opto's are Sink driven therefore (Pic Output Low = Opto On, High = Opto Off) `******************************************************************************* Interrupt: CellV = PreV ;Restores CellV to prevent interrupt errors if CellV >DHigh or CellV 4.30V or V <1.75V set out of range (b0=0) VData = 0 ;Set VData = 0 Cell error out of Voltage range condition else CellV = CellV - DLow ;Convert Word (CellV) data into Byte (VData) for output endif Loop1: if pin3 = 1 then Loop1 ;Wait until interrupt signal is low before begining transmission low MasterBus ;Turn on MasterBus Optocoupler (Reqd due to sink driven) serout MasterBus,Baud2400,(VData) ;Send VData (b0) to Master at Baud2400 high MasterBus ;Turn off MasterBus Optocoupler (Reqd due to sink driven) low SlaveBusOut ;Turn on interrupt signal for next Slave (SlaveBusOut) Pause Delay ;Allow time for next Slave and Master to be ready high SlaveBusOut ;Turn off interrupt signal for next Slave (SlaveBusOut) setint %00001000,%00001000 ` ;Activate interrupt when pin3 goes high return ;Goto main program loop