Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: galannthegreat on May 04, 2010, 02:53:10 PM

Title: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 04, 2010, 02:53:10 PM
I am wanting to build a circuit that will detect the level of a battery and report it to an MCU. Is there any devices that are good for this? Any circuits that will work here?

Pretty much I want to be able read the level of my battery, send it to an MCU, then output it to an LCD or some other system.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Cristi_Neagu on May 04, 2010, 03:54:52 PM
Use an ADC pin on your MCU. If you use a battery with a higher voltage than your maximum voltage input on the ADC pin, use a voltage divider.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Razor Concepts on May 04, 2010, 04:04:27 PM
Unfortunately that will not be very accurate, as under load the battery voltage will drop, so a true reading of charge level can't be read.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Cristi_Neagu on May 04, 2010, 04:14:59 PM
Well, you could either measure the voltage under light load (not powering motors and other such big consumers), or you could say: if the battery voltage drops under x volts under load, than that means that it's almost depleted. If you plan to use say a 6V battery pack, and under load it drops to 2-3V, then it's clear that that battery pack is either too weak, or almost empty.

Of course, the best way would be to measure the voltage and the current drawn, and work out the power. But you need current sensors for that (which, BTW, you also connect to the ADC pins).

Good luck.
Title: Re: Ideas for determining the charge level of a battery.
Post by: madsci1016 on May 04, 2010, 04:51:43 PM
There are two ways to approach this.

A 'coulomb counter' method, basically track current flow out of the battery. You know your battery has X Amp hours, and has been drawing Y current for Z hours. Battery left = X - YZ. This method does not have to worry about voltage drop under load, but it means you have to store the amount of current 'used' in non-volatile memory to keep the number between MCU  power cycles. Also, you will eather have to write to memory often (and burn out the memory space) or have a 'controlled shutdown' button on your robot that stores the variable before you turn it off.

The other method is to model the voltage vs time curve of your battery as it discharges.  Once you have that model, you can read the present voltage of your battery, and compare it to the curve for capacity remaining. To account for voltage drop because of load, you can also measure current at the same time, and (assuming you know / can measure the internal resistance of your battery) account for the voltage drop by adding    Internal Resistance * current    to your measured voltage.
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 04, 2010, 05:11:02 PM
Thanks for the tips. I've been looking at a circuit that uses an LM324 as comparators to detect different levels and output to an LED (working on other circuitry to use MCU input to read data).

You think this would work?
Title: Re: Ideas for determining the charge level of a battery.
Post by: Soeren on May 04, 2010, 06:42:57 PM
Hi,

Unfortunately that will not be very accurate, as under load the battery voltage will drop, so a true reading of charge level can't be read.
What?
It's exactly how you'd get a measure of the charge level, as the unloaded voltage tells you nothing about the charge level (assuming non-lead-acid).

If the measure is taken using whatever light (but known) load is on it with the controller as the load and then after the motors (or a known resistive load) has been engaged for 100 ms, you could get a very close estimate of internal resistance (R_i) of the battery and that relates directly to charge level.

The charge level/R_i function will have to be found for the battery in question.
Title: Re: Ideas for determining the charge level of a battery.
Post by: tmoney68 on May 04, 2010, 09:06:19 PM
I used a LM3914 to drive a LED bar graph directly. Much like the circuit in the pdf I've attached. Its nice and simple and doesn't require any programming.
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 05, 2010, 10:42:06 AM
Thanks for that idea, I really like it.
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 05, 2010, 11:49:16 AM
Just a quick question, what do you measure the outputs at when the LED is on or off? Does it give levels that are easily converted to digital?
Title: Re: Ideas for determining the charge level of a battery.
Post by: tim_wang on May 05, 2010, 03:03:11 PM
There are two ways to approach this.

A 'coulomb counter' method, basically track current flow out of the battery. You know your battery has X Amp hours, and has been drawing Y current for Z hours. Battery left = X - YZ. This method does not have to worry about voltage drop under load, but it means you have to store the amount of current 'used' in non-volatile memory to keep the number between MCU  power cycles. Also, you will eather have to write to memory often (and burn out the memory space) or have a 'controlled shutdown' button on your robot that stores the variable before you turn it off.

The other method is to model the voltage vs time curve of your battery as it discharges.  Once you have that model, you can read the present voltage of your battery, and compare it to the curve for capacity remaining. To account for voltage drop because of load, you can also measure current at the same time, and (assuming you know / can measure the internal resistance of your battery) account for the voltage drop by adding    Internal Resistance * current    to your measured voltage.

Your model for the coulomb counter will not work because the battery capacity is affected by many factors including self discharge, temperature, and current draw.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Razor Concepts on May 05, 2010, 03:04:42 PM
Just a quick question, what do you measure the outputs at when the LED is on or off? Does it give levels that are easily converted to digital?

Why in the world would you want to do this? Just use a voltage divider and a ADC pin.
Title: Re: Ideas for determining the charge level of a battery.
Post by: madsci1016 on May 05, 2010, 04:27:40 PM


Your model for the coulomb counter will not work because the battery capacity is affected by many factors including self discharge, temperature, and current draw.


