A PIC based Battery Management System

When tolerances go all wrong.

Just for giggles, I plugged in a set of hypothetical voltage divider-zener sets to measure the voltage of a single cell at the end of a 16 cell battery. Then I plugged in the maximum tolerances on a 2% zener and 1% resistors and made them go all the wrong way to cause the maximum measurement error possible within those tolerances. The step-tolerance of a 10 bit A/D converter, and measurement tolerance of the A/D converter were not considered (assumed perfect). It's an extreme scenario, one that will never happen, but the results were interesting.

The desired set-points were 3.65V high, and 2.1V low.

The hypothetical maximum variation in 'actual' cell voltage was:
high setpoint: 1.51V to 5.64V
low setpoint: .80V to 3.41V.

Isn't that funny?

Obviously the chances of that particular set of circumstances occurring are NIL, but it makes for a good thought exercise. Do you handle tolerances by including a programming mode, where you provide a known voltage across the pins and adjust in software? or do you use a trim-pot to physically adjust for the measurement tolerance?

Alternately, it may point the project back to multiple microcontrollers with fewer cells per controller (perhaps as low as 1:1).
 
OneEye said:
When tolerances go all wrong.

Just for giggles, I plugged in a set of hypothetical voltage divider-zener sets to measure the voltage of a single cell at the end of a 16 cell battery. Then I plugged in the maximum tolerances on a 2% zener and 1% resistors and made them go all the wrong way to cause the maximum measurement error possible within those tolerances. The step-tolerance of a 10 bit A/D converter, and measurement tolerance of the A/D converter were not considered (assumed perfect). It's an extreme scenario, one that will never happen, but the results were interesting.

The desired set-points were 3.65V high, and 2.1V low.

The hypothetical maximum variation in 'actual' cell voltage was:
high setpoint: 1.51V to 5.64V
low setpoint: .80V to 3.41V.

Isn't that funny?

Obviously the chances of that particular set of circumstances occurring are NIL, but it makes for a good thought exercise. Do you handle tolerances by including a programming mode, where you provide a known voltage across the pins and adjust in software? or do you use a trim-pot to physically adjust for the measurement tolerance?

Alternately, it may point the project back to multiple microcontrollers with fewer cells per controller (perhaps as low as 1:1).

More precision is always better. Assuming we don't intend large volume production of these boards we can probably afford to hand adjust each one. My guess is that should take about 5 or ten minutes -- one time.

Within that framework we can easily tolerate a wide variation in parts, etc. The issues that matter are consistency/repeatability and worst-case precision. Most of the odds and ends we've covered in this wide-ranging discussion are fairly consistent. And worst-case precision isn't too hard to compute.

I'm learning a lot and appreciate everyone's input.

I like the latest ideas about using zeners and dividers together. But it appears the lack of a ground reference for each cell may doom that approach. :-(

I suspect redirecting focus to a single MCU, floating ground system may be more fruitful. Perhaps a cheap MUX with high-z inputs. I don't know enough about floating grounds -- more research necessary.

Just came across an MCU compatible Bluetooth module which isn't cheap ($60), but is sooo cool. I may consider adding that to the mix. You can actually reprogram the MCU via the Bluetooth interface. A Wireless interface seems in keeping with a floating ground system. And having my bike automatically upload the day's stats to my computer is too cool!

Richard
 
A small update on MCU selection. Apparently PIC16 and lower series are so simple as making them hard to use with C or other high level languages. So I'll definetly skip those. On the other hand PIC18 series works ok with C (free IDE and gcc compiler). dsPIC are 16 bit, C compiler compatible and feature some serious capabilities (like hardware multiplication). Might be too much of a luxury.

Some interesting pieces:
PIC18FLF4458 13x 12 bit AD converters, 40-DIP package! $9
dsPIC30F4013 - 13X 12 bit AD converters, 16 bit, 40-DIP package, $9

if 13 x 10 bit DACs are ok, then prices go down to $4 or so for PIC18.

On Atmel side, it seems all their MCU work with C.

ATTINY861V is 20-dip, 11 x 10b ADC, $3. 8kb flash is a bit of a limitation if you want to log usage data.

Atmega processors also exist with lots of A/D channels, but not in DIP packages. Like Atmega640 in 100pin CBGA array.
16 A/D channels, lots of I/O, maybe too expensive at $12. I haven't found any way to wire it up. Certainly don't want to solder 100 pins...

DIP version Atmegas go up to 8 channel ADC. Like ATMEGA168 used in Adruino..
 
Just found an interesting app. note for a BMS building block chip:

http://www.intersil.com/data/an/an1333.pdf


Richard
 
:idea: An idea so simple just hit me I'm wondering how come it didn't appear here already. Must be something wrong with it :lol:

It solves two problems:
1) Voltage dividers need to have high resistance, so that the current they draw would not discharge the cells. As a rule of thumb it must be 100k or more. ADC requires 10k or less for quick and accurate measurement. So we need op-amp.
2) Cell balancing switch is at high voltage relative to MCU ground, so we need opto-isolator.

