A PIC based Battery Management System

Hi Brad,


The noise problem you have might require some power supply conditioning. I know when we build boards back that were put in noisy systems, we would always place 0.1 - 1.0 uf tantalum capacitors as near the supply pins of digital logic and uP chips as possible. We would places these across pretty much every chip. We would also place a choke in series with the power supply to clean up any spikes.
You could also place a larger filtering capacitor (~10-100 uf) across the supply rails for the entire board in conjunction with a forward biased diode.

And as others have said, you could also use voltage regulators and series diodes.

http://www.atmel.com/dyn/resources/prod_documents/doc7551.pdf (pg 29) shows a power supply circuit for a motor controller using an ATMEL CPU.
 
Slave layout is nearing completion on PCB. It will be approx 50mm x 100mm double sided (components only on the top) with slots/holes for upto 8mm cell posts covering 60-85mm distance between centre of cell terminals. That should fit 40-100ah TS/High Power cells. I can't go long enough to fit holes on the pcb for 200AH TS cells as the board won't fit on my 40ah cells. However an extension terminal or flying leads could just be soldered to the board to make it fit the bigger cells.

Latest docs

http://www.solarvan.co.uk/Master100708.txt
http://www.solarvan.co.uk/Master100708.jpg

http://www.solarvan.co.uk/Slave080708.txt
http://www.solarvan.co.uk/Slave100708.jpg

:)
 
A few updates to keep you in the loop.

Picaxe 08M chips can be had at £1.00 each excl vat in bulk. Not too bad. Later can buy bare pic chips and program in assembler.

Testing them today seem happy to work down to about 1.8V, so should cover most scenarios. :wink:

I've also changed to an I2C device the DS18B20 for pack temp sensing instead of the LM35 which will allow a lot of individually addressed sensors on the same input, so people can put them where they want in the pack, on the controller, on the motor etc etc. It also has a wider temp range -55 to +125C :)

I will do a write up when it's finished and working properly. I need every minute I've got before the cells arrive from China to work on the design/software.
I did do a comprehensive write up on my very old and agricultural relay :shock: driven BMS for my van 5 years ago.

http://www.solarvan.co.uk/solarvanbmsproj.zip

Pretty cringeworthy now, but I learnt a lot from that first one. :lol:


Changing to the 28X1 did add a few more inputs, but I did it mainly because it has a timeout function on the slave data serial input, so the Master software does not become stuck waiting for a slave to respond if there is a hardware failure on a particular cell. It can now detect that condition and report appropriately. Vital to the whole system. :wink:

I choose the 2w 15R balancing load as that has been proven to work over the last four years on Cedric's cell controllers. The balancing load of about 250ma was suffcient to keep 200AH cells in balance during that time so I'm happy with that. On smaller cells it will be even more effective. 8)

I will be using a Zivan NG3 and the same Charger cutback arrangement. The Picaxes don't do DAC output in the conventional sense ASFAIK, you have to use a PWM output but this drives an opto through an RC smoothing circuit so in effect the opto led changes brightness smoothly in response to changes in PWM Mark/Space ratio. I haven't decided wether to pull charger voltage up or down with opto control yet. Pulling it up gives a slightly more fail safe arrangement I think. :? The Master schematic incorporates this PWM control function for both Charger and Controller cutback :D

Many, many years ago as a callow youth I used to sneak about with a copy of Mayfair :oops: :wink: Now I skulk about, collar turned up, in an old fleece, with a carrier bag full of Schematics, Software printouts, Pic data sheets and the like :shock: :lol: How times have changed!

I've just ordered the 08M Picaxes to start building up the 50 slaves I need when the pcb's are finished. I have also ordered a PIC assembler level programmer so I can look at converting the Slave software to assembly and program it direct into bare pics once it's all tested. This will make the slaves a bit cheaper but owners won't be able to re-program themselves like they can with the Picaxe versions.

One of the Picaxes main attractions is the ease of re-programming 8) with a simple serial/usb cable and the free software it means as We/I release upgraded Slave/Master software people can just download it to there system in a few minutes. The free 32mb Picaxe basic editor is below, download it and tinker around!

http://www.rev-ed.co.uk/software/bas805.exe

The current sensor I will be utilising is based on the Allegro ACS754LCB series, which gives an 0-5v Output covering -100 to + 100A range.