No system is 'perfect' and all the variables you mention are also dependant on chemistry of battery, but it works 'well enough'.  Many of the fielded robotic systems I use at work use this method to track battery charge level, and itls been fairly accurate.

Also, I did mention you had to track current draw.
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 06, 2010, 12:30:13 PM
Just a quick question, what do you measure the outputs at when the LED is on or off? Does it give levels that are easily converted to digital?

Why in the world would you want to do this? Just use a voltage divider and a ADC pin.

Why you ask? Partially because I can, it simplifies it, no need for ADC conversions. Working with digital is far easier for me. I can just use a MUX to stick it all on one line and read what I need. Also I have pretty much all ADC's being used for other purposes.

But that is a good idea, and I will use that for future projects.
Title: Re: Ideas for determining the charge level of a battery.
Post by: waltr on May 06, 2010, 12:59:20 PM
For a simple digital signal for 'battery ok' or 'battery needs changing', one could use a voltage comparator IC like the LM339.
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 06, 2010, 01:22:34 PM
Yea, that's what I'm currently looking at atm. I'm gonna use one of those to get 4 different battery levels, condition the compartor outputs with buffers to get true logic levels, then I'll multiplex them to read it all from the one input I wanted to use.

Thanks all for your suggestions and help, I really appreciate alternate opinions.
Title: Re: Ideas for determining the charge level of a battery.
Post by: TrickyNekro on May 06, 2010, 01:28:40 PM
Basically, it can get as complicated as you want....
Some of the best methods to measure current in and out is inductance...
With a small transformer you can keep track of how much current has been in or out of the battery...
Of course the name transformer is quite symbolic... It's basically some coils around the same toroid...
One or two turns for the "load" coil is more than enough...

Then if you want accurate enough charge indication... you keep in mind the charge curve of the battery
and as said you keep track of the battery internal resistance with battery voltage accumulation and current draw
accumulation....

Basically... It can get as mean as you want.... your call...
But the meanest the better... ;-)
Title: Re: Ideas for determining the charge level of a battery.
Post by: galannthegreat on May 06, 2010, 02:27:47 PM
That's a good way to think about things. Measuring current can be quite... well... interesting. I can think of a way using your idea is using a very accurate inductor along with a magnetic flux sensor to measure current. Come to think of it, it wouldn't be too hard to make, just abit annoying to tune.

Thanks for the idea.
Title: Re: Ideas for determining the charge level of a battery.
Post by: TrickyNekro on May 06, 2010, 02:49:40 PM
No need... to measure induction like this....
you can measure very accurately induction with a coil...
And one toroid with a few turns coil for the battery and some 100 turns for the sensing is simply then best idea...
Note that number 100 is just a random number... you should use a proper equation to get the correct number of
windings...

Coils are good... but they produce current surges, and the more violent the demand for energy ( or current if you like)
is, the more violent the surge would be...
So there is a good chance you will NEED capacitors... Creating something like an RC oscillator filter....
That's for the Load coil!!!!
Especially if you re using PWM to drive heavy loads....

And also you MUST calculate the RC oscillator Q or quality factor to be as low as possible with some well calculated
tolerances... Or capacitors dielectrics will start to fly in no time.... :o :o
Title: Re: Ideas for determining the charge level of a battery.
Post by: Soeren on May 07, 2010, 01:40:38 AM
Hi,

A current transformer won't tell diddly about the battery charge level, only about instantaneous current, so to measure the amount of energy drawn, you still need other circuitry.
In fact, it doesn't matter whether you use a current transformer or eg. a low ohm resistor, but the resistor will be a lot easier to install, will take less real estate and less calculations (and is better understood by most hobby builders).

Current transformers have their places, but this isn't one of them.
Title: Re: Ideas for determining the charge level of a battery.
Post by: TrickyNekro on May 07, 2010, 02:39:21 AM
With transformers you get the change in current consumption... and if you ask me quite accurate with multi windings....

Of course you got to accumulate the data to find current in or out of battery and need also to monitor voltage of the battery...
So that you know the power consumption which is quite helpful... as you can judge based the maximum energy storage of the battery.... Easily... Of course you may need some more calculations here based on cell resistance but I haven't excluded more trouble to get a good reading...

Playing around with inductance is like a quad encoder... Quite difficult to install, more program lines but better results... Basically... it's a quad encoder for current...

And it's "Ideas" for determining the charge.... so on...
And that's not a bad idea at all... complicated yes... Already implemented yes... Commercialized yes...
What else???
Title: Re: Ideas for determining the charge level of a battery.
Post by: Cristi_Neagu on May 07, 2010, 03:11:46 AM
Why not just use a current sensor to determine current drawn? They just clip on the wire and output a voltage proportional with the current that is passing through the wire.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Soeren on May 07, 2010, 07:44:22 PM
Hi,

With transformers you get the change in current consumption... and if you ask me quite accurate with multi windings....
A resistor is every bit as accurate!


Playing around with inductance is like a quad encoder... Quite difficult to install, more program lines but better results... Basically... it's a quad encoder for current...

