A PIC based Battery Management System

OK, but I've been an analog guy all my life, so it's hard to adapt. I really don't know squat about microcontrollers.

After reading the comparison of PIC programmers and Atmel programmers, I think the Atmel looks better. :wink:

Here's one that would work as a single cell unit:
http://www.atmel.com/dyn/resources/prod_documents/doc2535.pdf
The ATtiny13, which has a 10 bit A/D and lower power consumption.

To calibrate the possibly marginal internal voltage reference, you could use one of the I/O pins to trigger a calibration mode. Feed in the desired upper voltage and hit the button (or use a jumper). The lower voltage could be just programmed in and based off the upper one. I think the upper voltage accuracy is more important.

A single cell unit can drive the shunt switch directly, and only needs to send a signal to the controller or charger for reaching the voltage limits.

Single cell units would scale nicely to any number of cells.

You might still want a separate controller to handle the charging current and display info about which cell is reaching the set point first. Otherwise you could use fairly simple analog methods for that part.
 
fechter said:
OK, but I've been an analog guy all my life, so it's hard to adapt. I really don't know squat about microcontrollers.
As you can tell, my analog education is somewhat lacking.

fechter said:
After reading the comparison of PIC programmers and Atmel programmers, I think the Atmel looks better. :wink:
:)

fechter said:
Here's one that would work as a single cell unit:
http://www.atmel.com/dyn/resources/prod_documents/doc2535.pdf
The ATtiny13, which has a 10 bit A/D and lower power consumption.
There's a ton of other stuff on that chip too, just in case you need a couple timers, a bunch of RAM, EEPROM, three more A/Ds, an Analog Comparator (Hmm!), `brown-out detection', power-on reset sequencing, or any of the other toys they stuffed in.

Oops, I forgot to mention the two 8-bit PWM channels. You can drive the shunt side with one of those and have a much better/cheaper solution than the discrete approach. Done! Fancy charging curve? Piece of cake.

(PWM is an MCU controlled output that allows the program to quickly and accurately select voltages at will. In steps of 1/100th of a volt, or whatever you need. Very repeatable and very accurate.)

fechter said:
To calibrate the possibly marginal internal voltage reference, you could use one of the I/O pins to trigger a calibration mode. Feed in the desired upper voltage and hit the button (or use a jumper). The lower voltage could be just programmed in and based off the upper one. I think the upper voltage accuracy is more important.
You could do that. But you probably don't need to. These chips have a decent reference on them. Calibrate the first one and go. Ten-bits of A/D is way overkill for this application. On a 5-volt scale that's .005 volts per step. This app. is probably fine with 0.1 volts per step.

fechter said:
A single cell unit can drive the shunt switch directly, and only needs to send a signal to the controller or charger for reaching the voltage limits.

Single cell units would scale nicely to any number of cells.
True.

fechter said:
You might still want a separate controller to handle the charging current and display info about which cell is reaching the set point first. Otherwise you could use fairly simple analog methods for that part.

The great loss with the single-cell approach: although there is plentiful, cheaply acquired accuracy -- that information is not available outside this cell-based sub-unit. So you can't track and log the cell voltages, which would be natural with a pack-based controller.

If something like I2C is available it might fix that. And might be made to transcend the differing ground potentials, not sure.

I've not used the lower-end ATmel chips yet. More research ...

Richard
 
Here's just a generalized configuration for a single cell uP: (pay no attention to the pin#'s)

In the simplest configuration, there would be two optocouplers, one for LVC and one for shunt active (to signal the charger to reduce current). An LED indicator would be good there too.

I did see some of the cheap PICs had serial communication ports. I suppose Atmel has them too.
Since we need optocouplers anyway, they could be sending serial data rather than a simple on/off command. This way you could send actual cell voltages to the main controller.

Can you send serial data one way and get away with only one optocoupler per cell? With a bunch of cells sending at the same time, either the main processor would need separate ports for each one or some other way to prevent data collisions.

Another goofball idea is perhaps there's a way to use capacitors to level shift the communications instead of using optocouplers. I've seen some 'one wire' communication schemes, but I don't know if you can get away with putting a capacitor in series with the line.

A PWM output to drive the shunt switch might be better than a simple on/off, but since the measurement cycle is so fast, even an on/off setup would end up behaving like PWM anyway.
I'm not sure if a FET or Darlington would be best, but either should work.