5v output = +100A
2.5V output = 0A
0v output = -100A

Resolution will be about 200ma with the Pic 28X1 10bit adc

This will be mounted off the master board to reduce interference.

http://www.farnell.com/datasheets/75747.pdf

Other sensors can be used but conditioning of the signal will be reqd to ensure signal is within 0-5v for the Pic ADC input.

If you were using a current sensor with a positive/negative voltage output (quite common) then this example circuit will condition signal, opto isolate it and bring it to 0-4vdc output with a centre (2.0v) 0 amp position.

http://www.solarvan.co.uk/CurrentSensorCircuit.jpg

I will be building my battery pack up into 10 cell subpacks for testing which will only be connected together for final install/bench test.

I can thoroughly bench test each 10 cell subpack before install and it's a lot safer at <40V per block, the entire pack charged voltage will be nearer 190V :shock: a bit too dangerous for tinkering with for my liking. Still got to be careful though I don't want any expensive smoke or singed dignity.

I have been thinking about transmission speed over the common 2400baud serial data bus.

At the moment I am transmitting a 16bit word variable containing the Cell Voltage (200-400 or 2.00-4.00V). 50 Cells takes an estimated second approx for all the data to be sent, but I want to improve on that.

This really is a waste of most of a byte and time consuming to transmit, so I have now crammed the result into a single byte without sacrificing accuracy. 8)

Basically the only V range we are interested in is the normal pic/lithium cell operating range, which is about 1.75-4.30V, anything outside that is indicative of a serious problem anyway.

The additional Slave code simply tests the cell voltage to see if it is >430 (4.30V) or < 175 (1.75V), if it is, it sets the transmitted byte to 0 which indicates to the Master "Houston we have a problem!".

If it's within the normal range it subtracts 175 (1.75) from the result which gives a value that can fit into a single byte with 10mv resolution.

This byte is then transmitted and the Master simply adds 175 back to it to get the correct Cell voltage in the 16bit word variable at the other end :)

Means 50% less data to send :shock: Should be twice as fast :wink:

Updated Slave Code

http://www.solarvan.co.uk/Slave130708.txt

I am now using a 128 byte Ram Scratch pad in the Master software to save all the single byte Cell Voltage data to during the faster Serial transmission.

Once the data has been transferred from the pack Slaves to the Master I can then manipulate/display this data as reqd.

Much better IMO but limits Max number of cells to 128, as that's all the scratchpad ram available in the 28X1 Picaxe Pic.

Should be more than enough for most systems.

http://www.solarvan.co.uk/Master130708.txt

I'm working on a subroutine to allow a horizontal scrolling display on the Lcd of all the cell voltages when a button is pressed.


Some updated and tweaked/schematics.

http://www.solarvan.co.uk/Master110708.jpg

http://www.solarvan.co.uk/Slave110708.jpg
 
Final Schematic Checking!

It's so easy to make a mistake, as I did on this version of the Master schematic :oops:

http://www.solarvan.co.uk/Master110708.jpg

Can you spot it? It's something that operates with the Slaves?

I've corrected it below, but this highlights a serious problem, me checking my own stuff. :shock: You miss things. Can others have a good look at both schematics and flag up any obvious errors for me please. I'm very close to final pcb layout, and if I had used the above version it would not have worked :cry:

http://www.solarvan.co.uk/Master130708.jpg

Help! Once it's cast in Stone or fiberglass it won't be easy or cheap to correct. :roll:
 
Your connector labeling is confusing. It's difficult to tell what connects to what. Where does Slave Data Initiate go?
 
On the Master J11 `Slave Data Initiate` goes to connector J2 `Interupt Trigger Input`on the first Slave cell. This initiates a data cascade through the Slaves. I will rename them later thanks. :wink:

Update

OK I have re-named them.

http://www.solarvan.co.uk/Master140708.txt
http://www.solarvan.co.uk/Master140708.jpg

http://www.solarvan.co.uk/Slave140708.txt
http://www.solarvan.co.uk/Slave140708.jpg
 
I have determined that my mode of failure is random code execution.

I calibrated my processors, then removed the calibration code completely. Now, when I run the motor, the processors all go haywire, but none of them lose their calibration (which is stored in eeprom.) So, I conclude that they were losing their calibration because the calibration routine was running randomly.

