Author Topic: Inconsistent Battery Reading under load  (Read 4498 times)

0 Members and 1 Guest are viewing this topic.

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Inconsistent Battery Reading under load
« on: February 04, 2024, 05:46:49 am »
I have built a battery discharger for RC 1S/2S application.  It has come a long way since I started this project and the unit does a lot of cool stuff, at least I think so.  It uses pwm to discharge to a resistor bank, I have a pid controller setup in the code to maintain and get to the discharge rate.  This is controlled by a 328PB mcu.  The power source is a 12VDC server power supply.  I am using an lm4132 external ref (A) to get as accurate ref for the adc as I can.  The drift on this reference is 10ppm/°C, and the board itself gets pretty warm, so it does drift a little, but not a lot. 

So here is the issue...  I have the code setup at a 10Hz sample rate, I average the 3 analog inputs 100x each, due to the pid controller oscillation this is necessary to get a close approximation of the output.  When there is no load on the battery I get decent readings, at least decent enough to offset the read with consistency.  But when I put a load on the battery, even if it is a straight value to the pwm out so no oscillation, I get a lower value return than I should.  I have a bench top dmm (HP3478A) hooked to the leads of the battery and measuring the value realtime as I am also measuring with my mcu code.  No load they read the same, with a load the mcu reads the value a bit lower than the dmm.  This difference is directly proportional to the load as well.  I have managed to write a simple equation to get correct for it, but nonetheless I am confused why it is there.  The measurement is taken through separate wires than those that carry the current from the load.  It doesn't matter which of my batteries I use, the value remains the same.  I thought maybe this was some sort of internal resistance in the wires being used for measuring, so I tried different length wires, which give slightly different resistance for the wires.  Same value needed to offset this "phantom" load.  My only guess is this is somehow a function of the voltage dividers I am using.  The voltage dividers are 10K, 5K1 and then a 1uF x7r capacitor for a filter.  but the filter doesn't matter, this happens with and without the filter cap. 


Next question.  What is the best way to set the voltage offset for the adc reading of the voltage?  There are 3 ways that I can think of:
1. Add or subract bits as necessary to the raw adc value.  I do this currently.
2. Change the VCC or Vref value to adjust for the offset.  I have this in my code as a user input to "calibrate" the voltage with their equipment.
3. Just add a float variable with an offset value.

Thanks
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #1 on: February 04, 2024, 07:32:56 am »
Can you add some numbers what you have?  (How much voltage changes under what exact load, what exect batteries do you use, what wires for power lines, etc).
« Last Edit: February 04, 2024, 07:37:33 am by Vovk_Z »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11627
  • Country: ch
Re: Inconsistent Battery Reading under load
« Reply #2 on: February 04, 2024, 07:35:53 am »
Without a schematic it’s kinda hard to guess what’s going on…
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1452
Re: Inconsistent Battery Reading under load
« Reply #3 on: February 04, 2024, 09:16:33 am »
I have built a battery discharger for RC 1S/2S application.  It has come a long way since I started this project and the unit does a lot of cool stuff, at least I think so.  It uses pwm to discharge to a resistor bank, I have a pid controller setup in the code to maintain and get to the discharge rate.  This is controlled by a 328PB mcu.  The power source is a 12VDC server power supply.  I am using an lm4132 external ref (A) to get as accurate ref for the adc as I can.  The drift on this reference is 10ppm/°C, and the board itself gets pretty warm, so it does drift a little, but not a lot. 

So here is the issue...  I have the code setup at a 10Hz sample rate, I average the 3 analog inputs 100x each, due to the pid controller oscillation this is necessary to get a close approximation of the output.  When there is no load on the battery I get decent readings, at least decent enough to offset the read with consistency.  But when I put a load on the battery, even if it is a straight value to the pwm out so no oscillation, I get a lower value return than I should.  I have a bench top dmm (HP3478A) hooked to the leads of the battery and measuring the value realtime as I am also measuring with my mcu code.  No load they read the same, with a load the mcu reads the value a bit lower than the dmm.  This difference is directly proportional to the load as well.  I have managed to write a simple equation to get correct for it, but nonetheless I am confused why it is there.  The measurement is taken through separate wires than those that carry the current from the load.  It doesn't matter which of my batteries I use, the value remains the same.  I thought maybe this was some sort of internal resistance in the wires being used for measuring, so I tried different length wires, which give slightly different resistance for the wires.  Same value needed to offset this "phantom" load.  My only guess is this is somehow a function of the voltage dividers I am using.  The voltage dividers are 10K, 5K1 and then a 1uF x7r capacitor for a filter.  but the filter doesn't matter, this happens with and without the filter cap. 