So we have 2 resistors + op-amp (voltage measurement) + opto-isolator + transistor + resistor (shunt/balancing)
6 components and lots of wires.
View attachment 1

Solution - combine the two! Only measure while balancing loop is on.
Components are reduced to two resistors + FET!
View attachment combined2.png

I can see two criticisms coming:

1) I'm measuring pack not cell voltage. So 10 bit adc error becomes 40mV instead of 4mV. But i don't see a problem if my cells are mismatching by 0.04V. Cheapest solution is to use 12 bit adc.

2) This is not bypass shunt that's discussed here a lot. I'm still not getting advantages of bypass shunt vs just dumping excess energy.

If you see more reasons why this won't work, post away! :)
 
tomv said:
This gets better and better :shock:

Notice how you can use single ADC channel to sample any cell? Balancing FETs are working like a MUX!



So 40pin DIP package MCU would handle 30 cells or so...

Cool! That's more like it.

Could you describe the voltage profile to the A/D input? Where will each cell's ground and positive levels be found. Are there limitations?

(An MCU with three I/O pins and a cheap shift register or two will handle 30 cells or so.)

Thanks!

Richard
 
The problem I see with that is you need to activate the shunts in order to measure the cell voltages during discharge or standby (not so good). It would also be challenging to get the right voltages to drive the gates on FETs at various voltages along the string. You still have the accuracy issues with the dividers also.

Now the ISL9208 sounds interesting. Never saw that one before! It does all the things we're looking for pretty much, and was designed specifically for this application. Can't beat that.
The datasheet is here: http://www.intersil.com/data/fn/fn6446.pdf
They show the price at $3.50 ea. in mass quantities. Each one handles up to 7 cells. Multiple units can be ganged together for more cells.

I still haven't given up on the ATtiny13 approach, other than programming it is very challenging. But that's a one time problem. If you had single cell ATtiny's measuring the voltage and controlling the shunts, they could send data to a main processor through a single optocoupler. When riding around, I don't really care about individual cell voltages, and the current is the same in all cells, so that could be measured on the pack as a whole to estimate state of charge. What I do care about is detecting a weak cell. If the ATtiny's sent voltage and shunt status information during charge, it should be possible to get an idea of the actual charge input to each cell.
 
In TOMV's idea, couldn't any "offset" in voltage readings simply be programmed/loaded in a field of the master microprocessor? The idea being to read the ACTUAL voltage present with a DMM at a cell junction and put it into the program? This "mapping" could be upgraded once in awhile to account for aging, etc...

Jeff K.
 
Embarrassing error in that circuit above is that it can't balance anything. For example when top shunt is active, it discharges the whole pack not just the top cell. Back to the drawing board for balancing solution.

Jeff: Yes, calibration info can be stored on the MCU. We have two kinds of errors here. This has been discussed a lot earlier in this thread.
1) Analog component errors. Those can be calibrated out. 1% resistors will drift from calibration at most 1% over temperature/humidity/aging life. But i doubt that one resistor would change in different direction (say due to temp) than the other. They would pretty much cancel each other errors out.

2) Sampling error - that's max ADC accuracy. it could be 0.1% using 10bit dac (so multiplied to 1% when measuring absolute, not differential voltage). If more precision is needed then I think it's easiest just to pick 12bit ADC to get 0.25% accuracy.

I'll post my cell measurement experiment soon. If I did it right this whole accuracy discussion is moot. Cell voltages seem to fluctuate a lot when under load/recovering from load/cooling/etc.
 