I have the watchdog timer and brownout settings all set up, but I still can't get all 20 processors to fail gracefully. If I stop the bike, unplug all of the processors and plug them all back in, they will all begin working again, but if I don't unplug them, they don't.

- Brad
 
peterperkins said:
OK I have re-named them.

http://www.solarvan.co.uk/Master140708.txt
http://www.solarvan.co.uk/Master140708.jpg

http://www.solarvan.co.uk/Slave140708.txt
http://www.solarvan.co.uk/Slave140708.jpg

I don't see any obvious problems.

The major concern I have is the slave CPUs connected directly across the cell for it's supply with no decoupling. High currents and parasitic circuit inductances are going to generate some voltage spikes and there is nothing to keep them away from the CPU. This is almost certainly the same problem that bquick is having.

You may need to decouple the CPU supply with an RC, then use a resistive divider across the cell to measure your cell voltage with and compare it to your reference voltage reading. A more bulletproof method may be to just use a micropower LDO 2.5V Regulator for the CPU supply and as the ADC voltage reference.

At any rate, I'd watch this problem.
good luck
 
Randomly said:
You may need to decouple the CPU supply with an RC, then use a resistive divider across the cell to measure your cell voltage with and compare it to your reference voltage reading. A more bulletproof method may be to just use a micropower LDO 2.5V Regulator for the CPU supply and as the ADC voltage reference.

At any rate, I'd watch this problem.
good luck

I think this is quite a good idea, especially if it can be regulated down to 2.0 or 1.8V and still work. Normally we expect a supply from a battery not to be noisy, but if its supplying a motor controller then it could be pretty nasty.

Another thing to think about is cutting the current drain right off when the cell gets below LVC. I realise there are some different views about this. Some people say its not a problem as they will always recharge as soon as LVC is reached, but I would be concerned about the storage problem.

To lose 1C in 3 months is 0.00046 C drain.
With a 10 Ah battery that is a drain of 4.6 mA
So even 1 mA drain could be bad for an already discharged battery.

Nick
 
I think you guys are correct that it's either spikes or RF noise that are causing the problems. I have brown-out detection set on the processors, so I think they would fail gracefully on low voltage.

I'm not an EE, so I could use our help. I'm assuming that I would put a resistor and capacitor in series with each battery wire? What values of R and C would you suggest?

Thanks.

- Brad
 
Hi Brad,

The frequencies generated by the controller/motor will be the commutation rate (10-300 Hz) and the PWM rate used for throttle control (say 16 kHz), plus all the harmonics. I guess the commutation and PWM will appear on the supply lines but the higher harmonics will couple as RF noise.

You can't really put much more than 10 Ohms in series as you don't want a big voltage drop, so its going to be difficult to filter out the commutation rate. The battery will take a lot of that out anyway, but to do more will require an active regulator. 10 Ohms and 33 uF tant will take out the PWM noise. For the RF noise, you want something like 10 nF to 100 nF right up against the micro, but getting the layout right is more important than the actual cap value. Of course, the best place to tackle the RF noise is where it is generated.

HTH, its a complicated subject.

Nick
 
Hi Guys:

I'm trying to make a LM117 differential amplifier work so I can make a LCD voltage meter for 16 cells.

However, I must be doing something wrong. I'm connecting the IC using this model:

INA117%20Cell%20Diagram.gif

Datasheet:
http://focus.ti.com/lit/ds/symlink/ina117.pdf

I've connected pins 1, 2, 4, 5 and 8 to the negative terminal of a 12v battery

Then I connected pin 3 to the wiper of a potientiometer so I can vary the voltage.

The output voltage on pin6 should equal the voltage on pin3 minus the voltage of pin2. In this case the voltage on pin2 is the negative terminal of the battery, so the voltage on pin 6 should simply mirror the pot on pin 3. However, it always says about 0.65v. It doesn't vary much when you change the pot.

I made all these connections directly to the pins without using any type of resistors for protection etc. If I understand correctly there are built-in resistors in the chip so it shouldn't need protection(?)

What can I possibly be doing wrong?

Can anyone suggest how to make it do a test reading on a cell voltage?

 
pin 4 needs to be connected to a -9 to -15V supply, pin 7 needs to be connected to a +9 to +15V supply. You can use 9V batteries for starters.

The output voltage range of this op-amp is several volts less than whatever the supply rails are.

A somewhat easier part to work with is the single supply LT1990 with Rail to rail input and output.
http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1154,C1009,C1126,P7521,D5087
 
