• Howdy! we're looking for donations to finish custom knowledgebase software for this forum.
    Please see: Funding drive thread

A PIC based Battery Management System

After reading quite a few pages of this thread(not all) i find myself thinking about a Pic based BMS + Charger + Controller(BLDC) all on one board sharing what they can. Main reason being, pcb proto types are damned expensive as far as i can tell making up about 50% of the cost associated with home brew electronics, so why not try to share some space. I repeatedly come back to all three of those parts are connected to the same wires, they have another significant portion of their costs in FETs and they all need them. Chargers mostly seem kinda dumb but BMS and Controller can both benefit greatly from a somewhat powerful micro controller. Maybe im seeing possibility's where there are none. Im still pretty new to most of this and not an EE, so i guess I need to go buy books and take some classes at the JC. I remember safe had some thread about putting a pwm + fet on top of each cell to act as some kind of weird pseudo BMS + controller, though im not sure that it was for brushless. has anyone else already thought of this and deemed it unfeasible?
 
bquick said:
These are also the cells physically closest to the motor (one inch away). So, they may be getting bombarded with noise from the motor. Maybe I should try wrapping the pack with aluminum foil?

A lot of noise is electromagnetic flux and the motor produces a lot of electromagnetic flux as different electromagnets inside switch on and off. The magnetic field tapers off with the square of distance, I believe, so getting it twice as far away should decrease that noise to 1/4 or so.
 
Has anyone worked out a simple/cheap way to monitor cell voltages with a single MCU yet?

I can read each cell separately with a $10 multimeter. Seems like there must be an easy corollary given an MCU and a few D/As. Isn't there?


Thanks

Richard
 
It would seem like there should be. As a part of my study into electronics, I'm getting into digital electronics and I should be able to delve into this topic soon, especially as I have some future interest in an "effective" BMS.

I don't understand what's so hard about it, either. The bare-bone logic and the digital sampling seems like it should be easy.
 
swbluto said:
It would seem like there should be. As a part of my study into electronics, I'm getting into digital electronics and I should be able to delve into this topic soon, especially as I have some future interest in an "effective" BMS.

I don't understand what's so hard about it, either. The bare-bone logic and the digital sampling seems like it should be easy.

With a bit more thought it turns out the simple subtraction approach is good enough for my purposes. Don't need a huge amount of accuracy. The 10-bit A/D on the MCU (the Atmega168 I have) should yield about 2% or 3% accuracy per cell, worst case. Readings of lower cells being more accurate, of course. Just need a 20-way multiplexer to connect to all the cells.

More accuracy can be had with higher resolution A/Ds or electrical prescaling. The whole thing seems much simpler today. Hmm. Time to glue something together.


Richard
 
rf said:
swbluto said:
It would seem like there should be. As a part of my study into electronics, I'm getting into digital electronics and I should be able to delve into this topic soon, especially as I have some future interest in an "effective" BMS.

I don't understand what's so hard about it, either. The bare-bone logic and the digital sampling seems like it should be easy.

With a bit more thought it turns out the simple subtraction approach is good enough for my purposes. Don't need a huge amount of accuracy. The 10-bit A/D on the MCU (the Atmega168 I have) should yield about 2% or 3% accuracy per cell, worst case. Readings of lower cells being more accurate, of course. Just need a 20-way multiplexer to connect to all the cells.

More accuracy can be had with higher resolution A/Ds or electrical prescaling. The whole thing seems much simpler today. Hmm. Time to glue something together.


Richard

I should read the previous posts. :lol: (Suspects everything has been thought out)

So you're sampling individual cell voltages using a 20-to-1 mux and comparing it to "ground"(or the ground part of the battery pack), storing the results cumulatively and using subtraction for each cell-sample to find the approximate cell voltage? Is this data being used for just LVC? Or are you also using it to detect unbalanced cells? I was thinking about adding a piezo-electric buzzer and use differently-numbered "buzzes" to distinguish the problem and avoid cutout altogether for just LVC(over-current cutout would still be there.). I originally thought of using a 20-to-2 mux to detect the individual cell voltage but that gets a little bit more complicated.

I'm getting an Arduino Diecimila(sp?) which is based off the Atmega168, so I'll be experimenting soon.
 
I should read the previous posts. :lol: (Suspects everything has been thought out)

So you're sampling individual cell voltages using a 20-to-1 mux and comparing it to "ground"(or the ground part of the battery pack), storing the results cumulatively and using subtraction for each cell-sample to find the approximate cell voltage? Is this data being used for just LVC? Or are you also using it to detect unbalanced cells? I was thinking about adding a piezo-electric buzzer and use differently-numbered "buzzes" to distinguish the problem and avoid cutout altogether for just LVC(over-current cutout would still be there.). I originally thought of using a 20-to-2 mux to detect the individual cell voltage but that gets a little bit more complicated.

