# Battery Voltage Measurement with OP Amp

Hello Everybody,

In the past I often found a solution here so now I try with something I could not solve with google.

I build a little current controlled battery simulator to charge and discharge cells with different current profiles. For this I have a cell, the charging/discharging circuit and the cell voltage measurement. I use an OP Amp with the output voltage directly connected to an ADC port of an Arduino Uno. The OP Amp has two functions: 1. multiplying the cell voltage times two (better resolution) 2. giving me just the cell voltage since for the charging the negative pole has not the same potential as ground. (see attached circuit figure)

The Arduino gets its reference voltage from an external precision reference (5V.) As you can see in the "test" figure, the measurements works well (precise enough, not noisy) except for one point:

When hitting about 2.44V the measurement starts to jump weirdly as if the resolution has decreased a lot. Does anybody has an idea why this could happen?

I already tried to measure precisely 2.5V with the result of an output voltage of 5V at the OP AMP and 2.49something as Arduino output. I have a bit of the feeling that it could be the Arduino, but not a slightly hint where to start looking.

In the past I, let’s say, mistreated the analogue input at least once with overvoltage but couldn’t determine any changes in the measurement quality afterwards. Could the route for my error could be somewhere there?

Thank you very much in advance! I hope somebody had something like this before.

Best regards Karsten

What op amp are you using? With many, there are limits on the allowable input voltage range.