Thanks for the response.

I connected pin4 to the negative terminal of a 12v battery, and pin 7 was connected to the positive. Is that right? I don't understand what -15v and +15 are exactly. I assume just connecting to a battery.

Thanks,
Eric
 
The supply voltages are relative to ground, so Pin 4 needs to be connected to -9 to -15V BELOW ground, Pin 7 connected to +9 to +15V above ground. It needs 2 batteries.

Using 9V batteries as an example, Connect the negative terminal of the 1st 9V battery to Ground. Connect the positive terminal of the 1st 9V battery to Pin 7. Connect the Positive terminal of the 2nd 9V battery to Ground. Connect the negative terminal of the 2nd 9V battery to Pin 4.

That's why I suggested the LT1990. Unlike the INA117 it does not need a negative supply but can work with a single +12V supply (it'll work with anything from 3v-36V).
 
Now I understand. Thanks. I'll order some of the amps you suggested and post my results.
 
Hey Randomly:

I noticed that it is only available in the SOIC package. I made the mistake of ordering that package size before--its TINY! The pins are so small I can't imagine how anyone could soler them (much less 16 chips).

What do you think? I'll look for other options.
 
these days most everything is surface mount, many newer ICs only come in surface mount packages.

You might try using something like this
http://www.futurlec.com/SMD_Adapters.shtml

A good fine point soldering iron or hot air tool can be very useful.
some SMD info:
http://www.sparkfun.com/commerce/present.php?p=SMD-HowTo-1
http://www.curiousinventor.com/guides/Surface_Mount_Soldering/101
 
Hardware is done for MK1 Slave, the PCB files should be flying through the ether to a man in shed in China early next week for 100 boards to be made :shock:

Still working on Master PCB layout, might finish that next week and will order 5 I think as it's cheap enough.

Master Software is improving, and I now have the SOC calculation routine up and running.

If you have the Picaxe Basic Interpreter loaded on your Windows based PC then you can download a simulation version of it here and run that to see how it works.

http://www.rev-ed.co.uk/software/bas805.exe

http://www.solarvan.co.uk/bms/Soctest180708.txt

The Master Software is currently upto 500 bytes used out of a possible 4096 bytes available, only used 1/8th of available space so far 8) Lot's of room for optimisation anyway i'm sure.

The SOC routine has been a tough one :? and at this stage it takes no account of variations in cell/battery chemistry and assumes a perfect cell. You get out what you put in :wink: There is no Temp/Peukert compensation or anything fancy like that at the moment. To be fair Lithium cells are quite good anyway and you get out what you put in near enough.

The routine catches charge/discharge data each second over a 1 minute periods and calculates an average 1 minute value for both. It then works out how much has been used or added in that 1 minute and then adds/subtracts that from the cell capacity/soc.

I'll add a 10% cutoff as well, so for my cells 40ah cells discharge will be limited to 36ah max. This will also help with errors in the SOC calculations which are again limited by the integer only maths.

After a mains external full charging cycle the SOC will be reset back to 100% or 40ah. The SOC counting will still take place during external charging and it will be interesting to watch the corelation between the amps counted in and out and the charging voltage cut off system. :wink:

Latest Software

http://www.solarvan.co.uk/bms/Master180708.txt
http://www.solarvan.co.uk/bms/Slave180708.txt

Limitations

Now I am working hard to make this as widely compatible with as many cells/batteries as possible, but I have had to keep an eye on my own specific requirements. To this end the new max cell capacity of the Master software is 65ah, this means I can use the full range of the limited 16 bit integer maths to maintain accuracy. It can be adjusted to allow upto 650ah capacity cells but at the expense of a decrease in SOC calculating accuracy. Also the maximum average current charge/discharge for any 1 minute period is limited to 65A to help with calculations. My Honda Insight falls within this range but again it can be adjusted to cover 650A at the expense of accuracy.

I don't know yet how accurate the whole thing will be, so I am erring on the side of maximum accuracy for my own application at present.


I'm trying to thoroughly document the software so you can adjust it for your own uses. I would welcome comments on the SOC routine and ideas to streamline/improve it please!!
 
Video interfacing and in car displays!

I've been thinking about this, and really like the idea of this superbly simple single chip 8 pin dip solution for a video lcd display.