Next question.  What is the best way to set the voltage offset for the adc reading of the voltage?  There are 3 ways that I can think of:
1. Add or subract bits as necessary to the raw adc value.  I do this currently.
2. Change the VCC or Vref value to adjust for the offset.  I have this in my code as a user input to "calibrate" the voltage with their equipment.
3. Just add a float variable with an offset value.

Thanks

Hi,

You may have to show how this is wired physically also, maybe with some pics.

You should check the setup with a source other than what you are using now, if you haven't done that yet.
Maybe a battery and a potentiometer to check the readings on the DMM and the ADC.
It could be that the ADC is averaging differently than the DMM.
Also, you could try a much larger capacitor to average the reading in an analog way rather than digital.
To get the average over N readings, N=100 may not be high enough.  You may have to go up much higher like 10000.  With N=10000 and the cap much larger (like 100uf) you may see more equal results from both measurement techniques.


 

Online PlainName

  • Super Contributor
  • ***
  • Posts: 6867
  • Country: va
Re: Inconsistent Battery Reading under load
« Reply #4 on: February 04, 2024, 09:39:52 am »
Can you put a scope on the wires to see what noise, if any, you are getting? Could simply be that there is ripple which the DMM is averaging out differently to the MCU code.

That was my initial thought when I saw 'PWM' and '10Hz'. But you say it happens also when there is no PWM. I would still want to put a scope on to be sure that there really isn't any at the pointy end.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9961
  • Country: nz
Re: Inconsistent Battery Reading under load
« Reply #5 on: February 04, 2024, 09:47:11 am »
I'm no battery charger expect, but all the hobby RC Lipo chargers i've used turn off charging/discharging for a second to do battery cell voltage checks.
Then either restart charging/discharging or end it, depending on what that reading say about the battery.
From memory they do this every 30 seconds or so.
I can tell it works this way by watching the current on the LCD display, it periodically go to zero for a sec. And whenever the charge/discharge cycle completes it's always during this time. Never during actual charge/discharge.   eg, battery charging is not considered 'complete' until all cells remain over 4.20V when charging is stopped.

Perhaps the best approach to your problem of ADC error from the PID is just to not deal with the problem at all.
« Last Edit: February 04, 2024, 09:56:09 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #6 on: February 04, 2024, 04:37:59 pm »
Can you add some numbers what you have?  (How much voltage changes under what exact load, what exect batteries do you use, what wires for power lines, etc).

It is not a high value.  At 30A it is approximately a 120mV difference, like I said, it changes proportionally with the load and I code it out with the following:

Code: [Select]
voltageFull = ((Fvoltage * (ValueR1F + ValueR2F)) / ValueR2F) + (Icurrent / ulF);

The part you are interested is the last part: (Icurrent / ulF).  ulF = 250 in my code.



Just to clarify, the pwm frequency is 490Hz, not changed from the default on the mcu.  The sample rate in which I read all the calculations is 10Hz, 10x a second.  The average that is taken is 100x on each input.

So the calculations function averages the sensors 100 times and spits that out 10 times a second.  I tried higher averaging without a sample rate, I just let the code loop as fast as it could, but this is a tft touchscreen and I needed to make the touch more responsive. 

The wires that carry the load from the battery to the discharger are 10awg wires, the voltage sensing is done on much smaller wires.  Maybe 24awg. 

Scope output is a DC line.  The noise in the reading is the same noise I get with nothing attached.  I will admit I have a few things running and it picks up noise just being where it is.

I have changed power sources from switched 14V and 12V to a 8.4V battery.  No change in the output. 

I am adding a schematic, a 3d view of the schematic, a pic of the actual wiring, output from my scope after the voltage divider and filter, and output at the battery.

This was a 10A load, the duty cycle is low at this load. 
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #7 on: February 04, 2024, 07:06:24 pm »
I did another measurement, reading the voltage at the voltage divider during a test.  Voltage at the divider matches the raw code for the voltage under a load.  So this is a difference it what is read at the divider vs what is read at the battery.  As I posted in my OP, the original design did not have a filter cap and had the same issue.