The answer might be more obvious if you look up the charged voltage for an NiMh and devide your measured voltage by 2 (assuming you calibrated your op amp circuit and actually KNOW the EXACT GAIN to be EXACTLY 2.000 ) and compare your measured voltage (after dividing by GAIN) to the charged voltage for an NiMh. I mean if the battery is already charged, what do you expect it to do ? (other than go into some kind of "trickle charge " mode, if that's even possible)

a freshly charged AA NiMH cell in good condition is about 1.4 volts.[20]

NiMh battery

jremington: What op amp are you using? With many, there are limits on the allowable input voltage range.

Not an issue with this circuit I think, the inputs are at about 1.2V in the differential amplifer configuration.

It could be genuine signal - check with a multimeter across the cell. However I don't see any decoupling in that circuit - decouple your opamp for stable operation.

Post a complete circuit diagram. The battery appears to be floating, so the reference for V1 and V2 is not clear.

As mentioned, the voltage plotted that looks wierd is actually the battery reaching the charged state at 1.4 V (OP's output voltage is about 1.75 times the battery voltage.) The battery is alternating between charging and discharging at the charged voltage. (probably a few hundred mV)

jremington: Post a complete circuit diagram. The battery appears to be floating, so the reference for V1 and V2 is not clear.

That's not an issue, the differential amplifier circuit will bias it OK - if it wasn't floating there could be a risk of it departing outside the safe operating envelope of the opamp, but as it is it is sitting balanced around 1.2V which should be OK for a modern opamp.

raschemmel: As mentioned, the voltage plotted that looks wierd is actually the battery reaching the charged state at 1.4 V (OP's output voltage is about 1.75 times the battery voltage.) The battery is alternating between charging and discharging at the charged voltage. (probably a few hundred mV)

Interesting theory, but the voltage steps go the wrong way.

When the battery is fully charged , it no longer presents a load and the voltage reverts to an op amp output with no load .

Try adding a bleeder resistor across the battery. (10 k to 22 k ohm)

Measure tge battery voltage with a meter and post the value

That's not an issue

Yes, it is an issue. We have no way of knowing what the rest of the charging circuitry looks like, and how it is connected to the existing circuitry.

We have no way of knowing what the rest of the charging circuitry looks like, and how it is connected to the existing circuitry.

Not to mention we have no idea what the actual resistor values are, what the actual gain is or what the actual battery voltage is when it is charged. I don't see how posting a plot from an amplifier with an unknown (actual) gain will tell us that. We need the plot to understand the symptoms but we need the (actual)voltage measured with a meter to calculate the actual gain.

The circuit is an Op Amp Subtractor

Try adding Voltage Followers in front of R1 & R2

Connect TWO 10 k resistors in series from +5V to GND you should measure 1.66 V and 3.33 V respectively at the two points where the resistors connect. If the Gain of your subtractor is really 2, it should output 4.00 V when you connect V2 to 3.33V and V1 to 1.33V. You use whatever it outputs to "CALIBRATE" it by deviding the output by 4.00 to obtain the "CORRECTION" Factor.

Vo = 2* (3.33V- 1.66V) = 2*2.00 V = 4.00 V

Suppose the output is 3.50V ( instead of 4.00V)

3.50 V /4.00 V = 0.875 1/0.875 = 1.14285714

Correction factor = 1.14285714 1.14285714* 3.50 V = 4.00. V For this case, a battery with a voltage of 1.4 V would (after dividing by gain) read 1.225 V 1.225 * 1.14285714= 1.40 V

Hi everybody,

thank you for all the kind and very valuable comments!

First, I used two NiMH batteries in series for testing purposes and the shown voltage is the actual one.

So the charging starts close to the nominal voltage of 1.2V. Since the cell voltage is rising slowly at this point I thought I take this example to show the effect. Sorry for not making this clear in the first place!

@ jremington: The OP AMP I am using is a LM 358 with a maximal supply voltage and difference Voltage of 32V – so I don’t think it that,

I also attached a complete circuit diagram of the current controlled battery simulator. Yes, the battery is floating. But since the OP Amp gives me only the differential voltage between the battery poles it should be ok.

@raschemmel: I compared the battery voltage with the Arduino outputs before with a reasonable precision. Like I said I charged the cells close from nominal voltage and expect a slow rise. Also it cannot be the cell because the “jump” also occurs with other cell chemistries, following the same pattern. The start of the “jump” varies a bit (2.43V – 2.443V) but the upper value is always 2.46.

I don’t understand how a bleed resistor could solve that. Furthermore I want to get reasonable precise capacity values by integrating the current over time. For this any unmeasured current will increase my error quite a bit.

Also thank you for that suggestion with the correction factor. But I did this already (not as accurate as you) and got reasonable results for the hole voltage range, except the little “jump” always at this position.

I used 56k Ohm for R1 and R2 and 112k Ohm for R3 and R4

@MarkT: Decoupling sounds interesting. However I have no idea how to do this. Would you mind giving me an example or an online link for that? Also suggestions how to make the circuit more robust would be nice.

I tried today to use different ports of the Arduino, no success. But I narrowed down the error a bit: Next to the the figure with the whole circuit I attached my latest measurement: I connected the Vout of the OP AMP directly with the Multimeter and the Arduino (both measured against ground). The result is shown in test3.jpg. The OP AMP output is not governing the “jump”.

So it must have something to do with the Arduino or how it is connected? Should I upload these connections as well?

Thank you again for your help!

Your schematic isn't 100% clear to me. For one thing, you have two nodes named Vout but I know they're not connected to each other.

From the red arrows, however, it seems that you have a mode where you charge the battery through a FET/shunt which is controlled to provide a constant current?

Since your cells get ground through this FET/shunt you are putting a common mode signal at the inputs to your op amp. It sounds like this has the potential to cause the results you're seeing, although I don't have a good reason why it'd happen at the end of charge (when you'd expect the FET to be fully on).

Edited to Add: wait...no...if your FET was fully on at the end of charge, then you'd have 12V across your battery. I don't understand how your FET is controlled...

I don't understand how a bleed resistor could solve that. Furthermore I want to get reasonable precise capacity values by integrating the current over time. For this any unmeasured current will increase my error quite a bit.

i

The OP AMP output is not governing the "jump".

There is no "jump" . That's the battery charging current reducing to "0".

Whether you understand it or not, as long as you refuse to add the bleed resistor your results will remain the same, regardless of anything else you do. As I already stated, the battery or batteries only constitute a "LOAD" in so much as they need charging. Once they are charged, they no longer present a load to the op amp and the op amp see's "no load" and the output oscillates at the last 10 - 15 mV. Adding a bleed resistor ensures that the op amp sees a load and the output will be whatever the charged voltage is because the bleed resistor current with respect to battery current is negligible and it should be obvious that once the battery is charged the charging current approaches 0 mA. Attempting to measure the charging current during the last 0.4 % of the charging cycle is a futile endeavor and you are wasting your time. Your circuit is complete. Just add the bleeder resistors and you should be done. (you may need to experiment a little with the value) Also , you can't charge batteries in series because when one is charged it will stop conducting current. (that should be obvious) Thus the remaining battery will not get any charging current. (which is no doubt linked to your "problem") ( the op amp output is "floating" because there is no load after one of the batteries is fully charged) Remove one battery and replace it with a load resistor. The current is the same through the resistor and the remaining battery. The load resistor needs to drop 1.4 V @ 80% of charging current R = 1.4 V/ Icharging

It's the most basic law (Ohm's Law) of electronics. Current is a function of Difference of Potential and resistance. If the sum of the two batteries is the same as the charger output no current will flow. At some point the current and difference of potential are so small there is nothing to pull down the op amp output and starts to "float" . What you are calling a "jump" (as if it shouldn't occur) is the battery's natural way of telling you one or both batteries are charged and no current is flowing. If you simply accept that fact you can stop collecting data at that point and call it "charging cycle complete" indication. Otherwise, if you refuse to accept the obvious you can add the "bleeder " resistor, starting at the higher value and adjusting value lower until the "jump" disappears.

Also it cannot be the cell because the "jump" also occurs with other cell chemistries, following the same pattern. The start of the "jump" varies a bit (2.43V - 2.443V) but the upper value is always 2.46.

That should tell you something, like , basically, any rechargable battery will no longer present a load once it's charged and your op amp will float and oscillate because it sees no load. (how can it with no difference of potential ? How can the output be pulled low if there is no current ? The only way to pull the output down when the battery is fully charged is to apply a lower voltage and start discharging the battery by sinking current instead of sourcing it. There are no other "options" You are either sinking current (discharging the battery), or sourcing it (charging the battery). You could alternate between the two to keep the voltage at some setpoint but if you simply command the op amp to an output voltage that is exactly the same as the sum of the two batteries, there will be no difference of potential and therefore no current. It's as simple as that. I can't believe how much you are making of a 15 mV fluctuation when the battery is charged. It's not showing up on your meter because it is averaging. Try changing your code to take 10 to 20 readings and average them and print only the average.

"Jump" = (2.47V-2.45V) = 0.020 V (@0.00488 V/ per analog count, this is 3 counts)

Based on the step size of the voltage steps, the "jump" appears to be 3 "steps" or analog counts (3*0.00488 = 0.01464 V) or just under 15 mV.

To call a 15 mV voltage change in a 0 to 2.47V range a "jump" is just ludicrous ( because it represents a 0.4 % voltage change)

Total Charged Battery Voltage = 2.47 V

"Jump"(%) = 100* (0.015 V/2.47V) = 0.59 %

I'm curious. How did you plot your readings ? Did you use a Terminal Capture software and copy and paste into Excel ?

@MarkT: Decoupling sounds interesting. However I have no idea how to do this. Would you mind giving me an example or an online link for that? Also suggestions how to make the circuit more robust would be nice.

Google "decoupling caps" It's just a fancy name for a cap that shunts high frequency noise go ground based on the capacitive reactance (Google "capacitive reactance " and do the math for "Let f = 100000, f = 10000, then f = 1000 and compare the three. What does that tell you about what the cap is doing ?. )

BigBobby: Your schematic isn't 100% clear to me. For one thing, you have two nodes named Vout but I know they're not connected to each other.

From the red arrows, however, it seems that you have a mode where you charge the battery through a FET/shunt which is controlled to provide a constant current?

Since your cells get ground through this FET/shunt you are putting a common mode signal at the inputs to your op amp. It sounds like this has the potential to cause the results you're seeing, although I don't have a good reason why it'd happen at the end of charge (when you'd expect the FET to be fully on).

Edited to Add: wait...no...if your FET was fully on at the end of charge, then you'd have 12V across your battery. I don't understand how your FET is controlled...

OK, I put some time into it and I understand now. If you don't mind, I added some labels to your schematic and reattached here. I'd post it as a picture, but my employer seems to block the free picture hosting sites (BTW - how little sense does it make that the forums will host the pictures as attachments, but not as pictures?).

So if I understand your circuit correctly, T1 is a voltage controlled resistance that results in a constant current through your cells. When S1 is closed and S2 is in position 1, the cells are pulled up to 12V and T1 limits the charge current through the cells. When S3 is closed and S2 is in position 2, the cells are pulled down to GND and T1 limits the cells discharge current. Nice circuit.

It appears in your data you are always charging, which explains why your schematic shows the charging configuration. If your cells are balanced, they should be at ~1.23V. Are you sure they're both 1.23V? If they are, then they should be far away from end-of-charge where their impedance might do weird things.

It seems like your control for T1 must be unstable. As a test, when you see the A/D reading fluctuating like that, could you ground the + input to the amplifier controlling it to see if the A/D reading goes back to normal?

It also seems that the instability must be affecting your Arduino beyond just putting a high frequency on your cells. If your multimeter was just averaging the signal clean, it would be in the middle of the Arduino's samples where your Arduino samples are clearly higher. Possibly T1 being unstable could result in common mode signals getting through the op-amp, or maybe its ground currents aren't separated from the grounds of your op-amp and avr.

Seeing if the A/D readings go back to normal when T1 is forced off, however, would be the first step before figuring out how T1 is affecting your reading.

BTW - how little sense does it make that the forums will host the pictures as attachments, but not as pictures?

The answer is simple. After you post the attachments , click SAVE then put the mouse cursor over the attachment and right click "Copy Link Address", then click Modify, select the image toolbutton (computer monitor icon) and paste the link address into that, then click save. done.

raschemmel: The answer is simple. After you post the attachments , click SAVE then put the mouse cursor over the attachment and right click "Copy Link Address", then click Modify, select the image toolbutton (computer monitor icon) and paste the link address into that, then click save. done.

Well, simple would be the img button having an option to enter a URL or a local file.

But thank you for telling me the workaround.

Well, simple would be the img button having an option to enter a URL or a local file.

The link address of the attachment would be a "local file" but if I'm not mistaken , I think what you were asking was why isn't the forum software smart enough to know an image file extension of an attachment means it should be displayed as an image instead of us having to copy the link address URL and paste it into the image toolbutton prompt window ?

I also attached a complete circuit diagram of the current controlled battery simulator. Yes, the battery is floating. But since the OP Amp gives me only the differential voltage between the battery poles it should be ok.

If you are referring to the schematic posted in Reply#14, it is not complete. The comparator "+" input does not have any input voltage associated with it. There is no part number for the fet. There is no component type or value or label for the cylindrical object , (is that the battery ?)

There is also no circuit description for what appears to be a fet switched by a comparator and nothing more. Is that a modification or addition to the original op amp subtractor ?

raschemmel: The link address of the attachment would be a "local file" but if I'm not mistaken , I think what you were asking was why isn't the forum software smart enough to know an image file extension of an attachment means it should be displayed as an image instead of us having to copy the link address URL and paste it into the image toolbutton prompt window ?

What I'm thinking of is something like adding pics on ebay, craigslist, gmail, etc: when you push the "add picture" button you get a dialog in which you can identify a picture on your local PC or a URL on the web.

raschemmel: If you are referring to the schematic posted in Reply#14, it is not complete. The comparator "+" input does not have any input voltage associated with it. There is no part number for the fet. There is no component type or value or label for the cylindrical object , (is that the battery ?)

There is also no circuit description for what appears to be a fet switched by a comparator and nothing more. Is that a modification or addition to the original op amp subtractor ?

The schematic certainly isn't complete, but it isn't that bad compared to other things posted to the forum.

Yes, the cylindrical objects are the two NiMH cells he mentioned in his post. The FET being controlled by the op amp measuring the current through the FET is almost certainly a constant current control. I was a bit confused by this circuit as I didn't see how he could achieve CC-CV charging, but then I remembered CC-CV is not how NiMH are charged.

He doesn't show the input to the current control op-amp. I assume it's a steady reference, but if it's not then possibly that's the cause of his problems.

Hopefully he comes back and answers, as it is an interesting problem.

He doesn't show the input to the current control op-amp. I assume it's a steady reference, but if it's not then possibly that's the cause of his problems.

There's no current control. That's a simple comparator. What is the cylinder under the comparator ? Is that a battery ? (or is it supposed to be a current limiting resistor ?)