Since the single cell processors draw a fair amount of current when they are active, it would be good if they could sleep most of the time. If they 'woke up' and took a measurement, then went back to sleep, the average drain could be much less. I bet they could sleep 90% of the time and still take a measurement many times per second. Battery voltages are not changing very rapidly, so we don't need to measure constantly.

 
An 8 pin PIC 12F683 would seem to be a reasonable choice, or, if you don't fancy getting to grips with assembler, then the easy to use BASIC-programmed variant, the PICaxe 08M might be an option. These things have a 10bit A to D, serial comms etc, will work from 3V, have a sleep mode that takes the current down to about 1.5uA and will directly drive an optoisolator. You can literally hook one of these 8 pin chips up to a cell directly, with the only components being the chip, an optoisolator and perhaps a current limiting resistor for the optoisolator LED (I'm not really sure this is even needed, the output pins might well be adequately current limited).

You could either run all the PICs/PICaxes in serial mode, with the optoisolated serial data streams running to one of the multi-input PICs/PICaxes as a master controller, or you could fit up to three optoisolators to each one, each with a different function (LVC, charge limit etc).

These things are pretty cheap (less than $1 for the 12F683, a bit more for the PICaxe version), so such a system would compare well to a hard-wired one. The great advantage such a system would have is that it could be programmed very easily. If you wanted to be ultra-clever, you could measure the characteristics of each cell in your pack and programme each individual PIC to respond in a custom way to the cell it was connected to.

The PIC 12F683 datasheet is here: http://ww1.microchip.com/downloads/en/DeviceDoc/41211D_.pdf and the PICaxe data is on this site: http://www.rev-ed.co.uk/picaxe/

Jeremy
 
Why can't the multiple pic chips all be powered from one source? A "master" pic sending power on demand to the string?
Jeff
 
The circuit is easier if each PIC is powered by the cell it's monitoring, as this allows the isolation to be provided "digitally" via the output optoisolators.

Powering a PIC, or PICs from a common source requires an A to D with a very large input voltage range, or some form of analogue isolation. Both of these are tricky to sort, so it's much simpler to just have a PIC connected to each cell and powered by that cell. The PIC has a sleep mode, so only needs to wake up for a maybe a second or so every minute or two to monitor the cell it's connected to. This keeps the power consumption to a minimum. The sleep period could easily be programmed in to be dependent on the rate of change of the previous few readings, which would allow the quiescent current to be reduced even further.

Jeremy
 
Just turned on my monitor ... wrote this post in the wee hours and forgot to post it ...



Half an idea ...

Sample and hold.

One MCU for the whole pack.

One small capacitor across each cell charges up to it's current voltage.

To read the voltage of a cell the capacitor is disconnected from it and
connected across the A/D. No MUX, no divider resistors.

An MCU with enough I/O lines can do lots of switching.

Or perhaps one optocoupler with a moveable ground? No MUX, etc.

Signal to turn on a shunt can be delivered to a cell at the full voltage of the pack. With a ten cent 5-volt zener sharing the cell's ground to bring it back down to logic level at the shunt.


Richard
 
fechter said:
Here's just a generalized configuration for a single cell uP: (pay no attention to the pin#'s)

In the simplest configuration, there would be two optocouplers, one for LVC and one for shunt active (to signal the charger to reduce current). An LED indicator would be good there too.

I did see some of the cheap PICs had serial communication ports. I suppose Atmel has them too.
Since we need optocouplers anyway, they could be sending serial data rather than a simple on/off command. This way you could send actual cell voltages to the main controller.

Pretty sure all the Atmel AVR processors have serial ports -- it's how they're meant to be programmed. And debugged.

fechter said:
Can you send serial data one way and get away with only one optocoupler per cell? With a bunch of cells sending at the same time, either the main processor would need separate ports for each one or some other way to prevent data collisions.

When you're short of I/O lines on a microcontroller you add a shift register. Daisy chained shift registers give you lots and lots of I/O lines.

http://www.windmeadow.com/node/20

Requires 3 I/O lines on the MCU. (I've seen the 74HC595N 8-output shift register latch for $.23 quantity 1.)

fechter said:
Another goofball idea is perhaps there's a way to use capacitors to level shift the communications instead of using optocouplers. I've seen some 'one wire' communication schemes, but I don't know if you can get away with putting a capacitor in series with the line.

I love goofball ideas! :)

I've been developing a hardware neophyte's hunch that optocouplers are overkill for on/off logic levels.

And, optocouplers are for listening to conversations next door. Our cells are in the house. We share a ground with our cell array.

fechter said:
A PWM output to drive the shunt switch might be better than a simple on/off, but since the measurement cycle is so fast, even an on/off setup would end up behaving like PWM anyway.
I'm not sure if a FET or Darlington would be best, but either should work.