I'm getting an Arduino Diecimila(sp?) which is based off the Atmega168, so I'll be experimenting soon.

Yes, the 20 to 1 mux makes it easy. Or you could use 4-way muxes on each of the Atmega168's six A/Ds. Not sure which is simpler/cheaper yet. Haven't looked at parts yet. Think I may have some 16-channel chips somewhere. I'm currently interested in this as a simpler way of checking, logging and displaying voltages. But this could easily be the basis for an LVC. Not sure it would be cheaper than Gary's analog LVC which I'm currently using.

Oh, `storing the results cumulatively' ... No. It's simpler than you make it sound.

To get the voltage of cell #20 you read from that cell, subtract the reading from cell #19 and you're done. For cell #19 you read from it and subtract cell #18 -- done. Simple and no `approximation' other than the A/Ds themselves.

This scheme provides limited but sufficient resolution for LVC, BMS, or whatever else we might want in this realm. Roughly 1/10th of a volt. More resolution can be had without too much trouble or expense, if you feel you must have it.

Richard
 
lostcoyote said:
nevermind.... wasn't the differential MUX explored on page 1 already?
Yes it was. We're not talking about a differential mux here. Simpler. Scale the whole pack voltage down to fit within the A/D's range, then isolate the cell we want to measure. Sacrifices resolution, but there's still enough to work with. (If not just use a better A/D.)


Richard
 
agreed.

any temperature coefficient induced errors to worry about?
would have to calibrate the initial resistor network but maybe the high precision's not a requirement either if using 1% 10ppm metal film. at least all the resistors would track over temperature provided you don't have them sitting on any hot spots on the PWB.

one could also use a single ended MUX with the resistive dividers integrated around it. the output would drive a diff amp (one leg connected to a precision reference calibrated to the cell voltage you want) into the ADC.


there's a guy up in Canada that built a BMS around a BugE vehicle/LFO 24 cell battery system...
http://www.nappepin.com/LithiumEV3.htm
 
lostcoyote said:
any temperature coefficient induced errors to worry about?
would have to calibrate the initial resistor network but maybe the high precision's not a requirement either if using 1% 10ppm metal film. at least all the resistors would track over temperature provided you don't have them sitting on any hot spots on the PWB.
No plans of volume manufacturing. So use average parts and align everything once with a decent meter. Store the offset and scaling factors into the EEPROM. With enough consistency and resolution the MCU can easily make up for lots of things.

I'll give it a try shortly.


Richard
 
There are a few problem areas to the approach.

If you need a 20:1 divider to scale the voltages to the A/D range you end up reducing your A/D resolution by 20, you amplify the effects of thermal drift by 20, even the resistor voltage coefficient amplified by 20 starts to be a noticeable error term. 20x multiplication of the resistor tolerances means you absolutely MUST calibrate every single divider stage and store the gain errors in the MCU for correcting readings.

0.1V resolution is sufficient for a LVC system, but it's not sufficient resolution for decent charge balancing. You can go to 13-14 bit A/D to try and make up for it but now you really have to start battling with the thermal drift problems. A 14 bit A/D has 60ppm resolution (roughly 250 uVolt per count), that's only 6 degrees of temperature on a 10ppm thermal coefficient resistor. Unfortunately 10ppm resistors also cost about $1 a piece. More reasonable costing parts are 25ppm which is only 2 degrees per count of your A/D. Intrinsic thermocouple junctions between the PCB and resistors will be in the range of 40 uV per degree. Resistor voltage coefficients can be in the 5-10ppm range. You also have to deal with noise and ground loop errors at these high resolutions so careful PCB layout becomes important.

The second issue is that those high precision resistors don't come in any larger values than 0.5 M - 1.0 M. You have a voltage divider hanging off each cell, the top cell is going to be constantly drained by ~70uA, but the bottom cell has to supply current for all the dividers connected above it which will be on the order of 1.5 mA. This situation constantly unbalances the battery pack to the tune of 1 Ah a month. Not to mention the danger of undervolting the cells if you leave the dividers connected and don't charge the thing regularly. It might be prudent to implement some way of disconnecting those dividers when you don't need to read the cell voltage.

Other than that it should work.
 
You are going to have to watch out for the Common mode voltage rejection errors of your diff amp from resistor mismatching.

Also the matching of the Mux channel resistances.

You're also going to have more than 45V across your bottom MUX from Ch1b to ch16b when those channels are off. Similar problem for the top mux.
 
Hey, a name that I recognize 8) (Randomly above)

Boy talk is a bit more technical over here on the sphere than it is back at the ranch (GPN) I bet that there is a lot I can learn on here. :D
 
Heya Sheriff Jon! :)