Someone posted something about RMS but it looks like the post is gone now.  But if the meter is in DC coupling, why would it measure RMS?  Also I have compared results on both of my DMMs, the 3478A and a Siglent SDM3055.  They are the same. 
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #8 on: February 04, 2024, 08:45:45 pm »
It is not a high value.  At 30A it is approximately a 120mV difference,
Batteries and wires have some internal resistance. 120 mV / 30 A = 4 mOhm, this is not too much. I don't see much inconsistency here.  :-//
Possibly, you may want to use a four-wire measurement circuit instead of two wire? I mean you may want to add two additional wires for voltage measurement purposes only which don't carry large currents, in addition to the main power lines?
« Last Edit: February 04, 2024, 08:50:49 pm by Vovk_Z »
 
The following users thanked this post: tooki

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #9 on: February 04, 2024, 09:22:23 pm »
It is not a high value.  At 30A it is approximately a 120mV difference,
Batteries and wires have some internal resistance. 120 mV / 30 A = 4 mOhm, this is not too much. I don't see much inconsistency here.  :-//
Possibly, you may want to use a four-wire measurement circuit instead of two wire? I mean you may want to add two additional wires for voltage measurement purposes only which don't carry large currents, in addition to the main power lines?

This is a 4 wire measurement.  The current carrying leads are separate, much bigger wires.  Also this isn't IR of the battery or the wires, I can see and calculate those.  This seems to be from the voltage divider that is measuring the voltage, not current. 
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3430
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #10 on: February 04, 2024, 09:25:03 pm »
Mesaured battery voltage depends on battery internal resistance Rs and load resistance Rl.

Load resistance includes resistance of the load and resistance of the ADC or DMM used for measurement.

These two resistance Rs and Rl make voltage divider, so the voltage will depends on exact values of Rs and Rl.

If you're trying to measure voltage with connected load which resistance can vary it leads to variable voltage reading...
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #11 on: February 04, 2024, 09:50:59 pm »
This is a 4 wire measurement.  The current carrying leads are separate, much bigger wires.  Also this isn't IR of the battery or the wires, I can see and calculate those.  This seems to be from the voltage divider that is measuring the voltage, not current.
I'm looking at your circuit diagram now (but have not investigated your PCB yet) and I have a question: do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.
 
The following users thanked this post: tooki, Manul

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #12 on: February 04, 2024, 10:24:28 pm »
This is a 4 wire measurement.  The current carrying leads are separate, much bigger wires.  Also this isn't IR of the battery or the wires, I can see and calculate those.  This seems to be from the voltage divider that is measuring the voltage, not current.
I'm looking at your circuit diagram now (but have not investigated your PCB yet) and I have a question: do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.

Yes, there is a shared ground plane between the voltage dividers and the battery ground, which is also shared with the power source of the device.  I don't understand what mean by a voltage drop on the battery (-).  Wouldn't the ground be 0V due to having a battery share the ground?

So if this is the case, how do I confirm this.  What do I need to measure to verify it?  I have tried different leads that have different resistance due to wire length and size but the difference in the values remain the same.

I'm going to put together another board that uses different values on the voltage dividers to see if that changes the measurements.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7045
  • Country: ca
Re: Inconsistent Battery Reading under load
« Reply #13 on: February 04, 2024, 10:45:06 pm »
Where is MCU pin 21? It should be right at the analog GND for a Kelvin connection.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #14 on: February 04, 2024, 11:31:48 pm »
Pin 21 is grounded to the gnd plane, there is also a 100nF x7r decoupling capacitor.

Also, here is a closeup pic of the battery lead. There is a sensor wire along with the current carrying wires to each terminal,





« Last Edit: February 04, 2024, 11:34:10 pm by trilerian »
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7045
  • Country: ca
Re: Inconsistent Battery Reading under load
« Reply #15 on: February 04, 2024, 11:44:41 pm »
OK, I wondered because pin 21 is not on your schematic symbol, I would add it. Can we see the PCB backside? I'm wondering if there are big slices in the ground pour and you have something grounded in the wrong spot.
Checking where the two critical voltage inputs are: (+) to the voltage divider resistor, and (-) to the MCU, REF, divider resistors to see if that could be picking up a voltage drop.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #16 on: February 05, 2024, 12:07:01 am »
Here you go.  I was hoping not to have to post how awful my routing is...  This is only my 3rd pcb design, I was thinking of paying someone to route this mess for me once I got the final design done.

