algorithym to calculate MAH on a battery charger

Greetings,

I'm trying to write a routine to calculate milliampere-hours (MAH) for a battery charger I'm designing. The approach I'm intending to use is to sample the charging current once every second, store the first sample in a 32 bit accumulator and add all following samples to it while keeping track of the number of samples. Every ten seconds or so, I'll divide that sum by the number of samples to get the average current. If I then multiply that by the percentage of an hour that has passed I should think that would be the current MAH that has been input into the battery. Total charge time will only be a couple of hours.

Does anyone see anything wrong with this approach?

Thanks for you help.

Reply to
Art K6KFH
Loading thread data ...

I think that'd be doing it the wrong way round. You shouldn't ever have to "sample" the charge current in an MCU-controlled battery charger. That current is supposed to be the primary parameter your MCU is in control of. As such, your program should already know by itself each time that current is changed. So log those events, with a timestamp from your timer you keep running in the background. The maths stay the same.

Unnecessary. Just add them up. If you sample each second, each milli-amp you sampled counts as one milliamp-second. You only have to divide at the end, by 3600 seconds/hour, to adapt the units.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

You would have to measure current as part of the control loop. The milliamp/seconds is what I use.

Reply to
Neil Kurzman

Thanks, Hans. I hadn't thought of it in those terms. MASecs works just fine.

Anyone else have ideas?

Art

Reply to
Art K6KFH

I meant to reply to that in my other update post. The charger is designed for Lithium Polymer batteries and the charger switches from constant current to constant voltage at 4.2volts and the current begins to drop from that point on so I do have to sample it periodically.

Thanks again, Art

Reply to
Art K6KFH

What if you don't know the current ?

You might want a running answer and not have to wait an hour or 2....

Reply to
booboo

[...]

Then you measure it. What I was trying to point out there that there's a significant probability that there's no need to measure, because the MCU will have told a current source what current to supply to the cell being charged --- that's how charging tends to work: you set a current, and watch the voltage, rather than the other way round.

Then you divide each time you need an update of the running answer. Or just get used to getting answers in units of milliamp-seconds, instead of the more conventional mAh.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

Or just divide by 3600 :) Since you are counting mA-seconds the amount of time the count runs for isn't relevant. It's just a change in the unit of measure. 3.6A for 1 sec is the same as 1 mA for 3600 seconds. Whether the battery can take that kind of charge is another question.

Robert

Reply to
R Adsett

That depends on the battery type, which I don't see mentioned in this post (was it somewhere in the thread? then I missed it). You are right for NiMh/Cd. But for Lead Acid batteries, you set the voltage (and a current limit) and observe the current.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

Magic is always the best solution -- especially reliable magic.
Reply to
Stef

I guess I should have clarified myself. I'm designing a Lithium Poly battery charger. This requires a constant current until the cell reaches 4.2 volts at which time it changes to a constant voltage of

4.2 volts and the current begins decreasing until it drops to some arbitrary value. During this time the current isn't controlled by the charger and so it has to be measured periodically. It spends a lot of time in this last part of the charge. Thanks to previous posters I have resolved the problem. Thanks for all your responses.

Regards,

Art

Reply to
Art K6KFH

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.