You are on page 1of 11

Cell-top BMS.

Communications Protocol: Each board is connected to the next via an opto-coupled, 2-wire link using the PIC12F1822 UART running at 9600 Baud, as shown below: Module n Master Module 2 Module 1

The communications system comprises a string of bytes, initiated by the master and passed on from one module to the next, being added to or subtracted from as required by each module, finally ending up back at the master unit which is how communications integrity is monitored. The first byte in the stream is a command and the last byte is always 0xFF as a terminator. Note that the data are processed such that 0xFF can never occur as data. The data stream is not buffered in the modules (apart from the two byte buffer in the UART) but each byte is passed on as it is received resulting in very little delay in each module. This means that even with 150 modules, the total communications time for a master poll should be around 150 mSecs. The basic commands are: 01 send the stored cell voltage value. This is reduced to a single byte representing a voltage range of approximately 2.2V to 4.0V. See below for more information on how this is worked out. If this command is received by a module, it inserts its cell voltage byte into the data stream immediately after the command, then passes on the entire data stream. Thus its address becomes the byte position in the data stream. The first module in the string has its data as the last byte received by the master and the last module will be the first byte. The master recovers these bytes into an array and processes them back into actual cell voltages. 02 change the state of the shunt. The next byte to be received is the shunt state, 0 for off, 1 for on. In this case, the next byte after the command is removed from the data stream so each module sees the shunt state byte intended for it. The master puts the first modules byte first in the data stream, the last one, last. Note that the addressing is effectively inverted from the 01 command. Loss of comms causes all shunts to turn off. 03 send the stored temperature value. This is a single byte which is the raw ADC count divided by four. The data byte is inserted into the stream as for the voltage byte. 04 reprogram the micro via bootstrap loader. Not implemented as yet. This is not a command that the master issues. Re-programming must be done by a computer.

Compression of the cell voltage: The ADC in the 12F1822 is 10 bits wide and would require two bytes to be sent as is. However, by reducing the cell voltage range somewhat, it can be sent as a single byte. The ADC input is taken from an LM385 reference diode at 1.235V and the supply (cell) voltage is used as the reference (Vcell). Thus the ADC count is given by ADC = ( 1.235*1023)/Vcell and the bytes representing voltage are inversely proportional to the actual voltage values. 3.99V gives an ADC count of 316 and 2.21V gives a count of 571. If 316 is subtracted from each of these values, they become 0 and 255 respectively, ie 0 represents 3.99V and 255 represents 2.21V. To turn these numbers back into voltages, the master adds 316 and then Vcell = (1235 * 1023)/ADC , the result being in millivolts. It should be noted that this scheme gives a resolution of approximately 12 mV at 3.99V and approximately 4 mV at 2.21V The ADC in the 12F1822 takes an average value of four samples to provide some noise reduction and any value larger than 0xFE is forced to 0xFE to allow 0xFF to be the string terminator. Temperature Measurement: Temperature measurement is by reading a thermistor voltage divider. In this case the LM385 is used as the reference voltage for the ADC as well as providing a stable reference for the thermistor. The ADC reading is divided by four to give a single byte (TempByte) which has sufficient accuracy and resolution for the 0 60 deg C range of interest. Typical values depend on the thermistor, but range from about 200 at 0 deg C to about 50 at 60 deg C. Note these values are inversely proportional to the actual temperatures, as for the voltage. The temperature is calculated as follows: Temp = ((128-TempByte)/K) +25 where K depends on the thermistor used and is selected from a four value look-up table to suit the temperature range being measured. Typical values are in the range 2.0 to 3.0. See the Appendix. The SMD thermistor is mounted close to the cell negative terminal for good thermal contact with the cell. The basic philosophy of the system is to keep each modules hardware and firmware as simple as possible and to do all the processing and decision making in the master unit. Module Components: 1 x PIC12F1822 microcontroller 1 x Vishay VO615A Optocoupler 1 x2A, 50V NPN Transistor 2 x 2-pin headers *1 x 5-pin header (for ISP) 4 x 6R8 1 watt SMD resistors (shunt) 1 x PCB 1 x LM385-1.2 Voltage Reference 1 x Thermistor AVX NB12K00103KBB 1 x 10uF 16V Electro 1 x .1uf Ceramic 8 x SMD resistors