And it's "Ideas" for determining the charge.... so on...
And that's not a bad idea at all... complicated yes... Already implemented yes... Commercialized yes...
What else???
Yes, it's a very bad idea, ultimately bad as a matter of fact.
Complicated, no, not really, current transformers are very simple, wind the calculated amount of copper (+ some for good measure, i.e. loss) around a powdered iron core donought, tailor the output impedance and voltage with a trimmer in parallel and a resistor in series and you're done. But a resistor is still simpler.
Already implemented, yes, for AC
Commercialized yes, for AC
What else??? Try: Incapable of working with DC at all, yes, very much so.

This is all flaming nonsense relative to the precision debate however, if you pardon my French.
There is absolutely no gain in precision by using a current transformer over using a resistor - KISS!

The advantage of current transformers is that you can measure high current AC voltages with a low primary drop and galvanic isolation, not that you can get better precision (an inductive shunt will actually be of lower precision than a pure ohmic shunt, as it will be very frequency dependant unless "wound on air").
Since the voltage is within safe levels, you don't need isolation, so a resistor is the simpler solution (and it will work, contrary to the transformer idea).

Before you repeat yourself once more about the brilliance of a current transformer in this app, I think you need to explain this revolutionary technique you use to measure DC current with a transformer   ???

The current transformer will only be precise at 0A current I/O, which doesn't appear at any time with a battery connected due to the self discharge of same, but at least it will be fairly accurate until the vehicle actually consumes power ;)

If the resistor seems too low tech, too simple and too resilient, a Hall current sensor could be used, but at a price about 100 times as high, trouble with adjusting the width of the sensor track, it's distance relative to the sensor and the real estate it takes...

Going with a resistor is a no-brainer.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Cristi_Neagu on May 07, 2010, 11:13:35 PM
I'm asking this out of pure "academic" curiosity, not to start an argument.

It's all fine with low current and moderate voltages. You could stick a 5W resistor, measure the current drop, and there's your current. But what about larger currents? What about 15V and 10A? A 1 ohm resistor would need to dissipate 100W. That's big and it's a waste of power. What to use then? Or is the resistor wired in some other way, not in series with the consumer?

I ask this because, while looking over current choppers, they all seem to use a series resistor to measure a current drop. When that gets too big, it starts an oscillator that switches a series transistor on/off. Like i said, all fine for low power, but what about bigger power?

Thanks.
Title: Re: Ideas for determining the charge level of a battery.
Post by: Soeren on May 09, 2010, 12:15:36 PM
Hi,

It's all fine with low current and moderate voltages. You could stick a 5W resistor, measure the current drop, and there's your current. But what about larger currents? What about 15V and 10A? A 1 ohm resistor would need to dissipate 100W. That's big and it's a waste of power. What to use then? Or is the resistor wired in some other way, not in series with the consumer?
The voltage doesn't really matter (as long as we're not talking dangerous to touch voltages).
You wouldn't use a 1 Ohm resistor for 10A of course. You allways need to addapt the value to what you want to measure.
With 10A, a 10 mOhm resistor would give you 100 mV and dissipate 1W.
If that's considered to little for measuring, 100 mOhm will give you 1V at 10W and that is a lot of wasted power and too large a drop IMO.
When you're talking high power (think EVs) with killerWatts of power, a resistor is totally out of the question.
That's when you break out the Hall sensors, which can measure current draw (mostly +/-) directly on the trace/wiring.
Some examples from Allegro (http://www.allegromicro.com/en/Products/Categories/Sensors/currentsensor.asp)

I ask this because, while looking over current choppers, they all seem to use a series resistor to measure a current drop. When that gets too big, it starts an oscillator that switches a series transistor on/off. Like i said, all fine for low power, but what about bigger power?
"High power" is not really something I associate with hobby robots, but even 1W of loss can be detrimental of the very same reason.
This PDF (http://www.lem.com/docs/products/fhs%2040-p%20sp600.pdf) is the datasheet for a very versatile sensor going to around 100A (or 5A, or whatever in between depending on PCB design). It is not expensive and I have seen it in some online stores (just don't remember which at the moment.
Title: Re: Ideas for determining the charge level of a battery.
Post by: TrickyNekro on May 09, 2010, 12:31:37 PM
That was an answer and thank you!

I have used a resistor before... It's the very high gain of the op amp that frightens me...
Even worse... the digital ones like the once I used from Dallas... seemed to lick somehow current...
I don't really give credit to me schematics... but something must have been going awfully bad...

So let me be stupid... I'll give a try when I have time...
Surely it isn't stuff for new guys... But for me... it's what I study... or at least try to...  :P


Thanks again, your reply was more than astonishing... (I should have shut the f... up by now)
But... I KISS nobody  ;D ;D ;D

Best Regards, Lefteris
Greece
Title: Re: Ideas for determining the charge level of a battery.
Post by: Soeren on May 09, 2010, 12:53:00 PM
Hi,

But... I KISS nobody  ;D ;D ;D
Doesn't that make your mother sad   :P

hehe, you're welcome and no kisses needed, my s.o. is in the kitchen now, so I'll just go there for that (and a refill ;D)