Makes sense. Simplicity is good.

fechter said:
Since the single cell processors draw a fair amount of current when they are active, it would be good if they could sleep most of the time. If they 'woke up' and took a measurement, then went back to sleep, the average drain could be much less. I bet they could sleep 90% of the time and still take a measurement many times per second. Battery voltages are not changing very rapidly, so we don't need to measure constantly.

Perfect.


Richard
 
Jeremy Harris said:
An 8 pin PIC 12F683 would seem to be a reasonable choice, or, if you don't fancy getting to grips with assembler, then the easy to use BASIC-programmed variant, the PICaxe 08M might be an option. These things have a 10bit A to D, serial comms etc, will work from 3V, have a sleep mode that takes the current down to about 1.5uA and will directly drive an optoisolator. You can literally hook one of these 8 pin chips up to a cell directly, with the only components being the chip, an optoisolator and perhaps a current limiting resistor for the optoisolator LED (I'm not really sure this is even needed, the output pins might well be adequately current limited).
I consider PIC and AVR roughly functionally equivalent. I have several AVR development boards (~$10 a piece.) I have decades of experience with the free GCC C compiler which has been ported to the AVR. That wins it for me. I'd prefer the title of this thread were `MCU based Battery Management System'. Either brand will do the job. I will be using the AVR for mine.

I can write in assembler and BASIC. For real, important, iterative work -- I choose not to. Assembler is a bad idea for any but the simplest tasks due to complexity. MCU projects tend to get more complex over time and as you realize what's possible. And I don't like BASIC as much as C.

C was designed from the beginning to map straight to assembler/machine code. It's often referred to as a mid-level language rather than high-level. This is why most operating system hardware drivers are written in C today -- Windows, Unix, Linux, etc. BASIC is a non-standard mess, with the better versions somewhat morphing into C. (I've written commercial BASIC compilers.)

If some fancy algorithm is needed for something you can often find it on the net. If C code is available it will probably just plug in and work. Not gonna happen with BASIC, definitely not with assembler.

The hardware developed for a PIC will, in most cases, transplant to an AVR (or vice versa) with very little trouble.

Richard
 
I think a capacitor will be plenty to bridge ground potentials for serial data. The trick will be to format the data so that there is no DC component. RF links do this all the time. For RS-232 formatted data a simple way to do this is to always send a byte and it's inverse. (i.e. "byte" then "not(byte)" ) Additionally since RS-232 idles as a one, either idle data should be sent, or the serial data pin should idle as an input. Another bonus of the capacitor is that it's easy to use it for data going in both directions.

Also, just because a MCU has only one serial port doesn't mean that you can only have one serial communication port. It's quite possible to create a serial port (or anything else) in software. The hardware peripherals are just usually operate faster and independently from the main program.

Marty
 
Fechter, what's a good capacitor value to start with on your 20:1 divider?

file.php


I want to give that a try shortly.

Richard
 
Okay, I just had a crazy idea. Someone may already have suggested it, I don't remember. Apologies if so.

What if the single central MCU had a floating ground. (We'll figure out where it gets it's power from later.) It could cycle through all the cells selecting each ground one at a time. One shared A/D.

Wouldn't that simplify and fix just about everything else? Except for talking to the outside world. Which it could do via optos. Then we'd get the full resolution of the A/D. At 10-bits that's .005 volts per step. Cool.

This means shunts need to be latched, but I think that was the plan anyway.

Richard
 
rf said:
Okay, I just had a crazy idea.
Hey, I'm the man with the crazy ideas... :wink:

I'm not sure how this tangent of using a capacitor improves anything. Is the idea that you provide a storage facility so as to slow or smooth current?
 
rf said:
Fechter, what's a good capacitor value to start with on your 20:1 divider?

I want to give that a try shortly.

Richard

I'd try something between .01 to .1 uf. As long as it's much larger than the 200pf sampling capacitor in the A/D, the charge won't be changed much by sampling.

Safe, a capacitor allows a voltage difference between a signal sorce and destination. It passes an AC signal, but blocks DC. There can be problems if the DC is not really steady and has noise on it. This noise will typically be low frequency, so by using a small enough capacitor, you can block most of the noise too.

To couple data to a floating MCU through a capacitor, the frequency of the data has to be pretty high so that the transients in the battery during discharge don't pass through and cause false triggering. I think lawsonuw is on the right track there if we don't want to use optocouplers.

I did a bit a searching on optocouplers. They're only about $.32 ea and will prevent problems caused by transients in the battery. I guess they're not so expensive that they need to be avoided. They are also available in quads, if we want to reduce the part count.

In the one MCU per cell approach, it seems like it might be possible to use a single optocoupler to send both the low voltage signal and the shunt active signal. You're not usually charging and discharging at the same time.

In thinking a bit more about it, the uP would sense the voltage reached the upper threshold during charging and increase the PWM to the shunt. When the shunt reaches around 95% duty cycle, then it needs to signal the charger to start reducing current. This way the maximum possible charging current will be allowed (well at least 95% anyway) during balancing. Using a higher shunt current does not change the software.
 
safe said:
rf said:
Okay, I just had a crazy idea.
Hey, I'm the man with the crazy ideas... :wink:

I'm not sure how this tangent of using a capacitor improves anything. Is the idea that you provide a storage facility so as to slow or smooth current?

There have been several references to capacitor tricks. One of mine was wondering if there was a way to sample a cell voltage at one ground level and cheaply move the capacitor to the central MCUs ground to measure it. Thus using a cheap capacitor to bridge the different ground potentials.

--

On another sub-thread, Looking back through recent posts, I see that Patrick suggested a floating ground earlier. That may be a topic worthy of more contemplation by the chip-heads (wire slingers?)

Richard
 
Biggest Problem Solved

The biggest conceptual problem with voltage dividers in the past was to solve the math, but that's been solved. I've done it over on the other thread, but I just want to give a "heads up" that it is no longer a mystery.

Basically all the cells will have predictable slopes based on the values of their voltage dividers. By flexing the test voltage from 0-4 you can force the cells to tip their hand and divulge their secrets of their slopes. Once you know their slopes it's a trivial "y = mx + b" math problem that someone could have figured out in high school.

Just wanted everyone to know here... 8)

Voltage Divider + PIC = No Brainer Solution

(however beyond about 4 cells it might not work as well)

file.php
 
Using a capacitor to "transfer" a voltage measurement to the ADC would work, but you'd need the equivalent of a MUX to make it work. You could make such a MUX out of optocouplers with FET outputs. They have an on resistance of around 100 ohms. They may also be refered to as analog switches. It would involve a bunch of logic to get the switches to work in the proper sequence.

The biggest problem is not determining the cell voltages from the tap voltages. That's easy.
There are other problems that are more difficult.
 
fechter said:
A one PIC per cell concept is interesting, but I don't know how you can interface to a CAN or I2C bus with a voltage offset unless you use optocouplers. To be really handy, it would be necessary to communicate both ways to calibrate the individual cell voltage measurements and program the set points for charge and discharge. Some of the 'dumber' PICs are very cheap however.

There are chips specifically made for that. In fact it's easier to find digital in/out chip than analog transistor out optocouples.

Really neat ones don't actually use leds, but a sort of on chip transformer and encoding/decoding logic. Very low power draw, very long life and digital-compatible signal levels. Overview is here:

Selection table here:
http://www.analog.com/en/subCat/0,2879,767%255F827%255F0%255F%255F0%255F,00.html

2 channel chip that can both send and recieve info is $1.6 in large quantity.

The main down sides are SOIC packaging and higher prices. Probably there are alternatives with similar functionality.
 
fechter said:
rf said:
Fechter, what's a good capacitor value to start with on your 20:1 divider?

I want to give that a try shortly.

Richard

I'd try something between .01 to .1 uf. As long as it's much larger than the 200pf sampling capacitor in the A/D, the charge won't be changed much by sampling.

Thanks, Fechter. I'll give it a try.

safe said:
The biggest conceptual problem with voltage dividers in the past was to solve the math, but that's been solved. I've done it over on the other thread, but I just want to give a "heads up" that it is no longer a mystery.

I noticed there are even online calculators for voltage dividers.

Too bad there's not an easy (cheap) way to shift voltage ranges around too. If I divide 100-volts by 20 (cells) then I can feed the result right into my 5-volt A/D and look at the last cell. With a 10-bit A/D with 1024 total steps, only the top 50 steps will refer to the last cell -- the other 974 steps are wasted. The top/last cell is the worst case. The bottom/first cell can use the full 1024 steps. (These are assumptions on my part. I'll give them a try with real hardware later this week.)

Fifty steps is probably enough for our purposes, .1 volt steps. But once you get started with a microprocessor you always find more and cooler things to do with it. I hate to sacrifice precision at the outset.

A voltage divider is like the gain control on an oscilloscope. I'd rather have the position control to keep the same size display and move it up and down -- so I can look at different parts of the signal (cells) with the same resolution.

Hardware is so ... hard ... Making small changes to MCU code can often be done in a couple minutes -- without even unplugging the chip from the circuit.

Richard
 
tomv said:
There are chips specifically made for that. In fact it's easier to find digital in/out chip than analog transistor out optocouples.

Really neat ones don't actually use leds, but a sort of on chip transformer and encoding/decoding logic. Very low power draw, very long life and digital-compatible signal levels. Overview is here:

Selection table here:
http://www.analog.com/en/subCat/0,2879,767%255F827%255F0%255F%255F0%255F,00.html

2 channel chip that can both send and recieve info is $1.6 in large quantity.

The main down sides are SOIC packaging and higher prices. Probably there are alternatives with similar functionality.


Those are cool. That would definitely work, but about the same price as optocouplers.
 
rf said:
Too bad there's not an easy (cheap) way to shift voltage ranges around too. If I divide 100-volts by 20 (cells) then I can feed the result right into my 5-volt A/D and look at the last cell. With a 10-bit A/D with 1024 total steps, only the top 50 steps will refer to the last cell -- the other 974 steps are wasted. The top/last cell is the worst case. The bottom/first cell can use the full 1024 steps. (These are assumptions on my part. I'll give them a try with real hardware later this week.)

Fifty steps is probably enough for our purposes, .1 volt steps. But once you get started with a microprocessor you always find more and cooler things to do with it. I hate to sacrifice precision at the outset.

A voltage divider is like the gain control on an oscilloscope. I'd rather have the position control to keep the same size display and move it up and down -- so I can look at different parts of the signal (cells) with the same resolution.

That's the hard part I guess. A higher resolution A/D like Beagle found (or even a higher one) might be one workaround. A combination of dividers and zeners might work. Zeners would be like adjusting the vertical position on your scope.
 
fechter said:
A combination of dividers and zeners might work. Zeners would be like adjusting the vertical position on your scope.

Following that logic a bit further...

The voltage divider would be used to cut n*(3.65-2.1) to less than 5V and the zener would be used to bring the top end into range.

48V system = 16 cells.

Top cell high = 16*3.65=58.4V
Top cell low = 16*2.1 = 33.6V

Voltage range = 24.8V. Use a ~5:1 voltage divider to adjust that to 4.96V range.

5:1 divided voltage:
top cell high = 11.68V
top cell low = 6.72V

Use a ~6.7V zener.

A/D measured high = 4.98V
A/D measured low = 0.02V

Values would need to be tweaked to match available parts, there are 2% zeners with 6.45V, 6.55V, 6.66V, and 6.75V available. Alternately, you could put the zener before the voltage divider, so you would use a ~33.5V zener, 33V, 33.65V and 33.85V are avialable.

With this setup, the resolution of a 1024 bit A/D would be ~0.03V on the high cell of a 16 cell pack.

Each cell would need a similar computation.

How could the stacked tolerances of a 2% zener, with 1% resistors in the voltage divider circuit, and the A/D tolerance affect the cell's actual vs. measured voltage?
 
How about comm via RF (no wires) or little transformers for isolation. Transformers with high impedance would not draw much at rest, no?
Jeff K.
 
OneEye said:
fechter said:
A combination of dividers and zeners might work. Zeners would be like adjusting the vertical position on your scope.

Following that logic a bit further...

The voltage divider would be used to cut n*(3.65-2.1) to less than 5V and the zener would be used to bring the top end into range.

48V system = 16 cells.

Top cell high = 16*3.65=58.4V
Top cell low = 16*2.1 = 33.6V

Voltage range = 24.8V. Use a ~5:1 voltage divider to adjust that to 4.96V range.

5:1 divided voltage:
top cell high = 11.68V
top cell low = 6.72V

Use a ~6.7V zener.

A/D measured high = 4.98V
A/D measured low = 0.02V

Values would need to be tweaked to match available parts, there are 2% zeners with 6.45V, 6.55V, 6.66V, and 6.75V available. Alternately, you could put the zener before the voltage divider, so you would use a ~33.5V zener, 33V, 33.65V and 33.85V are avialable.

With this setup, the resolution of a 1024 bit A/D would be ~0.03V on the high cell of a 16 cell pack.

Each cell would need a similar computation.

How could the stacked tolerances of a 2% zener, with 1% resistors in the voltage divider circuit, and the A/D tolerance affect the cell's actual vs. measured voltage?


Cool. Zeners are nice and cheap. Not sure how to locate the bottom/ground of each cell though. (It's always something ...) :)

(10-bit A/D == 1024 steps)
 
Back
Top