#REM Li-Ion Battery Management Configuration & Test Module. By Peter Perkins Picaxe 28X1 - PIC16F886 - 181109 - www.150mpg.co.uk - V0.08 **************************** 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. ************************** Master Picaxe 28X1 Pinout ************************** Top _____ (Pic Reset) Reset -01| ^ |28- Output 7 (Drive Inhibit Out) (Current Sensor In) Adc 0 -02| |27- Output 6 (Charger Relay Out) (Spare Adc In) Adc 1 -03| |26- Output 5 (Video Display Out) (Spare Adc In) Adc 2 -04| |25- Output 4 (Controller Cutback Out) (Spare Adc In) Adc 3 -05| P |24- Output 3 (WatchDog Led Out) (Program In) Rxd -06| 2 |23- Output 2 (Slave Data Bus Out) (Program Out) Txd -07| 8 |22- Output 1 (Charger Cutback Out) (- Supply) Gnd -08| X |21- Output 0 (Audible Alarm Out) (Resonator In) Osc 1 -09| 1 |20- +Ve (+ Supply) (Resonator In) Osc 2 -10| |19- Gnd (- Supply) (Button A In) Input 0 -11| |18- Input 7 (Master Data Bus In) (Button B In) Input 1 -12| |17- Input 6 (Interlocks In) (Temp Sensors In) Input 2 -13| |16- Output c5 (Charging Led 2 Out) (Speed Sensor In) Input 3 -14| |15- Output c4 (Dash Led 1 Out) ----- ************************ Other IC's On Master Pcb ***************************** *********************** Watchdog Picaxe 08M Pinouts *************************** Top _____ (+ Supply) +Ve -1| ^ |8- Gnd (- Supply) (Program In) Rxd -2| 0 |7- Txd (Program Out) (Watchdog Led Out) Output 4 -3| 8 |6- Output 1 (Audible Alarm Out) (Pulse Count In) Input 3 -4| M |5- Output 2 (Master Reset Out) ----- ****************** SV2000 Serial to Composite Video IC ************************ Top _____ (Sync Out) Syn -1| ^ |8- +Ve (+ Supply) (Video Out) Vid -2| V |7- Nc (No Connection) (Serial Data In) Rxd 4 -3| I |6- Inv (Serial Data Invert Mode) (- Supply) Gnd 3 -4| D |5- Txd (No Connection) ----- ************************ Master Module Specification ************************** Board Supply Voltage 8.00-20.00V DC or as limited by 5.00V 78L05 regulator CPU Supply Voltage 5.00V CPU Speed 8mhz with internal resonator (Pic limit 20mhz with external res) Average Board Supply Current at 12.00v <100ma Maximum Serial Bus data rate 4800 baud (Picaxe 08M limit at 8mhz) Maximum Cell Capacity 65ah (65535) (Limit of 16bit Word Variable) Maximum Pack Voltage 650v (65535) (Limit of 16bit Word Variable) Maximum Charge/Discharge rate 100A (Allegro Current Sensor limit) Maximum 128 Slave Modules per Master Module (Pic Scratchpad Ram limit) Battery Pack Temp Sensor Range (0 to 127C) Composite Video Display data rate 9600 baud (SV2000 Serial to Video Chip) Composite RCA Video Monitor Output 1V 75ohm PAL/NTSC Charger relay output 5.00v at 500ma Opto Isolated Charger/Controller Cutback outputs max 25ma ******************************************************************************* ********************* Program Size 787 out of 4096 Bytes ********************** ******************************************************************************* #ENDREM `Variables Constants and I/O definitions `Variables 16bit (Word) symbol CellVoltage = w1 ;w1 (b2,b3) = Cell Voltage 0-1023 10bit (0-5v) symbol PackVoltage = w2 ;w2 (b4,b5) = Calculated pack voltage (Voltage of all Cells added together) symbol Speed = w3 ;w3 (b6,b7) = Speed Sensor Pulse length `Variables 8bit (Byte) symbol CountA = b27 ;b27 = General 0-255 8bit Byte Counter or General/Local Variable symbol CountB = b26 ;b26 = General 0-255 8bit Byte Counter or General/Local Variable symbol CountE = b23 ;b23 = Local General 0-255 8bit Byte Counter or General/Local Variable symbol VoltageData = b2 ;b2 = Voltage data byte (8bit value) (Received from Slave via serial link) `Constants symbol Cells = 5 ;Number of cells in the battery pack (50) (Max is 128 cells) symbol Delay = 50 ;Interrupt and data delay in milliseconds (50ms) symbol DiscardLow = 175 ;Cell correction value 175 or 1.75V added to CellVoltage to recreate correct V symbol TimeOut = 100 ;Serial Data Receive Timeout value 100ms `BaudRate constants for 8mhz symbol Baud1200 = T600 ;Baud rate 1200 at 8mhz symbol Baud2400 = T1200 ;Baud rate 2400 at 8mhz symbol Baud4800 = T2400 ;Baud rate 4800 at 8mhz symbol Baud9600 = T4800 ;Baud rate 9600 at 8mhz (Note Baud9600 is reserved for the Video output chip) `Pins used for I/O and designations `*** Digital high/low Outputs on port b - Outputs 0-7 *** symbol SlaveBus = 2 ;Slave Data Bus Output Baud4800 on Output 2 symbol Video = 5 ;Dashboard Video display Baud4800 (9600) on Output 5 `*** Digital high/low Inputs on port c - Inputs 0-3 & 6-7 *** symbol ButtonsADC = 1 ;Menu Buttons ADC input 0-5V ADC on Input 1 (0-5v = 1 of 6 values) (0,1,2,3,4,5) symbol TempSensor = 2 ;I2C DS18B20 Battery Pack Temp Sensors on Input 2 (-55 to +125C) symbol SpeedSensor = 3 ;VSS Speed sensor pulse sensor on Input 3 (Measures length of a single pulse) symbol MasterBus = 7 ;Master Data Bus Input Baud4800 on Input 7 ;************************************************************************************************************* Start: ;BMS Configuration Routine setfreq m8 ;Setfreq CPU Freq to 8mhz serout Video,Baud9600,(" ") ;Video Display serout Video,Baud9600,(27,67,27,70) ;Video Display Clear Screen & Hide Cursor serout Video,Baud9600,("* BMS Testing! *",10,13) ;Video Display pause 2000 ;Pause for 1 second serout Video,Baud9600,("Press 1 to read ") ;Video Display serout Video,Baud9600,("Temp Sensor Ser ") ;Video Display serout Video,Baud9600,("Press 2 to read ") ;Video Display serout Video,Baud9600,("pack Slave Data ") ;Video Display serout Video,Baud9600,("Press 3 to read ") ;Video Display serout Video,Baud9600,("Speed Sensor Val") ;Video Display pause 1000 ;Pause for 1 second Loop0: gosub MenuButtons ;Gosub MenuButtons if CountE = 1 then SensorSerial ;If Button 1 is pressed goto SensorSerial if CountE = 2 then MasterBusTest ;If Button 2 is pressed goto MasterBusTest if CountE = 3 then CheckSpeed ;If Button 3 is pressed goto CheckSpeed goto Loop0 ;Loop until a button is pressed ;*************************** Test Single Slave Voltage Reading ***************************** SensorSerial: `The readowsn command reads the serial number and then puts the family code `in b6, the serial number in b7 to b12, and the checksum in b13 `Note that you should not use variables b6 to b13 for other purposes in your `program during a readowsn command. serout Video,Baud9600,(27,67,"Sensor Serial No",10,13) ;Video Display Main: readowsn TempSensor ;Read serial number on input2 serout Video,Baud9600,(#b6," ",#b7," ",#b8," ",#b9,10,10,13) ;Video Display serout Video,Baud9600,(#b10," ",#b11," ",#b12," ",#b13,10,10,13) ;Video Display serout Video,Baud9600,("Note the 8 No's!") ;Video Display serout Video,Baud9600,("Press M to exit!") ;Video Display Loop2: gosub MenuButtons ;Gosub MenuButtons if CountE <> 5 then Loop2 ;If Button 5 not pressed then wait goto Start ;Goto Start of main program ;*************************** Test Battery Pack Slave Data Buses ***************************** MasterBusTest: ptr = 0 ;Reset Scratchpad pointer to 0 (Start of 128 byte Scratchpad Ram) high SlaveBus ;Turn on Message waiting signal (SlaveBus) pause Delay ;Hold Message waiting signal high until Slave has time to respond low SlaveBus ;Turn off Message waiting signal (SlaveBus) for CountB = 1 to Cells ;Start for/next loop CountB (1 to Cells) serin [TimeOut,DataError],MasterBus,Baud4800,@ptrinc ;Receive Data on opto bus into Scratchpad Ram and inc pointer next CountB ;Repeat loop until CountB reaches Cells PackVoltage = 0 ;Reset PackVoltage Total to zero = 0V ptr = 0 ;Reset Scratchpad pointer to 0 (Start of 128 byte Scratchpad Ram) for CountB = 1 to Cells ;Start for/next loop to calculate Pack voltage and check cell data/voltage CellVoltage = 0 ;Clear CellVoltage Variable VoltageData = @ptrinc ;Load VoltageData (b2) with value from Scratchpad Ram and inc data pointer CellVoltage = CellVoltage + DiscardLow ;CellVoltage (w1) = CellVoltage (w1) (1-255 0.01-2.55V) + (175 1.75V) ;Note (w1) is a 16 bit word variable made up of (b2) & (b3) byte variables PackVoltage = PackVoltage + CellVoltage ;Add Cell voltage to accumulated Pack voltage next CountB ;Increment for/next loop and move to next cell serout Video,Baud9600,("Voltage = ",#PackVoltage,10,10,13) ;Output PackVoltage to Video Display serout Video,Baud9600,("*** Test OK! ***") ;Video Display serout Video,Baud9600,("Check the value ") ;Video Display serout Video,Baud9600,("shown is correct") ;Video Display serout Video,Baud9600,("with a meter! OK") ;Video Display serout Video,Baud9600,("Press M to exit!") ;Video Display Pause 5000 ;Wait 2 Seconds Loop4: gosub MenuButtons ;Gosub MenuButtons if CountE <> 5 then Loop4 ;If Button 5 not pressed then Loop4 goto Start ;Goto Start of main program ;*************************** Cell Data Errors (Timeout) ***************************** DataError: serout Video,Baud9600,("Cell ",#CountB,10,10,13) ;Video Display with Line Feed serout Video,Baud9600,("Data Error!!!!") ;Video Display Pause 5000 ;Wait 2 Seconds goto Start ;Goto Start to try again ;************************************************************************************************************** CheckSpeed: ;Pulsin measures VSS pulse. If no pulse result will be 0 serout Video,Baud9600,(27,67,"Drive at 30mph as indicated by a GPS Unit") ;Video Display Loop5: pulsin SpeedSensor,1,Speed ;Measure length of a VSS pulse in 5us (8mhz) units (Timeout 0.32768s) serout Video,Baud9600,(27,83,0,6,"Sensor ",#Speed," ") ;Video Display gosub MenuButtons ;Gosub MenuButtons if CountE <> 5 then Loop5 ;If Button 5 not pressed then Loop5 goto Start ;Goto Start of main program ;************************************************************************************************************** MenuButtons: ;Menu subroutine decodes button Inputs and returns 1 of 6 values (0,1,2,3,4,5) readadc ButtonsADC,CountE ;Read ButtonsADC input and get value into Local Byte Variable CountE CountE = CountE + 6 / 42 - 1 ;Convert ADC data to button number return ;Return to main program