#REM Li-Ion Battery Management System Slave Module by Peter Perkins. Picaxe 08M - PIC12F683 - 300708 - www.150mpg.co.uk - V0.68 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 (Master Data Bus Out) (Slave Data Bus Out) Output 4 -3| 8 |6- Output 1 (Bypass Load Out) (Slave Data Bus In) Input 3 -4| M |5- Input 2 (RefAdc In 1.235V) ----- ************************ Slave Module Specification *************************** Supply/Cell Voltage 1.75 - 5.00V DC (Pic limits) Average Supply Current at 4.00v <100ua Voltage Ref LM 385 1.235V accuracy 1% Supply/Cell Voltage sensing accuracy +/- 30mv Maximum balancing/bypass current 333ma at 5.00V Serial Bus data rate 4800 baud (Picaxe 08M limit at 8mhz) Maximum Cell Capacity 65ah (65,000) (Limit of 16bit Word Variable) Maximum 128 Slave Modules per Master Module (Pic Scratchpad Ram limit) CPU Speed 8mhz with internal resonator Permitted Working Cell Voltage Range 1.75 - 4.30V RefVADC should be 1263 but can be adjusted to compensate for variations. ******************************************************************************* ************************** Slave Data Bus Commands **************************** If Message = 1 then (Send CellV Data to Master on Master Bus) If Message = 2 then (Increase MaxCellV point +10mv) (Balancing load/bypass cut in point) If Message = 3 then (Decrease MaxCellV point -10mv) (Balancing load/bypass cut in point) If Message = 4 then (Increase RefVADC Calibration Value +10) If Message = 5 then (Decrease RefVADC Calibration Value -10) If Message = 6 then (Send Message back to Master on MasterBus) Bus Testing Routine ******************************************************************************* #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-1024 10bit symbol CellA = w2 ;w2 (b4,b5) = Cell average voltage last 10 measurements symbol RefVADC = w3 ;w3 (b6,b7) = Fixed Ref Voltage Calibration LM385 1.235v * 1023 = 1270 (1250-1280) symbol MaxCellV = w4 ;w4 (b8,b9) = Maximum Cell Voltage (Balancing load/bypass cut in point) `Variables 8bit symbol VData = b0 ;b0 = Voltage data byte (8bit value) (Sent to Master via link) symbol Message = b12 ;b12 = Message data byte (8bit value) (Received from Master/Slave) symbol Counter = b13 ;b13 = General 0-255 byte ADC loop counter variable `Constants symbol Delay = 10 ;Interrupt and data delay time in milliseconds (10ms) 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) `Pins used for I/O and designations `*** Digital high/low Outputs *** symbol MasterBus = 0 ;Master Data Bus Output 4800baud on Output 0 symbol Load = 1 ;2W 15R Transistor driven load/bypass resistor on Output 1 symbol SlaveBusIn = 3 ;Slave Data Bus Input 4800baud on Input 3 symbol SlaveBusOut = 4 ;Slave Data Bus Output 4800baud on Output 4 & optional led indicator `*** Analogue ADC Inputs *** symbol RefInput = 2 ;LM385 1.235V RefAdc on Input 2 `******************************************************************************* `******************************************************************************* Start: ;Main program start setfreq m8 ;Setfreq CPU Freq to 8mhz disablebod ;Disable Pic Chip Brown Out Detection to function at lower supply V RefVADC = 1270 ;Set Initial RefVADC Calibration Value [1.235v * 1023 = 1270] (1250-1280) MaxCellV = 370 ;Set Initial Maximum Cell Voltage 3.70v (Balancing load/bypass cut in point) `******************************************************************************* `******************************************************************************* Main: ;Main program loop label CellA = 0 ;Set Cell Average word variable to 0 (Zero) for Counter = 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 Counter ;Repeat loop until 10 ADC readings obtained CellA = CellA / 10 ;Calculate average ADC reading for last 10 readings CellV = RefVADC *25 / CellA * 100 / 25 ;Calculate Cell Voltage from the average ADC reading if CellV >= MaxCellV then ;If Cell V >= MaxCellV (3.70v initial Value) then high Load ;Turn on load (and load indicator led If fitted) else low Load ;Turn off load (and load indicator led if fitted) endif if pin3 = 0 then Main ;If pin 3 is 0 then there is no incomming message serin SlaveBusIn,N2400,(Message) ;Receive Message (b12) from Master/Slave at 2400bps x2 (4800bps at 8mhz) pause Delay ;Pause 0.01 of a second `******************************************************************************* `************************ Slave Data Bus Command (1) *************************** if Message = 1 then ;If Message = 1 then send CellV Data to Master on (MasterBus) if CellV >DHigh or CellV 4.30V or V <1.75V set out of range (b0=0) b0 = 0 ;Set b0=0 Cell error out of Voltage range condition else CellV = CellV - DLow ;Convert Word (CellV) data into Byte (VData) for output endif serout MasterBus,N2400,(VData) ;Send VData (b0) to Master at 2400bps x2 (4800bps at 8mhz) goto Transmit ;Jump the next instructions to help speed endif `************************ Slave Data Bus Command (2) *************************** If Message = 2 then ;Increase MaxCellV point +10mv (Balancing load/bypass cut in point) MaxCellV = MaxCellV + 10 ;Add 10mv to MaxCellV endif `************************ Slave Data Bus Command (3) *************************** If Message = 3 then ;Decrease MaxCellV point -10mv (Balancing load/bypass cut in point) MaxCellV = MaxCellV - 10 ;Subtract 10mv from MaxCellV endif `************************ Slave Data Bus Command (4) *************************** If Message = 4 then ;Increase RefVADC Calibration Value +10 RefVADC = RefVADC + 10 ;Add 10 to RefVADC Calibration endif `************************ Slave Data Bus Command (5) *************************** If Message = 5 then ;Decrease RefVADC Calibration Value -10 RefVADC = RefVADC - 10 ;Subtract 10 from RefVADC Calibration endif `************************ Slave Data Bus Command (6) *************************** if Message = 6 then ;If Message = 6 then send Message back to Master on (MasterBus) serout MasterBus,N2400,(Message) ;Send Message (b12) to Master at 2400bps x2 (4800bps at 8mhz) endif `********************** Re-Transmit Message to next Slave ********************** Transmit: high SlaveBusOut ;Turn on Message waiting signal (SlaveBusOut) pause Delay ;Hold Message waiting signal high until next Slave has time to respond low SlaveBusOut ;Turn off Message waiting signal (SlaveBusOut) serout SlaveBusOut,N2400,(Message) ;Pass Message (b12) to next Slave at 2400bps x2 (4800bps at 8mhz) goto main ;Goto main loop