*not used once the module is programmed. May be deleted and programming done by temporary pressure contact ie stick a connector into the 5 holes and hold it with your thumb while it programs!

Cell Module attached to a Thunder Sky cell:

The cell module shown above differs from the current design slightly in that the thermistor is not a surface mount device and is simply pushed down next to the cell casing. Also, the latest design has increased copper area for the shunt resistors to improve cooling. Master Control Module: This needs initialisation as to the number of cells connected, which is done by setting a constant in the firmware. It is assumed that Li cells only are used and the default cell voltage range of 2.21 to 3.99 is satisfactory. The Vmax and Vmin trip points may be user programmed but the default values are 3.60V and 2.50V. The master simply polls the daisy chain of slaves on a continuous basis. It receives the data stream back from the last cell and stores the raw bytes in an array in RAM. This array needs to be large enough to hold the cell voltage and the cell temperature bytes . The PIC16F1827 has enough RAM to store data for 200 cells. The array is processed to find the largest and smallest values and these are displayed on the LCD as Vl and Vh, Tl and Th, together with the cell numbers. The total voltage is also computed and displayed. The master has two outputs for charger control: one is activated if any cell exceeds Vmax and the other when all cells reach Vmax. The latter is intended to shut the charger off entirely and the former can be used to either switch off or cut back the charger. (This one is not implemented in the current software) A third output controls a LED which indicates an alarm condition: loss of comms or any cell reaching Vmin. The master has the facility to conduct bottom balancing of the cells. For bottom balancing, when the switch is activated all shunts are turned on. As each cell reaches Vmin, its shunt is turned off until all shunts are off. While in this mode, the display shows the highest and lowest cell voltages and the word Balancing: followed by the number of shunts that are turned on. This number will slowly decrease to zero as all cell voltages come together. Only bottom balancing is implemented at present. Note that in the event of a comms failure, the cell modules automatically turn off their shunts.

Completed Controller:

The picture above shows a completed controller connected to four cells.

The temperature display:

Balancing mode:

This shows the number of cells (16) with their shunts still turned on.

Parts List for the Control unit: 1 x Microchip PIC16F1827 I/SO 2 x MOSFET, NXP PMV30UN or similar (20V, 2A SOT-23) 1 x LCD Module 16 x 2. 1 x Opto coupler same as cell modules. 1 x 78L05 ACM 5v regulator, SMD. 1 x LED. 2 x 330R .25w smd resistor 2 x 2k2 .25W smd resistor 2 x 10K .25W smd resistor 1 x 22K .25W smd resistor 2 x 270R .5W smd resistor 2 x .1 uF smd ceramic cap 1 x 10/16VuF smd electrolytic cap 1 x 16 way pin connector for LCD 1 x 5 way pin connector for ISP 2 x 2 way pin connector for comms in and out. 1 X SPST toggle switch for balancing 1 X momentary push button (toggles display) 1 x PCB Construction: The cell modules use smd parts and if you havent built anything this way before, give it a go! Its quite straightforward and if you have more than a few boards to assemble, a bench-top oven is a worthwhile investment. I used a Sunbeam Mini Bake and Grill Model BT2600 which is rated at 1300 -1400 watts. It looks like this:

It has a temperature control and a timer on the right hand side, along with a couple of indicator lights. Its a 230v model and has elements top and bottom.

The metal tray is perfect for holding your boards. To start assembly, collect all the components together and get a syringe full of solder paste. Lay out the boards on the tray as below:

The tray actually holds about 20 of the cell module boards, but if you just want to try the process out on a few at a time, thats fine. The next step is to go over every pad on every board and squeeze a small drop of solder paste onto each one. This is pretty tedious! You dont need much paste, just a small drop of about a millimetre or so, but dont worry if you use too much, itll come off at the end. An absolutely essential tool for this job and for every step in the process is a magnifier that you can wear on your head. Mine has two binocular magnifiers and also a small, round magnifier, all of which can be swung in or out as required. Youll also need a decent pair of tweezers or forceps with tips small enough to pick up the parts . The design uses pretty much the largest smd parts available, so you should not have too much difficulty handling them.

Heres a tray of 18 boards with the solder paste drops applied:

Now you have to place all of the components. Best to start with the lowest ones and do all boards with one component at a time, ie place R1 on each board, then R2 etc. That way you wont miss any, especially if you count out the correct number for the amount of boards you are doing each time. Place the parts carefully using the magnifier and the tweezers and try to get them all straight and centred on the pads. The solder paste helps hold them in place, but dont sneeze! If you have difficulty turning the parts over, simply drop one into your open palm and then you can easily roll it over with the end of the tweezers without it flying off into infinity. Its a good idea to place all the parts with any printing they may have uppermost so you can see what they are after soldering. Be careful not to let any sleeves or other stray bits of anatomy brush across the boards as you go as it is easy to knock some parts off without noticing. Once you have placed all the parts, its time to turn the oven on. Set the thermostat for 200 degrees Celsius and give the oven time to stabilise. (Just wind the timer round for hour or so, you wont be using it). Once you see the thermostat cycling, open the door and carefully slide the tray into the oven sitting it on a wire tray about the middle. Use an oven glove! Close the door and check the time, you will need only 2 or 3 minutes. Watch carefully through the glass door and you should see a blob of paste suddenly turn silver after no more than 3 minutes. That means the solder has melted and is flowing. Give it 30 seconds more, then turn the oven off and open the door. Dont be tempted to remove the tray or indeed move anything, just walk away and let it all cool down. When its cool enough to touch, then you can remove the tray and have a look at your handiwork! Below is a picture of one of my first experiments and you will see that four components have moved out of place. This is due to having unequal amounts of solder paste at each end and the difference in surface tension when it melts pulls them out of shape. Easily fixed with a soldering iron and the tweezers, but a nuisance, so when squirting solder paste try to make the blobs equal in size.

Heres a picture of a whole tray of 18 boards and there werent any movers on this one!

Once you have all of your boards made, shout yourself a glass of Champagne as it is quite a significant achievement. But you still have to fit the thru-hole parts which are the 2 x 2-pin headers for the comms and the 5-pin one for the ISP (programmer). You may not wish to fit this one and the programmer can be connected by just pushing the pins through the holes and holding some pressure on the contacts while programming.

Now comes testing and programming: You will need a computer (surprise!) running Microchips MPLAB IDE (I use version 8.66) and either the CCS C compiler or just use the CellTopBMS .hex file to burn straight to the chip. Youll need a PICkit 3 programmer. Also, set the device type to 12F1822 (Configure/Set Device in the MPLAB IDE) Connect the PICkit 3 to the 5 pin ISP header. Its a good idea to make up a short extension cable for this to avoid wear and tear on the PICkit socket . Then select Programmer in the MPLA IDE and under Settings/Power select Power target from PICkit You should see no error messages and a confirmation that the PICkit can see the 12F1822. Then just click on Program and it should happen! Verification is automatic. You can do all of your boards in one go and hopefully they will all program correctly. Then you need to test that they all work and to do that you will need to build the controller if you havent already. As there is only one of these, you can just assemble it with a soldering iron ( .5mm tip is what is needed). The pads are already tinned, so you can simply place the parts one at a time and touch the iron onto the pads as you go. Just hold each part down with the tweezers and solder away! If you need a little extra solder, use something like .56mm cored stuff and if you do apply too much, remove it with some solder wick. The magnifier is essential for this work, it lets you see tiny bridges that might create If you do, apply some solder wick. Note that the LCD, the LED and the optocoupler are fitted to the opposite side of the board to the other components. Also, you need to fit a 22k pull-up resistor from +5V to the top of each switch. This was an error on my part where I assumed the micro had internal pull-ups on ALL of its port pins and this turned out not to be the case. If you look carefully at the photo, youll see a couple of smd resistors across the switch connection pads and a wire link that runs off back to +5V. Programming is done in the same way as for the cell modules, except the device must be changed to 16F1827. The default values for cell numbers, low voltage alarm, balancing voltage and maximum cell voltage are: 45, 2.5V, 2.8V and 3.6V respectively. These will do to test things with but you will almost certainly want to change the cell numbers to suit your own installation. To do this yourself requires the CCS C compiler at present. Note that the pushbutton cycles the display between the two modes shown above and the spst toggle switch turns on/off the balancing mode. You will also need to make up some comms cables: Use twisted pair with 2-pin header sockets on each end. (Hint: to make twisted pair, get two lengths of different coloured (red and black is good) plastic insulated wire, clamp the two wires of one end in a vice, put the other ends in a drill chuck, tighten and pull the wires out straight with a small amount of tension. Pull the drill trigger and watch!) Connect Dout on the controller to Din on a cell module and its Dout back to Din on the controller. Connect your cell module to a 3.2V supply eg a cell! And the controller to a 12V supply which should light up the LCD backlight whose display will show Ready.. for a second or so and then the cell voltage as in the picture above. Or No Comms if it isnt working. In this case carefully check that your connecting cables are all the right way round, particularly observing the correct polarity for each twisted pair. If all is well, put your finger on the thermistor and you should see the temperature change on the controller. Flick the balancing switch and you should be able to feel the shunt get warm with the end of your finger. You can test all of your cell modules in this way.

Installation Once you have them all working, they can be fitted to your battery cells. Just bolt them on, being careful to observe the correct polarity. The watchdog timer on each module will cause the micro to restart if it gets glitched up by noisy power connection, so dont worry about that. When you have all the cell modules fitted, connect them up, Dout to Din in a daisy chain fashion. You will have to make up comms cables as you go. Work out the polarity and make sure you connect them correctly. If you connect each one back to the controller as you go, you will see an ever increasing Vt as each one comes to life. Be aware that the Dout terminals are NOT opto-isolated, so you will find an ever increasing voltage on those pins with respect to the other end of the battery which is optoisolated, but be aware all the same. Note that the cell closest to the Din terminals of the controller is cell number 0! Cell numbering starts at 0 and goes up to 1 less than the total number of cells, so the cell nearest to the Dout terminals of the controller is the highest number. ie the first one in the daisy chain is the highest number and the last is the lowest. Heres a picture of one of my battery boxes with cell modules installed:

Note that each cell is actually three cells in parallel.

Operation In display mode 1 you will see the highest and lowest cell voltages (Vh and Vl) with the total battery voltage Vt on the second line together with the cell numbers for highest and lowest (h and l). Press the button for a short time and the second line of the display changes to show the highest and lowest cell temperatures. If you get a comms failure, the display will show No comms! alternating with mode 1 showing the last stored values, and the led will flash. If any cell drops to 2.5V the led will come on. Balancing Run your battery down until Vl = 2.80V. Turn on the Balancing switch and the display second line will show Balancing: followed by the number of cells whose shunts are turned on. Just leave it going until that number becomes zero. Thats it! Turn off the balancing mode and connect up the charger making sure to turn it off when the first cell reaches 3.60V. There is an output on the controller that activates when this voltage is reached and this can be used to turn your charger off automatically via a relay or something, unless your charger has a Disable input.

Appendix. K values for some typical thermistors: For Murata NXFT15XH103FA2B25 thermistor: temp byte >=94 K = 2.4, >76 and <94 K=2.2, <=76 K=2.1 For EPCOS B57164K0103+000 thermistor: temp byte >=128 K= 3.0, >74 K=2.8, <=74 K=2.5 For AVX SMD NB12K00103KBB thermistor: temp byte >103 K=2.6, >92 K=2.5, >81 K=2.4, >72 K=2.2

You might also like