I thought this thread has plenty of info to start building something, so here's a first step:

1 cell battery DIScharger :))

Observations/next steps:
- Should write code for LVC! I've drained my cells to 0V. This is the first next step!
- Battery voltage fluctuates a lot. ADC/resistor accuracy errors are much smaller than those fluctuations. Those are Nimh cells, I'll try LiIOn next
- I need a better load. My 50W 2ohm resistor won't cut it. Ideally something programmable
- Once I hookup temp sensor I can actually do charging too
 

Attachments

  • eneloop_discharge.png
    8 KB · Views: 1,398
jeffkay said:
In TOMV's idea, couldn't any "offset" in voltage readings simply be programmed/loaded in a field of the master microprocessor? The idea being to read the ACTUAL voltage present with a DMM at a cell junction and put it into the program? This "mapping" could be upgraded once in awhile to account for aging, etc...

Jeff K.

Will cell 16's measured ground potential change when one or more of the lesser cells takes a dip? That would probably make the scheme unusable.

I wouldn't mind a duplicate circuit with the shunt removed if this were a good MUX replacement.

Richard
 
tomv said:
This gets better and better :shock:
file.php


Theft is the most sincere form of flattery. 8)

I like the fact that you've placed the FET's behind the resistors and I might take the idea and transfer it over to the 12 volt BMS thread. This is really good because you can drop the power dissipation rating requirements of the FET's since they are behind the resistors. Less power means less cost. :)

(you could buy $0.50 cent FET's rather than much more $$$)

One of the biggest advantages of splitting the battery into 12V units (besides the fact that it's backwardly compatible) is that the PIC doesn't have to worry about errors that might get too large. The voltage divider error increases with more cells. If you only have four cells then the error is very small.

Another big advantage of this is that the lower halves of the resistor pairs are reduced to just one resistor. (they all share the same lower resistor) This has the benefit in that it reduces the cost and the potential errors.

A Good Design. :)

(I wish I could claim credit for it :wink: )
 
fechter said:
[...]
I still haven't given up on the ATtiny13 approach, other than programming it is very challenging. But that's a one time problem. If you had single cell ATtiny's measuring the voltage and controlling the shunts, they could send data to a main processor through a single optocoupler. When riding around, I don't really care about individual cell voltages, and the current is the same in all cells, so that could be measured on the pack as a whole to estimate state of charge. What I do care about is detecting a weak cell. If the ATtiny's sent voltage and shunt status information during charge, it should be possible to get an idea of the actual charge input to each cell.

I haven't given up on the MCU per-cell approach either. But, I still suspect the single central MCU design will be much simpler and require fewer parts. Low power, high voltage FETs and opamps are very cheap. Can't we build our own differential MUX?

We can build a one cell BMS/charge controller without too much trouble. We could connect it to any single cell in a large battery pack and monitor and control that cell, no problem. Add a bunch of relays to connect our single-cell BMS to each of the other cells, one at a time, and we could charge the whole pack. So why can't we replace the relays with something less funky?

One MCU, one A/D, an array of cheap switches and bits to select any cell in turn. Put a latchable shunt on each cell and we're done. If we can monitor each cell at it's ground potential then talking to the shunt will probably be fairly simple too -- or just use optos.

Even running a floating ground on the MCU can't be that bad. My ATmega168 runs a long time on a 9-volt battery.

Richard
 
fechter said:
I still haven't given up on the ATtiny13 approach, ...

The ultimate ...

One MCU per cell. No central MCU. Each cell talks to the rest via I2C (or whatever). Together they provide LVC and charge control services. String as many together as you want and go.


Richard
 
An article on our subject, right on time! Those guys probably read endless-sphere 8)
http://www.edn-europe.com/novelmeasurementcircuiteasesbatterystackcelldesign+article+2044+Europe.html

All our approaches discussed and then some more:
1) voltage dividers - accuracy problems
2) high commond mode voltage amps - too expensive
3) separate adc per reporting via digital isolated bus - too expensive

And new stuff:
4) switched capacitor - need high voltage switches. neat
5) pulse excited transfomer-diode - :shock: don't follow this one yet

The author seems to be writting about this kind of stuff for 20+ years... So I'm reading it carefully
 