First pic has both top and bottom runs.  2nd pic is only the bottom.  There is a long break made by the temp sensor, that is actually not on my board I am working on.  That was added because I added the external ref and had to run VIN of the temp sensor off the voltage ref output instead of the board VCC.  On the board I am testing, that is a big jumper soldered from the decoupling capacitor on the ref and the temp sensor VIN pin.  But even on my previous design where I was not using an external ref, this was still an issue. 
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1113
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #17 on: February 05, 2024, 05:38:14 pm »
do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.
^ This. You want either to completely separate the grounds, or use a difference amplifier with appropriate gain (1/2, 1/3 or whatever you need) instead of voltage divider.
 
The following users thanked this post: Vovk_Z

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #18 on: February 05, 2024, 06:20:17 pm »
do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.
^ This. You want either to completely separate the grounds, or use a difference amplifier with appropriate gain (1/2, 1/3 or whatever you need) instead of voltage divider.

What do I have to do to completely separate the grounds?  Do you mean to make the voltage divider gnd not be a part of the ground plane?  Just run it back to the gnd pin?  But if the gnd pin is attached to the gnd plane, wouldn't it still be part of the same gnd? 
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #19 on: February 05, 2024, 06:30:03 pm »
Look at 'differential difference amplifier'. You may find it exactly what you need instead of voltage divider. And it may have less then 1 amplification ratio. I mean it may have ratio exactly as your divider but it can help separate your grounds.
« Last Edit: February 05, 2024, 07:35:28 pm by Vovk_Z »
 
The following users thanked this post: trilerian

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1113
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #20 on: February 05, 2024, 06:31:52 pm »
do you have the same the only one GND both for the power Bat- line and for your voltage divider GND? I suspect those are the same GND (connected together) so basically you don't have a 4-wire measurement (but rather a 3-wire). If so then the voltage drop you see is a voltage drop on a Bat- power wire.
^ This. You want either to completely separate the grounds, or use a difference amplifier with appropriate gain (1/2, 1/3 or whatever you need) instead of voltage divider.

What do I have to do to completely separate the grounds?  Do you mean to make the voltage divider gnd not be a part of the ground plane?  Just run it back to the gnd pin?  But if the gnd pin is attached to the gnd plane, wouldn't it still be part of the same gnd? 

Maybe more accurate would be to say that Bat- must not be connected to divider GND. I haven't studied your design, so I don't know, maybe it's hard to do. As I said, you can use difference amplifier as a second option.
 
The following users thanked this post: trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #21 on: February 05, 2024, 07:22:02 pm »
I'll redesign with a differential amplifier.  Just to make sure, use the differential op-amp and not an analog comparator?

EDIT:  Also, I assume I will want to filter the input to the differential op-amp and not the other way around, filtering the output?
« Last Edit: February 05, 2024, 07:26:20 pm by trilerian »
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1113
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #22 on: February 05, 2024, 07:34:43 pm »
I'll redesign with a differential amplifier.  Just to make sure, use the differential op-amp and not an analog comparator?

Simple op amp with 4 resistors making up difference amplifier. You probably want rail to rail output and input.
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #23 on: February 05, 2024, 07:34:50 pm »
I guess I misspelled a name ot the amplifier. There is a difference between a difference amplifier and a differential amplifier, and TS needs difference amplifier as everybody stated (except me).
Upd.: I've seen a lot of fully differential amplifiers (with differential output too), that's why I guess it is better to use here a term 'difference amplifier' which don't have to have differential output typically.
« Last Edit: February 07, 2024, 04:51:17 pm by Vovk_Z »
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1425
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #24 on: February 05, 2024, 07:38:11 pm »
I'll redesign with a differential amplifier.  Just to make sure, use the differential op-amp and not an analog comparator?

EDIT:  Also, I assume I will want to filter the input to the differential op-amp and not the other way around, filtering the output?
You definitely don't need a comparator instead of opamp.
And I'm not sure you need a filter.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf