'------ Li-Ion Battery Management System Remote Display Unit Chip ------------- '------ Picbasic Pro Compiler version PIC12F683 - 111010 - V02 Beta ---------- '------ This code is for the Remote Display chip in the remote display unit --- '------ Please report any errors or problems. '------------------------------------------------------------------------------ '**************************** 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. '********************* Remote Display PIC12F683 Pinouts ************************ ' Top ' _____ '(+ Supply) +Ve -1| ^ |8- -Ve (- Supply) '(Not Used) Output 5 -2| 6 |7- Output 0 (Not used) '(16x2 Lcd Display Out) Output 4 -3| 8 |6- Output 1 (Data OK Led Out) '(Rxd Serial Data In) Input 3 -4| 3 |5- Output 2 (Not Used) ' ----- '******************** Remote Display Module Specification ********************** 'Supply Voltage 5.00V DC same as Master 'Average Supply Current at 5.00v 10ma 'CPU Speed 8mhz with internal resonator '2400 baud serial comms via 433mhz wireless link with Master 'Wireless range 75M approx 'Audible alarm sounds 0-5 seconds after Alarm received or data/signal failure 'Alarm delay 0-5 seconds adjustable via 100k pot '******************************************************************************* '********************** Program Size 650 out of 2048 Words ********************* '******************************************************************************* '------------------------------ General configuration -------------------------- 'Below used with MPASM Assembler @ __config _FCMEN_ON & _IESO_ON & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO 'Below used with PM Assembler '@ DEVICE PIC12F683,MCLR_OFF '@ DEVICE PIC12F683,BOD_OFF '@ DEVICE PIC12F683,PROTECT_OFF '@ DEVICE PIC12F683,WDT_OFF Define OSC 8 'Set PBP processor speed to 8 Mhz INTCON = %10001000 'Set GPIO Change Interrupt Enable & Global Interrupt Enable bit OSCCON = %01110101 'Sets internal osc to 8 Mhz (Default) and stable CMCON0 = %00000111 'Comparators off GPIO = %00000000 'Outputs low TRISIO = %00001000 'Set Pin GPIO.3 as Input 'Debug is used as it is the fastest and smallest serial routine to drive the Lcd display DEFINE DEBUG_REG GPIO 'Set Debug pin port DEFINE DEBUG_BIT 4 'Set Debug pin bit for Lcd Display GPIO.4 DEFINE DEBUG_BAUD 2400 'Set Debug baud rate 9600 or 2400 DEFINE DEBUG_MODE 1 'Set Debug mode: 0 = true, 1 = inverted (T=True Idle High)(N=Inverted Idle Low) DEFINE DEBUG_PACING 1000 'Set Debug Character Pacing mode to 1ms between bytes include "modedefs.bas" 'Allows the use of the standard serin/serout command '******************************************************************************* 'Variables Constants and I/O definitions '------------------------ Variables 16bit Word---------------------------------- '------------------------ Variables 8bit Byte ---------------------------------- Alarms var Byte 'Alarm Type Byte (0-255 number of different Alarms) ErrCell var Byte 'Number of the Cell with any Error condition 'Alarms Additional Information (255 possible Alarms) 0 = No Alarms 'If Alarms = 0 then (No Alarms Set) 'If Alarms = 1 then (Cell over AbsMax V) 'If Alarms = 2 then (Cell under AbsMin V) 'If Alarms = 3 then (Cell data serial transfer timeout error) 'If Alarms = 4 then (Battery Pack over AbsMax Temp) 'If Alarms = 5 then (External End Charge OR Battery Fault Condition) (Pack Voltage Drop Detector) 'If Alarms = 6 then (Internal End Charge) (Cells have all reached balancing voltage during this charge cyle) 'If Alarms = 7 then (Pack Voltage > Maximum permitted Pack Voltage) 'If Alarms = 8 then (Pack Voltage < Minimum permitted Pack Voltage) '--------------------------- Constants ----------------------------------------- '---------------- Pins used for I/O and designations ------------------------- '------------------ Digital high/low Inputs/Outputs ------------------------ Led var GPIO.1 'Data OK Led on Output 1 Lcd var GPIO.4 'Serial 2400 or 9600 baud out to 16x2 Lcd on Output 4 Rxd var GPIO.3 'Serial 2400 baud in from Master via 433mhz link on Input 3 '******************************************************************************* '******************************************************************************* Main: 'Program Start pause 2000 'Wait for two seconds for lcd to be ready debug 254,1,254,128,"Rem Display V02" 'Transmit data to Lcd pause 2000 'Wait for two seconds Start: 'Program Loop high led 'Turn off data Led (Sink driven) serin Rxd,N2400,5000,Timeout,["bms"],Alarms,ErrCell 'Receive qualifier & data from Master if Alarms > 0 then DisplayAlarms 'If conditions met goto DisplayAlarms low led 'Turn on data Led (Sink driven) Pause 100 goto Start DisplayAlarms: '255 different possible Alarms! debug 254,1,254,128,"Alarm ",#Alarms,254,192 If Alarms = 1 then '(Cell over AbsMax V) DEBUG "Cell ",#ErrCell," >AMaxV" 'Video Display endif If Alarms = 2 then '(Cell under AbsMin V) DEBUG "Cell ",#ErrCell," Max Temp" 'Video Display endif If Alarms = 5 then '(Pack Voltage Dropped) DEBUG "Voltage Drop" 'Video Display endif If Alarms = 6 then '(All Cells Reached Balancing Voltage) DEBUG "Charge End OK" 'Video Display pause 5000 'pause for 5 seconds to allow audible alarm to sound low led 'Turn on data Led (Sink driven) Silence audible Alarm endif If Alarms = 7 then '(Pack over Maximum Voltage) DEBUG "Pack V > Max V" 'Video Display endif If Alarms = 8 then '(Pack under Minimum Voltage) DEBUG "Pack V < Min V" 'Video Display endif toggle led pause 10000 goto DisplayAlarms Timeout: DEBUG 254,192,"No Signal!" toggle Led pause 10000 goto Timeout