I don't know if it's more technical, but it's more electrical. Pretty schematics too.

There's lots of interesting around this place, read Ho!
 
Thanks for your input, Randomly.

Randomly said:
There are a few problem areas to the approach.

If you need a 20:1 divider to scale the voltages to the A/D range you end up reducing your A/D resolution by 20, you amplify the effects of thermal drift by 20, even the resistor voltage coefficient amplified by 20 starts to be a noticeable error term. 20x multiplication of the resistor tolerances means you absolutely MUST calibrate every single divider stage and store the gain errors in the MCU for correcting readings.
Calibration is expected. Suspect one-time will be sufficient. The initial application is monitoring and logging, so this is a non-critical application.

0.1V resolution is sufficient for a LVC system, but it's not sufficient resolution for decent charge balancing.
Charge balancing is not my goal at this point. Though if you use this system as a charge limiter I suspect 0.1V should be fine. If you charge each cell separately to a 0.2V tolerance it should be possible to realize close to 100% capacity by modifying the charge protocol accordingly. (I'm still using per-cell chargers with my bike. The voltage tolerance on the cheap Voltphreaks chargers is wider than this. No problem.) But I'm a resolution junkie, so will probably be looking for ways to increase it.

You can go to 13-14 bit A/D to try and make up for it but now you really have to start battling with the thermal drift problems. A 14 bit A/D has 60ppm resolution (roughly 250 uVolt per count), that's only 6 degrees of temperature on a 10ppm thermal coefficient resistor. Unfortunately 10ppm resistors also cost about $1 a piece. More reasonable costing parts are 25ppm which is only 2 degrees per count of your A/D. Intrinsic thermocouple junctions between the PCB and resistors will be in the range of 40 uV per degree. Resistor voltage coefficients can be in the 5-10ppm range. You also have to deal with noise and ground loop errors at these high resolutions so careful PCB layout becomes important.
I'm a programmer. My knowledge of electronics is more limited. Voltage dividers seem an acceptable tool to scale the pack voltage to fit the A/Ds range. That essentially maps 80-volts of input (my 20-cell A123 pack) to the smaller 5-volt range (negotiable) of the A/D on my Atmega168 MCU. Roughly, 80-volts in equals 5-volts out. 40-volts equals 2.5-volts. 20-volts in from the battery pack equals 1.25-volts at the A/D. Simple division.

Now to show some real naivete ...

If there was an inexpensive way to electronically shift (not scale) the input voltage range down you could gain a lot of resolution. Example: 80-volt input equals 5-volts at the A/D. 40-volt input equals 0-volts at the A/D. To allow focusing on the upper half of the pack (in this example.)

If it were possible to shift cleanly and linearly you could double the resolution (in this example) or quadruple it ... etc. It's already possible to realize greater resolution on the lower cells, of course. The bottom cell could be read without a divider and utilize the full resolution of the A/D. Subsequent cells need more and more division with the greater loss of resolution that ensues. I've been told a zener diode might be able to effect the voltage shift. But I know very little about them or what kinds of problems they might create. Things are much easier in the virtual world ... :) Complexity and parts count may be prohibitive.

The second issue is that those high precision resistors don't come in any larger values than 0.5 M - 1.0 M. [...]
Calibration is expected. Low precision parts should be fine if they don't impart additional drift of some sort.

You have a voltage divider hanging off each cell, the top cell is going to be constantly drained by ~70uA, but the bottom cell has to supply current for all the dividers connected above it which will be on the order of 1.5 mA. This situation constantly unbalances the battery pack to the tune of 1 Ah a month. Not to mention the danger of undervolting the cells if you leave the dividers connected and don't charge the thing regularly. It might be prudent to implement some way of disconnecting those dividers when you don't need to read the cell voltage.
Not a concern at the moment. But will be, should this pan out for other functions.

Other than that it should work.
Cool!

Thanks,

Richard
 
lostcoyote said:
maxim makes a 16:1 or dual 8:1 MUX which handles rail to rail input voltages as well as a supply voltage of +/-20v.

http://datasheets.maxim-ic.com/en/ds/DG406-DG407.pdf

going with something like that, one could use a much smaller divider network (not 20:1) and tap near the middle of the battery pack network as virtual ground (or at the most negative if desired). [...]
I think I have some of those. Will probably play around with the onboard 6-channel mux to start though.

simplified schematic:
(note that the MUX enable pin can be used to shut off the divider chain when not in use) [...]

Cool.


Richard
 
I figured you'd be calibrating it. It doesn't make sense not to take advantage of such a powerful tool that an MCU with EEPROM makes available. I just wanted to reinforce the fact that the accuracy of a resistor divider system will be very dependent on resistor tolerances.