http://www.speechchips.com/shop/item.aspx?itemid=5

A lot of vehicles now have lcd monitors built into the dash and this could/should drive them if they have a compatible RCA 1v 75ohm Video input. You can also get one of these nice motorised in dash lcd things!

This looks like a gem and has a video input to display the bms data ;)

E-Bay Item number: 130239538523

Yes the display has limited capabilities, but seems a bargain price to me and simple to add to the master pcb (which I will do this week) You don't have to install it on the pcb and can still use the two line lcd text module.

The chip accepts serial data from the master and generates RS170 (US NTSC Compatable) and CCIR (EU PAL Compatible) monochrome video that can be fed into any display/tv/monitor capable of displaying standard RCA Video.

sv2000diagram_small.gif


Ohh err :)

sv2000.jpg


Might even be able to add some graphics/bargraphs to it by modifying fonts etc :shock:

http://www.speechchips.com/downloads/sv2000.doc
 
I recently built and tested a system very similar to Peter's, one pic per cell, opto-isolated bus, etc... I am using a different pic, but the concept is still the same.

img_2573.jpg


Here are some things that I been learning along the way:

1. Make sure to have a fuse on your circuit. Not only does it protect your circuit if something bad happens, it also makes for a convenient way to disconnect your PCB from the battery. Otherwise you have to unbolt it every time you want to disconnect it.

2. High frequency noise is going to be a problem. I am running a PFC-30 charger, and the first time I plugged it in my BMS went crazy. Even though I am using a decoupling cap on the pic and diode/100uf cap on the input power, I still had issues with the charger (I am sure it is going to be worse under actual driving conditions). My solution was to add chokes in between the charger and the pack.
img_2574.jpg


This didn't eliminate the noise, but brought it low enough that my boards could run without resetting.

3. Connectors are the key to success. I hate making cables. So, I decided on using rj45 connectors because I can by pre-made 6" network cables. It really makes for a modular system.

4. LEDs are super helpful for troubleshooting. I put a RGB LED on my board.

5. Sink instead of sourcing current when connecting an opto-isolator. This was my the one real mistake on my design. The issue is that when the cell voltage is low (below 3v). The combination of the fact that the input diode drops .4v and the pic has trouble sourcing more than 2ma without dropping some voltage (in my case it was dropping almost 1v). Seeing that my opto-isolator wants a minimum of 1.5v to fire, it is going to be in trouble. I should have wired my opto-isolators so that the pic would sink current instead of sourcing it, eliminating the voltage drop. Instead I am "hacking" on a transistor to fix the issue.

I am sure there are more things I am forgetting, but I thought it might be helpful to someone just to read these suggestions.

Best regards,

Zach
 
That's very helpful thanks.

Can we have some close up pics of your boards?

Please keep us updated. What smoothing decoupling do you have on the boards?

Peter
 
I am just using a 100uf on the input, and a .1uf right next to the pic. The .1uf is ceramic and the 100uf is tantalum. Here's a picture of a partially populated board (sorry, it's the only thing I have on my website).

img_2568.jpg

I'll take some more pictures soon.

Zach
 
Nice work Zach! Those look like 100ah Thundersky cells.

How much shunt current can it take (what is the shunt resistor value)?

What MCU are you using?
 
Thanks! Actually they are LFP160s (160ah Thunder Sky's). The resistor is 10ohms, 3w. When balancing, it burns between 400-500ma.

I've only run one full charge cycle on my test pack, but the results looked pretty good. I charged the pack at 12amps. One cell got to 4.1v and I stopped charging (I was being a bit conservative). At that point the other cells ranged between 3.9v and 4v with only one cell down at 3.8v (this was the cell I was using to power the board during software development). I assume after a few more charge cycles, they will all get a little closer. I could also reduce the charge current, set the shunt trigger voltage a bit higher, and let the whole pack spend more time balancing. I think this will take some experimentation.

EDIT: One other bit of info that I thought was interesting... After just sitting for 24 hours, the voltage on all but one of the cells fell to 3.34v and that odd cell fell to 3.35v. According to the little chart in the book that came with the batteries, I need to get the cells up to 4.2v and hold them there for an hour while tapering off the current. However, that chart is showing a charge current of 80amps, which charges the batteries in 160 minutes. I can't get anywhere near 80 amps, so I will be scaling my timing accordingly.

Zach
 
Back
Top