tomv said:
Embarrassing error in that circuit above is that it can't balance anything. For example when top shunt is active, it discharges the whole pack not just the top cell. Back to the drawing board for balancing solution.
Well, you are missing a FET that would isolate the ground. If the ground was not connected then if you opened two FET's next to each other then you could balance a cell. You need one more FET than you have cells.
 
tomv said:
An article on our subject, right on time! Those guys probably read endless-sphere 8)
http://www.edn-europe.com/novelmeasurementcircuiteasesbatterystackcelldesign+article+2044+Europe.html
55fa.jpg


A good article. This one seems to pretty closely match the original concept of the thread:

"Figure A presumably solves the problem by converting cell potentials to current, obviating the high common-mode voltages. Op amps feed a multiplexed- input ADC; the decoded ADC output presents cell voltages. This approach has serious fl aws. First, the required resistor precision and values are unrealistic, and they become progressively more unrealistic as the number of cells in the stack increases. Additionally, the resistors drain current from the cells, a distinct and often unallowable disadvantage."
 
safe said:
This one seems to pretty closely match the original concept of the thread:

Yep, they cover everything we come up with so-far. Their transformer based design is way too complicated for my taste. I can't even find the transformer part they are using...

I'm really curious about how to practically build this:
55fc.jpg

Description is really cursory, and I wonder if up to FET voltage limits this works just as well as transformer-do-anything design.
 
Anyone here own one of those fancy R/C battery chargers? Care to lift the lid and look inside? How do they monitor cell voltage, etc?

Richard
 
tomv said:
Yep, they cover everything we come up with so-far.
Well not quite... they brought up the idea of the voltage divider and mentioned the fact that you need really high precision knowledge of the resistors to be accurate. They didn't think of the idea of using a PIC generated tuning routine to establish what the resistor values might be. Of course... no one has been able to prove that such an idea can actually work. :lol:

So we've at least proposed a way to overcome that... even if the solution is still elusive.

I do like the fact that he starts out by explaining how simple it seems, but how difficult it is to achieve in practice...
 
safe said:
tomv said:
Yep, they cover everything we come up with so-far.
Well not quite... they brought up the idea of the voltage divider and mentioned the fact that you need really high precision knowledge of the resistors to be accurate. They didn't think of the idea of using a PIC generated tuning routine to establish what the resistor values might be. Of course... no one has been able to prove that such an idea can actually work. :lol:

So we've at least proposed a way to overcome that... even if the solution is still elusive.

I do like the fact that he starts out by explaining how simple it seems, but how difficult it is to achieve in practice...

They also didn't mention floating the ground of the whole MCU circuit. I can hook one of my battery-powered Atmega168's A/Ds to any cell of my battery pack and get a good accurate reading. All I need to do is automate the moving of the test leads from cell to cell.

Yes this creates some issues. But none of them are really that bad. I thought their transformer solution was kind of funky and expensive.

Richard
 
I still beleive that most of this BMS stuff is unnecessary. The most important component by far is the individual cell voltage tester. I plan to be making one soon. Its just a simple voltage divider and an ADV to give each cell's voltage. The calibration will be done in software.
 
Beagle123 said:
Its just a simple voltage divider and an ADV to give each cell's voltage.
In the chart you use optocouplers that appear to be always on. That's going to be a mistake I think because optocouplers will show definite deterioration within less than six months if always on. You would need to do the the Bob Mcree circuit and limit the usage of the optocouplers by placing them behind some sort of switch. Bod Mcree uses a Voltage Detector as a switch.

:arrow: Optocouplers are not reliable or precise... their measured value is best thought of as an "all or nothing" thing than a measurement of voltage.
 
They make optocouplers that last as long as a typical LED. Practically forever.

To do a switched capacitor sampling, you'd need two optoFETs for each cell, a bus with a sampling capacitor across it, and a pair of switches to the ADC input. You would need to be darn sure that there was some dead time between switches (break before make).
switched capacitor level shifter.jpg

tomv:
3) separate adc per reporting via digital isolated bus - too expensive

Hmm... ATtiny13's are like less than $1.00 ea. Optocouplers might cost about the same.
Actually, I think single cell MPU's could 'communicate' one way, not really needing a bus.

You still need some way to control the shunts on each cell too.
 
Back
Top