an ATMEGA168 has a 10 bit A/D, so capable of resolving 1024 levels. If you scale 80V into those 1024 levels you get 80mV per step resolution.

Yes shifting the voltage of a cell down is the ideal solution but there don't appear to be any elegant ways to do that simply and accurately. A zener diode won't work at all. Linear Technology has an app note on measuring cell voltages in battery stacks where they measure each cell voltage through a custom transformer. Differential amplifiers can do the job but you again run into the resistor precision problem and the common mode voltage gain problem. They also list a number of approaches in that app note as well that don't work well and why.

You also need to be careful of leakage currents in your dividers since with 1M -10Meg resistors it won't take much leakage current into a node to throw your measurements all out of whack.

Don't hook up those mux's as lostcoyote has them in that last schematic, you'll fry them. He may come up with a fix.

if I were you I'd just do the voltage dividers, calibrate it up and see how it goes.
 
Randomly said:
You are going to have to watch out for the Common mode voltage rejection errors of your diff amp from resistor mismatching.

Also the matching of the Mux channel resistances.

You're also going to have more than 45V across your bottom MUX from Ch1b to ch16b when those channels are off. Similar problem for the top mux.


see note 1 per datasheet above:
(Note 1: Signals on S_, D_, A0, A1, A2, A3, or EN exceeding V+ or V- are clamped by internal diodes. Limit forward current to max-
imum current ratings.)

internal clamping diodes are present. user supplies the current limiting (which is by circuit design with the 1k series resistors at each analog input)

yes on the common mode. need an OP amp with good common mode rejection. the alternative is to place virtual ground on cell 8 and operate the mux with +/- supply voltage taps (not a problem).... the alternative is probably better anyways so why not just do it. cuts the common mode voltage down by 1/2 at worst case. back a ways in the 30 something pages so far on this topic, someone presented an OP amp topology for extending the CMRR. my schematic is a simplified representation (sorta like a block diagram) where one would make the diff amp whatever it needs to be to meet CMRR requirements.

an alternative would be to divide down the voltages to within the range of the ADC input range (10v in this case per data sheet) and use a single mux. then let the PIC controller do the subtraction.

btw, the mux given above has 8 ohms matching betwen channels (not bad) with RdsON =100 ohms.


given that the parts are cheap to build one up, it would be worth building and give it a test over temp to see how it does.

i'm just tossing this out on the table. in all practicality, i would probably buy an alalog system myself, as is presented in the 16 channel BMS topic. much simpler and probably good enough in my opinion.
 
yes it has clamping diodes and if you limit input currents with resistors it won't destroy the part, but you will be getting large amounts of substrate current injection and I don't think they guarantee that the part will perform properly while it's clamping pins. It's very likely some of that clamped current could end up in your active channels causing large errors.

also you will be flowing significant currents out of the cells for all the pins that will end up clamping. For Mux B you'll be clamping 6 inputs with the worse case of something like 20 volts across your 1k resistor. I think that would exceed the current specs on the device. You'll need to increase your series resistors and/or clamp the voltages outside the device with schottky diodes. You'll also have to deal with all that current drain out of battery which again won't be the same for each cell. It'll tend to unbalance the pack over time.

also remember matching within 8 ohms with a 1k source resisistance is on the order of 8000 ppm error.
Another issue is the 100 ohm channel resistance is highly temperature dependent and will probably get up to 150 ohms at 80C and down to 70 ohms at -20c. These issues may cause temperature dependent gain errors.

The opamp common mode rejection ratio won't be as important as the common mode errors from the mismatching of your 10k and 1K resistors. I would suggest the LT1990 differential amp which already has resistors that are laser trimmed to match to high precision. You could actually just use one LT1990 per cell as a diff amp and then mux the outputs of the opamps into your A/D although that would get a bit pricey. But it would do the level shifting and be reasonably accurate for 16-24 cells.
 
sounds like it's time to scrap the dual MUX plan/diff amp plan.

(schematic deleted)

if cost is not such an issue
(from a hobbyist standpoint where one is building 1 or 2 units, it may not be as compared with total battery cost)


why not just place an AD628 instrumentation amp at each cell and power it off some taps that can supply like 10v. The datasheet says it handles common mode voltages of +/-125v and is also speced with a CMMR of 75dB.
http://www.analog.com/static/imported-files/Data_Sheets/AD628.pdf
with a 50v common mode voltage, this corresponds to ~9mv common mode voltage error - i'd think that getting the cells to within 10mv is pretty darn good.

the parts are like $5 and so for a 16 cell system, you're talking about $80.

feed the outputs of the instrumentation amps into that 16:1 MUX and then into a high input impedance ADC and you've got it. because the ADC has high input impedance (or stick a voltage follower in there if it doesn't), the Rds-ON becomes negligible.
 
Back
Top