Author Topic: Inconsistent Battery Reading under load  (Read 4375 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: 1419
  • 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: 11546
  • 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: 1440
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: 6847
  • 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: 9953
  • 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: 1419
  • 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. 
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3378
  • 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: 1419
  • 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: 7000
  • 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: 7000
  • 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: 1109
  • 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: 1419
  • 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: 1109
  • 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: 1109
  • 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: 1419
  • 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: 1419
  • 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.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #25 on: February 05, 2024, 07:52:01 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.

Filter is for the pwm frequency of 490Hz.  The literature I am reading on the difference amplifier says it has a gain of 1, so the output will be up to 4.2V, 8.4V - 4.2V.  I need it down to less than 4.096V since that is the top end of my LM4132 reference I a using.
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #26 on: February 05, 2024, 08:36:35 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.

Filter is for the pwm frequency of 490Hz.  The literature I am reading on the difference amplifier says it has a gain of 1, so the output will be up to 4.2V, 8.4V - 4.2V.  I need it down to less than 4.096V since that is the top end of my LM4132 reference I a using.

You can set gain of less than one, you can set any arbitrary gain just by choosing ratio of resistors. You want filter at the output: series resistor and capacitor to ground. Don't put filter at the input (or feedback path), unless you know very well what you are doing, because you risk ruining CMRR or something else bad. CMRR might or might not be important, but better stay on safe side unless you know for sure. Also I suggest to use 1% resistors or better for the same reason.
 
The following users thanked this post: Vovk_Z, trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #27 on: February 06, 2024, 11:51:47 pm »

You can set gain of less than one, you can set any arbitrary gain just by choosing ratio of resistors. You want filter at the output: series resistor and capacitor to ground. Don't put filter at the input (or feedback path), unless you know very well what you are doing, because you risk ruining CMRR or something else bad. CMRR might or might not be important, but better stay on safe side unless you know for sure. Also I suggest to use 1% resistors or better for the same reason.

So I need to pick an op-amp to start with.  Presumably one with high impedance so I can run high value resistors to it?  What value resistors should I be looking at here?  100k, higher?  Bandwidth, while that is listed as an important doesn't seem like an issue with the adc of the 328P being 125kHz.  What does seem to be an issue is the output current, I see a lot of these over 40mA.  So I need to make sure I stay under 40mA, right, 328P input current limit on a pin is 40mA?  Although a filter on the output may take up some of that?

So, I need 2 or can I do a 2 channel op amp?  And it is fine, I assume, to use the junction between the +/- for the cells in series to measure from.  One going from + to the junction, the other going from the junction to -? I have no issue measuring from the junction to - now, so I assume it is fine, and probably will work better than subtracting.  Although in its own way that is what it is doing, lol. 


Would something like https://www.mouser.com/datasheet/2/268/MCP6496_Data_Sheet_DS20006758-3078050.pdf work?  Better choice available?
Thanks
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #28 on: February 07, 2024, 02:12:18 pm »
I added the attached to my schematic.  If I understand what I have read I will create a ratio of R3/R1.  R3=10k, R1=11K5 (not sure on these values).
Then this will measure the difference between the + and - inputs.  + will be 4.2V (highest) and - will be 0.  There are 2 channels to measure both cells.  The output then has a lowpass filter with cutoff of 31Hz to make the output a DC line from the 490Hz pwm.  I'm still not sure on my choice of op-amp. I would appreciate feedback on this.

Thanks
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #29 on: February 07, 2024, 04:48:33 pm »
So I need to pick an op-amp to start with.  Presumably one with high impedance so I can run high value resistors to it? 
I guess you have to look at power supply voltage available for your opamp (that's first restriction). And consider input voltage range.
If you want to measure voltage from zero then look for opamps who can work rail-to-rail, at least for input ('RtoR Input ').
« Last Edit: February 07, 2024, 04:52:36 pm by Vovk_Z »
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #30 on: February 07, 2024, 05:07:22 pm »
I'm still not sure on my choice of op-amp. I would appreciate feedback on this.
[/quot
Looks like ok. I don't know about availability this opamp but seems it is available for ordering. It has RtoR input and output. Since your supply voltage is 5 VDC (and not higher) then it can be fine.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #31 on: February 07, 2024, 06:14:37 pm »
Looks like ok. I don't know about availability this opamp but seems it is available for ordering. It has RtoR input and output. Since your supply voltage is 5 VDC (and not higher) then it can be fine.

Are 1% resistors good enough, or should I use 0.5 or 0.1%?  I generally get the 1% for most parts, but kind of feel this is a more important component to get really close on values, but mainly for the math.  I can measure these on my 4 wire meter to get actual values.

What I am curious about is how the input impedance of the resistors affects the output?  The 328P like less than 10k on the adc pins.  So if I have a 10K/12K divider essentially on the input that is 5455 \$\Omega\$, if that is transferred to the output plus the 5K1 \$\Omega\$ after the output, would put be just above the 10K.  But there is the filter cap that may help a bit too.   


EDIT:  Also reading through the data sheet it says the VDD needs bypass capacitors.  I don't see any values given for the bypass.  Should 100nF be ok?
« Last Edit: February 07, 2024, 06:39:29 pm by trilerian »
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #32 on: February 07, 2024, 08:34:21 pm »
1) rated resistor accuracy depends on you. You may use 1% but select them manually with DMM, or use 0.1 % and select manually with good DMM too. The difference is that with 1 % initial accuracy you definitely have to select identical but with 0.1 % initial accuracy they might  be good enough without additional selection. And you don't need 4-wire ohmmeter to measure 10 k resistors (just usual 4-5 digit DMM).
2) Output impedance of your diffamp is 5k1 for DC, and less for AC because of a capacitor. If ig is too much - use another opamp as buffer.
3) 100 nF is typically ok for opamp bypass until other is clearly stated.
« Last Edit: February 07, 2024, 08:36:45 pm by Vovk_Z »
 
The following users thanked this post: trilerian

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #33 on: February 07, 2024, 09:04:51 pm »
So I need to pick an op-amp to start with.  Presumably one with high impedance so I can run high value resistors to it?  What value resistors should I be looking at here?  100k, higher?  Bandwidth, while that is listed as an important doesn't seem like an issue with the adc of the 328P being 125kHz.  What does seem to be an issue is the output current, I see a lot of these over 40mA.  So I need to make sure I stay under 40mA, right, 328P input current limit on a pin is 40mA?  Although a filter on the output may take up some of that?

I don't know what exactly you mean by high impedance op amp. I suppose you want resistors something like 30k and 10k (will give you gain of 1/3). Not too low, not too high. Bandwidth is not important, I would choose an op amp which has low current consuption and has good price. Faster ones often need more current and are pricier.

Output current is completely irrelevant. Your thought process here is completely wrong. 40mA limit is for 328P output. Input is really high impedance, so there is almost no current. You just need to make sure to not exceed ADC input voltage range. But if op amp is powered from same supply as 328P, that is impossible. For instance, it would be a danger to power op amp from 12V, while feeding it's output directly to MCU input which is powered from 5V.

I added the attached to my schematic.

Schematic is wrong. Remember: amplifier always uses negative feedback. So feedback from output must go to inverting input.

Are 1% resistors good enough, or should I use 0.5 or 0.1%?  I generally get the 1% for most parts, but kind of feel this is a more important component to get really close on values, but mainly for the math.

1% is minimum, but should be enough. Mainly it affects two things: accuracy of gain and CMRR. I don't think you need high CMRR in this aplication. And for accuracy, I don't think that you will gain much more by going 0.1%. Calculate or experiment.

What I am curious about is how the input impedance of the resistors affects the output?  The 328P like less than 10k on the adc pins.  So if I have a 10K/12K divider essentially on the input that is 5455 \$\Omega\$, if that is transferred to the output plus the 5K1 \$\Omega\$ after the output, would put be just above the 10K.  But there is the filter cap that may help a bit too.

Nothing on the input gets transfered to op amp output. Op amp output (in closed loop) always has very very low impedance. So only 5.1k of the output filter. Yes, you can say that ADC likes less than 10k, but 10k is not resistance, it's impedance. Filter cap has way enough low impedance.

Op amp bypassing is generally based on op amp bandwidth and frequency band of interest. In your case I would go more than 100n, like 1uF or more, for sure can't hurt.

Actually after reading your posts, I strongly suggest you prototype before producing a PCB.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #34 on: February 07, 2024, 09:38:54 pm »

Schematic is wrong. Remember: amplifier always uses negative feedback. So feedback from output must go to inverting input.

[\quote]

Thanks, I was trying to figure out the inverting/ non inverting inputs.  I haven't had a design with op-amps yet, so wasn't sure which pin was which. I guess I didn't really understand what was meant by the inverting and non inverting inputs.  But it makes sense now. 





I really appreciate the advice so far, and I have been reading on op-amps  to try an understand them a bit more.  We'll se how this affects output under load.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #35 on: February 08, 2024, 12:32:23 am »
I don't know what exactly you mean by high impedance op amp. I suppose you want resistors something like 30k and 10k (will give you gain of 1/3). Not too low, not too high. Bandwidth is not important, I would choose an op amp which has low current consuption and has good price. Faster ones often need more current and are pricier.

Output current is completely irrelevant. Your thought process here is completely wrong. 40mA limit is for 328P output. Input is really high impedance, so there is almost no current. You just need to make sure to not exceed ADC input voltage range. But if op amp is powered from same supply as 328P, that is impossible. For instance, it would be a danger to power op amp from 12V, while feeding it's output directly to MCU input which is powered from 5V.

I wasn't sure how high of values to choose for the input resistors, but it seems it doesn't matter much.  The only real thing that matters is the gain.  I need to be under 4.096V, I am using an external reference for the ADC, so while 5V won't hurt the pin, anything 4.096V and above just reads 1023.  So my choice of resistors are 11K5, 10K. 

At a max input of 4.35V this should reduce it to ~3.8V
Quote
Schematic is wrong. Remember: amplifier always uses negative feedback. So feedback from output must go to inverting input.

I updated my schematic and attached.

Quote
Nothing on the input gets transfered to op amp output. Op amp output (in closed loop) always has very very low impedance. So only 5.1k of the output filter. Yes, you can say that ADC likes less than 10k, but 10k is not resistance, it's impedance. Filter cap has way enough low impedance.

Op amp bypassing is generally based on op amp bandwidth and frequency band of interest. In your case I would go more than 100n, like 1uF or more, for sure can't hurt.

Thank you
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #36 on: February 08, 2024, 03:00:37 am »
I would like to bring back the subject of grounding the battery in this circuit.  Is this actually needed?  Using the difference amplifier there isn't a need for the batt - to be grounded, or at least I don't think so.  It will measure the difference between V1 and V2 no matter how far above ground V2 is.  If I am following  what I have read, the summing point is a virtual gnd created in the inverting amplifier, so the inputs are 0V.  Although I am a little confused how there isn't current flowing when the voltage is being dropped to 0.  But...  The point is I don't think the battery - needs to be connected to ground to measure the voltages here.  So what about the battery - being connected to ground for discharging?  The mosfets gates are controlled by the microcontroller, when the gates turn on a circuit is completed from the Batt - to the Batt + through an external resistor bank.  I am failing to see the need for a gnd reference here.  The current sensor is a hall sensor, so it isn't directly measuring the voltage of the battery, the voltage sensing isn't grounded to the battery, which I think is the point there.  Although the op amp itself is grounded.

I am attaching my full schematic again, with the difference amplifier update.  I would very much appreciate some clarity on the grounding.  If the battery - needs to connect to the ground plane, and why?

Thanks
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #37 on: February 08, 2024, 09:09:53 pm »
Batt- should be grounded, how else the circuit will close? Actually why would you put that current sensor (and fuse!) on the low side in series with mosfet source? That's awkward at best, may cause problems at worst. Put them to the high side. And draw schematic in a way, that n-ch mosfet source faces down, drain faces up. It's really confusing to read the way it is.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #38 on: February 09, 2024, 12:55:08 am »
Batt- should be grounded, how else the circuit will close? Actually why would you put that current sensor (and fuse!) on the low side in series with mosfet source? That's awkward at best, may cause problems at worst. Put them to the high side. And draw schematic in a way, that n-ch mosfet source faces down, drain faces up. It's really confusing to read the way it is.

Going back to the start of the project.  A device was given to me to reverse engineer since the original maker wasn't making them anymore and wouldn't respond communication attempts.  So I did my best to reverse engineer the project with some help from this and other forums.  The lowside current sensor and fuse was pulled directly from his design.  Where I differ from the original design is I am using pwm to open the gate of the fets and allow current to pass between the external resistor bank and the battery.  The fets are not sinking current, well except for their IR, they are just connecting drain to source which connects the resistor bank.  I could place the current sensor and fuse between the Batt+ and one of the load terminals.  But back to the ground question.  I still fail to see why the Batt- has to be grounded to the rest of the circuit.  This seems isolated to me.  I know for certain if the fets were not involved, if I was just connecting the battery to the resistor bank with the current sensor to measure the current, it would work without the battery being grounded to the circuit.  I have this setup with a dyno using the same style current sensor. The dyno was purchased from a company, I didn't build it.   

Now, all that said...  I found out today, that the original designer decided to release a V2.  Maybe he found out I was making one, who knows.  But regardless, I'm not going to be able to release this before he does, so I am going to go back to the drawing board and redesign this properly.  At this point it is now for me and I want to build it right.  I bought a couple of huge linear mosfets to start with and I am going to move this off of the 328P and onto an esp32 or an stm32.  The mosfets I bought are IXTK90N25L2, which are pricey.  There is a lot of stuff I will have to change, but I am going to keep the difference amplifier.  I may be building this for the next year, lol.  But I am enjoying learning how to do it and that is worth all the money and time I have and will put into it.

Moving to the ESP32 is for twofold reasons, one, my program space is at 97% with the 328P and there was still more I wanted to add.  And, to force myself into another MCU since I have only been using the 328P so far. 
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #39 on: February 09, 2024, 03:58:27 am »
So, interesting tidbit about this circuit as well.  I asked awhile back how to implement reverse polarity protection for the battery.  I asked what would happen if I plugged the battery in backwards.  I think someone said something about a full bridge rectifier.  And then the "just use polarity plugs", which I was doing already.  But the battery connections are 5mm bullets and they can get plugged in accidentally.  So one fine day in the middle of the night, I decided to see what happens if you plug the battery in backwards.  Well, nothing popped.  My current sensor sensed current in the opposite direction of normal use, I am using a bi directional sensor.  I know it sensed in the opposite direction because the analog reading was below 512 instead of above.  Now, obviously the load has to  be plugged in for it to happen, without the load plugged in, you are just touching the positive of the battery to the ground of the circuit, and nothing will happen because there is no ground for current to flow.  Back to the reverse polarity.  When I connected it in reverse the mosfets heated up a lot faster than normal, so it is still bad, but it didn't blow anything up.  So this is another reason why I think the battery doesn't have to be grounded to the rest of the circuit.  When it was connected in reverse polarity and current was flowing it didn't affect the rest of the board. 

I am attaching a couple of pics of the actual board.  I have drawn on the top side pic.  When the mosfet is turned on current flows (old belief) from the higher potential (+), through the load and to the LOAD pad on the pcb, this is via stitched to the pad on the bottom which is connected to the drain of the mosfet, from there is goes through the mosfet and to the source which is on top of the pcb, through the fuse then the current sensor and finally to the lower potential (-) of the battery.  I seperated the drain and the source on the top and bottom of the pcb because the amount of current the traces carry can be up to 45A.  According to a chart I looked at, I needed 30mm traces for 40A and a 30°C temp rise. I didn't know how to accomplish that except to put one of the traces on the bottom.  I chose the drain on the bottom because the source has the fuse.   

Despite the design flaws, this device actually works pretty well.  And to alert the user of reverse polarity plug in, the screen flashes all red and in big white letters it says battery backwards, it flashes for 1 second at a time until the reverse polarity issue has been fixed, or the mosfets burn up and current flow stops.  I'm using the reverse current flow as the condition to flash the screen.  I do have proper reverse polarity protection via a mosfet on VIN as well, but when that is plugged in backwards, nothing happens or turns on. 

 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #40 on: February 09, 2024, 09:49:21 am »
or the mosfets burn up and current flow stops.
It'll take some time to fully burn a MOSFET into nothing. Most semiconductors make a short circuit when they die, so you'll still have a path for a current. And still, a leftover (burned textolite, etc) is conductive. So there is a risk of overheating a battery and a battery fire.
If short circuit current is limited by a resistance of an additional resistive load within a rated battery current limits then ok.
(When you apply an opposite voltage to the closed MOSFET its body diode starts to conduct a current. That's why you see hot MOSFETs).
« Last Edit: February 09, 2024, 09:51:08 am by Vovk_Z »
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5129
  • Country: nl
Re: Inconsistent Battery Reading under load
« Reply #41 on: February 09, 2024, 11:20:37 am »
I may be totally wrong here so I'll leave my coat on to be able to make a quick escape but... looking at the 3rd picture you posted you are bundling the load and sense wires? I wouldn't be surprised if that is where your problem originates  :-//
Keyboard error: Press F1 to continue.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #42 on: February 09, 2024, 01:56:44 pm »
I may be totally wrong here so I'll leave my coat on to be able to make a quick escape but... looking at the 3rd picture you posted you are bundling the load and sense wires? I wouldn't be surprised if that is where your problem originates  :-//

I don't think I am.  The sensor wires are completely separate from the load wires starting at the connectors.   The consensus is that somehow the voltage dividers and the battery gnd both being connected to the ground plane causes the difference I see.  I'm not sure how that exactly works.  But I was told it wasn't a true 4 wire connection because of the voltage divers ground, it was more of a 3 wire connection.  The fix is to use a difference amplifier instead of the voltage divider to measure the voltage with.  I have now designed that into the circuit.  This essentially eliminates the voltage sense leads being connected to ground, except through the battery ground.

 Now I am trying to understand why the battery - needs to be connected to the pcb ground.
 When going through the current flow of the design, I don't see any current from the battery needing to go through the pcb ground.  It is limited to the specific traces used for the battery circuit.  The only reason I can think that the battery ground would need to be connected to the pcb ground is if the batt- needs to be at the same potential as the pcb lower potential.  Which is this case I don't think it needs to be.  Voltage sensing of the battery is being done with a difference amplifier.  After my reading on those the input to the divider is theoretically zero, and the output ends up being a potential difference between the inverting and non inverting leads.  The current sensor doesn't care about the ground connection of batt-,  and I don't think the mosfets do either, when their gates turn on, current flows from the higher potential to the lower potential. 



or the mosfets burn up and current flow stops.
It'll take some time to fully burn a MOSFET into nothing. Most semiconductors make a short circuit when they die, so you'll still have a path for a current. And still, a leftover (burned textolite, etc) is conductive. So there is a risk of overheating a battery and a battery fire.
If short circuit current is limited by a resistance of an additional resistive load within a rated battery current limits then ok.
(When you apply an opposite voltage to the closed MOSFET its body diode starts to conduct a current. That's why you see hot MOSFETs).

That is where the fuse is supposed to come in.  If the mosfet internal shorts and gets stuck closed the voltage drop across the load will cause a current around 70-80A.  The fuse is a schurter 50A fast blow fuse, although I'm not quite sure how long that is supposed to take to blow.  I will admit the safety features need more work.  For one, the fuse would never blow if this were a 1S lipo, and if a 2s lipo is discharged enough, it wouldn't supply enough voltage under the load to create over a 50A current flow either.  This is another reason why I am going to change this to the linear fet sinking the current.  If the fet creates an internal short there is no load at all for the battery to go through and it is a true short.  Current theoretically goes infinite and the fuse should blow. 
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #43 on: February 09, 2024, 03:02:01 pm »
Now I am trying to understand why the battery - needs to be connected to the pcb ground.
 When going through the current flow of the design, I don't see any current from the battery needing to go through the pcb ground.  It is limited to the specific traces used for the battery circuit.  The only reason I can think that the battery ground would need to be connected to the pcb ground is if the batt- needs to be at the same potential as the pcb lower potential.  Which is this case I don't think it needs to be.  Voltage sensing of the battery is being done with a difference amplifier.  After my reading on those the input to the divider is theoretically zero, and the output ends up being a potential difference between the inverting and non inverting leads.  The current sensor doesn't care about the ground connection of batt-,  and I don't think the mosfets do either, when their gates turn on, current flows from the higher potential to the lower potential.

You are still insisting, that ground is not needed. To be frank, your schematic is drawn horribly. The purpose of schematic is to make all relations between components and circuit blocks as clear as possible. Yours fails at that. Well drawn schematic makes even a complex design easy to perceive, bad schematic obfuscates even the most obvious and simplest circuits. I believe because of that schematic you have (kinda self-inflicted) confusion. See the image attached. Battery and load is in series, so you can connect them in two different ways. If you call circuit on the right "not connected to ground", ok, that's fair. I agree, technically speaking, it's not connected to ground. But the circuit on the right has a potential issue, that the battery common mode voltage is flying up and down when mosfet is switching. That will introduce extra and totally unjustified common mode noise to you kelvin sense wires. So the normal way of connecting things is left side circuit.

Now I will redirect your question back to you , why Batt- needs to be connected to circuit ground?
 
The following users thanked this post: Vovk_Z

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #44 on: February 09, 2024, 06:05:27 pm »
You are still insisting, that ground is not needed. To be frank, your schematic is drawn horribly. The purpose of schematic is to make all relations between components and circuit blocks as clear as possible. Yours fails at that. Well drawn schematic makes even a complex design easy to perceive, bad schematic obfuscates even the most obvious and simplest circuits. I believe because of that schematic you have (kinda self-inflicted) confusion. See the image attached. Battery and load is in series, so you can connect them in two different ways. If you call circuit on the right "not connected to ground", ok, that's fair. I agree, technically speaking, it's not connected to ground. But the circuit on the right has a potential issue, that the battery common mode voltage is flying up and down when mosfet is switching. That will introduce extra and totally unjustified common mode noise to you kelvin sense wires. So the normal way of connecting things is left side circuit.

Now I will redirect your question back to you , why Batt- needs to be connected to circuit ground?

I wasn't insisting that the Batt- didn't have to be grounded.  I was asking why it needed to be because I didn't understand why it needed to be.  The whole conversation started with this is an issue due to the grounding of the 4 wire connection and Batt-, essentially being a 3 wire connection.  Which I still don't understand, but there is a whole world of electronics that I don't understand.  Sometimes you just fix what someone tells you to fix.  But in light of the issue, I am trying to understand why Batt- needs to be grounded.  This makes no difference in whether or not I add the difference amplifier.  I think the difference amplifier is a more elegant solution to a voltage divider and want to incorporate it.  I'm just looking for understanding, that is all.

Also, sorry about my schematic, I'll just leave it as I am a beginner,  posting in the beginner forum, and will make bad mistakes and draw bad schematics.  All I can do is try to improve on them as I learn more.


EDIT:  And I really do appreciate the help, and will go back and try to update my schematic. 
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #45 on: February 09, 2024, 08:45:43 pm »
Sorry for being a little harsh. You know, they say good teaching should involve either jokes or harshiness, then things sink into head much better. I guess I'm out of jokes today. Sort of like "I have come here to chew bubblegum and kick ass. And I'm all out of bubblegum."

The whole conversation started with this is an issue due to the grounding of the 4 wire connection and Batt-, essentially being a 3 wire connection.  Which I still don't understand

Take a look at picture 1. Battery, positive and negative wires with their own resistance and a load at the end. The reason you don't measure 10V at the load is because both positive and negative wire have voltage drop (~100mV on each). So if you need accurate voltage measurement, that sucks.

You say alright, I will add independent sense wires right at the battery to avoid issue with power wires droping voltage under load. Picture 2. Works like a charm. Even though sense wires also have resistance, but the current is zero, so no voltage drop. It is litterally like measuring right at the battery terminals with a multimeter.

Now because of circuit implementation you join ends of power negative wire and sense negative. Picture 3. Note that what you get is essentially power negative wire and sense negative wire in parallel. Two wires in parallel is essentially one wire! So load current now also flows through negative sense wire, it has voltage drop and you have measurement error.

I am trying to understand why Batt- needs to be grounded.

This comes from the fact that you use a directly driven mosfet for switching. Imagine for a moment that you use a relay instead. In a relay control coil and contacts are isolated. So you can drive the relay with your MCU and relay contacts are floating relative to MCU ground. Their are independent, not referenced to anything else. It would work very nice, just slow and contacts would burn with time.

So you use a mosfet. Mosfet is controlled by the votage between gate and source. So you connect source to ground (0V) and switch voltage at gate. Nice. But notice that mosfet source terminal is used both for control and as one of it's "contacts" (continuing relay analogy, another "contact" is drain). So you have no isolation. So anything what mosfet is switching is inevitably referenced to the circuit which controls it.

There are isolated mosfet driving options. Those include using gate drive transformer, optocoupler, solid state isolated gate driver (last two require isolated power supply to power the isoltage side). If you implement something like that, you have floating mosfet switch. But don't do that, that's unjustified and too complicated for the task.
« Last Edit: February 09, 2024, 08:57:03 pm by Manul »
 
The following users thanked this post: tooki, Vovk_Z, trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #46 on: February 10, 2024, 12:38:35 am »

Now because of circuit implementation you join ends of power negative wire and sense negative. Picture 3. Note that what you get is essentially power negative wire and sense negative wire in parallel. Two wires in parallel is essentially one wire! So load current now also flows through negative sense wire, it has voltage drop and you have measurement error.

Thank you for that explanation.  I did not think of the negative sense wire being in parallel as I didn't think there should have been current running through the ground plane


Quote
This comes from the fact that you use a directly driven mosfet for switching. Imagine for a moment that you use a relay instead. In a relay control coil and contacts are isolated. So you can drive the relay with your MCU and relay contacts are floating relative to MCU ground. Their are independent, not referenced to anything else. It would work very nice, just slow and contacts would burn with time.

So you use a mosfet. Mosfet is controlled by the votage between gate and source. So you connect source to ground (0V) and switch voltage at gate. Nice. But notice that mosfet source terminal is used both for control and as one of it's "contacts" (continuing relay analogy, another "contact" is drain). So you have no isolation. So anything what mosfet is switching is inevitably referenced to the circuit which controls it.

And thank you again, that makes sense. 


I'm going to mull this over a bit more, and I'll probably have more questions.  But that does help clear that up a little.

Thank you
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #47 on: February 20, 2024, 01:18:40 am »
The op amp circuit is not working at all.

I am going to try to explain what voltages are where and I have made some screenshots, but they are kind of bad...

Channel 2, (channel 1 inverting input not connected, non inverting is connected since it is the junction between the 2 cells).  Channel 2, place low potential probe on a ground, connect ground of battery to the circuit as well because there is a potential difference.  Ok.  With the high potential probe, measure the non inverting input before any resistors (battery ground).  0V - Ok, good.  Measure the inverting input before any resistors, cell 1.  3.85V - ok, good, storage charge.  Measure non inverting at op amp channel 2 input.  3mV.  Hmm, this should still be zero...  Ok, measure inverting op amp channel 2 at input.  1.79V.  And measure channel 2 output, 3.17mV. 

The op amp I chose is:
MCP6497T-E/SN
https://www.mouser.com/datasheet/2/268/MCP6496_Data_Sheet_DS20006758-3078050.pdf

I am completely lost... 
I'm going to try to figure out how to use ltspice and see if it can help.  But I am lost.
Thanks


 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #48 on: February 20, 2024, 04:41:43 pm »
I think you have your input polarity wrong going into difference amplifier. Non inverting (+) input branch must be connected to the positive side of your battery, inverting (-) must be connected to negative side (I mean, relative potential). Man, you need to always double check these things. Easiest is probably to just rewire the cable.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #49 on: February 20, 2024, 05:15:29 pm »
I think you have your input polarity wrong going into difference amplifier. Non inverting (+) input branch must be connected to the positive side of your battery, inverting (-) must be connected to negative side (I mean, relative potential). Man, you need to always double check these things. Easiest is probably to just rewire the cable.

So higher potential goes to the non inverting, and lower potential goes to the inverting inputs?  The inverting input has the feedback and the non inverting has the divider to gnd?



I have attached a schematic of the part to verify.

Thanks

 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #50 on: February 20, 2024, 05:54:13 pm »
I flipped the inputs just to test, and that does make it work...  But now I am even more curious.  Measuring the high potential on the pin gives half the voltage.  Voltage divider, so that makes sense.  Measuring the voltage on the inverting pin gives half the voltage as well.  Which if the output is the full voltage would make sense.  Right, the inverting essentially is a voltage divider from the Vout to the low potential.  If the resistors are the same value, half of Vout.  Interesting.  I realize there is a lot more to it, and I have watched a few videos and read a few articles on this now.  But this is the way my brain is processing it...
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #51 on: February 20, 2024, 09:50:21 pm »
I cut some traces and soldered in jumpers.  Now both sides are working.  I had to remove the resistor from the output filter, but leaving the cap still seems to get rid of the pwm frequency, so...  Stable voltage on the outputs and all the way up to the pins on my microcontroller, but the adc is fluctuating a lot more.  Will have to track that down.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #52 on: February 20, 2024, 10:04:26 pm »
And, as a follow up.  All that work and it solved nothing.  Voltage under load still reads about 0.01V lower than either of my bench DMMs. 
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #53 on: February 20, 2024, 11:19:25 pm »
I cut some traces and soldered in jumpers.  Now both sides are working.  I had to remove the resistor from the output filter, but leaving the cap still seems to get rid of the pwm frequency, so...  Stable voltage on the outputs and all the way up to the pins on my microcontroller, but the adc is fluctuating a lot more.  Will have to track that down.

You can't remove filter resistor, it may lead to op amp instability and oscillation. It's a must for most op amps.

All that work and it solved nothing.  Voltage under load still reads about 0.01V lower than either of my bench DMMs. 

Are you serious? 10mV lower than bench DMM? That's actually a very good result you got there. DMM is a precision instrument, your circuit is not.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #54 on: February 20, 2024, 11:55:54 pm »
You can't remove filter resistor, it may lead to op amp instability and oscillation. It's a must for most op amps.

Not the feedback resistor.  The low pass filter resistor after the op amp. 

Quote
Are you serious? 10mV lower than bench DMM? That's actually a very good result you got there. DMM is a precision instrument, your circuit is not.

I understand that.  And I need to do some more testing, but I originally started this thread because of that issue.  Voltage under load was 10mV less than what my DMM read.  At least at the battery terminals.  I coded out the error, but it was proportional to the current, luckily it was just a simple slope.  But if I change the load resistance, the values change, so I was hoping to fix that. 

EDIT:  Hah, I started this thread with a 100mV difference, now I am down to 10mV.  Well, that is 10x better, lol.  Ok, I will do more testing to confirm results, and if it stays at 10mV, I can live with that.
« Last Edit: February 20, 2024, 11:59:12 pm by trilerian »
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #55 on: February 21, 2024, 12:11:03 am »
You can't remove filter resistor, it may lead to op amp instability and oscillation. It's a must for most op amps.

Not the feedback resistor.  The low pass filter resistor after the op amp. 

Yes, the low pass filter resistor! You CAN'T remove THAT.

Stable voltage on the outputs and all the way up to the pins on my microcontroller, but the adc is fluctuating a lot more.  Will have to track that down.

Stable only because your DMM is averaging and integrating. In reality your op amp is most likely oscillating. That's why adc is fluctuating. Put back the low pass filter resistor!

I understand that.  And I need to do some more testing, but I originally started this thread because of that issue.  Voltage under load was 10mV less than what my DMM read.  At least at the battery terminals.  I coded out the error, but it was proportional to the current, luckily it was just a simple slope.  But if I change the load resistance, the values change, so I was hoping to fix that. 

EDIT:  Hah, I started this thread with a 100mV difference, now I am down to 10mV.  Well, that is 10x better, lol.  Ok, I will do more testing to confirm results, and if it stays at 10mV, I can live with that.

You stated like 120mV or something. Well, 10mV in 4 volt range is like 0.25%. That's GOOD. Come on, think about that, you have only 10bit ADC, your resolution is 4mV, plus ADC likely has some offset, ADC is sampling single ended, not differential, layout not perfect, maybe some small ground level shifts, plus op amp offset, gain error, plus maybe some other errors. That's very good what you got. Real engineering is not like math on a paper where everything is perfect. Otherwise engineers whould have no job, only mathematicians would.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #56 on: February 21, 2024, 01:57:02 am »
Yes, the low pass filter resistor! You CAN'T remove THAT.

Wait, the low pass filter isn't in any of the designs I saw online.  And when I have that in, it decreases the output to 0.7V instead of 3.4V.
I am attaching a pic of the schematic and arrows pointing the resistors I have removed.



 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #57 on: February 21, 2024, 06:31:05 am »
I would try to use at least 22-47 R there. But as you know look at the resulting voltage drop. Seems you ADC is consuming a lot of current. You may play with different capacitances there too. And you may add opamp buffer/filter instead of pure passive. But 10 mV error is pretty fine for existing simple solution.
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: Inconsistent Battery Reading under load
« Reply #58 on: February 21, 2024, 09:17:46 am »
Yes, the low pass filter resistor! You CAN'T remove THAT.

Wait, the low pass filter isn't in any of the designs I saw online.  And when I have that in, it decreases the output to 0.7V instead of 3.4V.
I am attaching a pic of the schematic and arrows pointing the resistors I have removed.

Simple to remember: most op amps can't drive capacitive loads. Capacitor on the output of op amp generally is big no-no. With series resistor it's ok, because then the op amp "sees" a resistor, not capacitor, or at least "less" the capacitor, "more" the resistor.

Your filter with 5k1 is a good filter, keep it. If you see such a voltage drop with series resistor in, than something is hugely wrong. Maybe capacitor is cracked, maybe ADC is half fried or something else. Is it so on both channels?
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #59 on: February 21, 2024, 01:39:02 pm »

Simple to remember: most op amps can't drive capacitive loads. Capacitor on the output of op amp generally is big no-no. With series resistor it's ok, because then the op amp "sees" a resistor, not capacitor, or at least "less" the capacitor, "more" the resistor.

Your filter with 5k1 is a good filter, keep it. If you see such a voltage drop with series resistor in, than something is hugely wrong. Maybe capacitor is cracked, maybe ADC is half fried or something else. Is it so on both channels?

Ok, that makes sense.  I can remove the capacitor too and see what it looks like on my scope.  I can also try other values for the low pass.  But yes, it has the big voltage drop on both channels.  This filter works fine without the op amp setup. 


EDIT:  Alright, nevermind.  I must have had something wrong.  I put the resistors back in and it is fine.
« Last Edit: February 21, 2024, 02:45:32 pm by trilerian »
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #60 on: February 22, 2024, 06:39:29 am »
I have another question . This is related to the input conditions of the op amp. It states that neither input voltage can exceed Vdd-Vss. In my case that is 5V. Technically, cell2 of the lipo positive side is up to 8.6V above ground due to it being in series. However, there is the voltage divider on the non inverting input. So does that mean the input only sees the divided voltage? If I measure the voltage at that node it is fine, and I just want to make sure I am not stressing the max ratings.
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #61 on: February 22, 2024, 08:07:46 pm »
There are two modes or two states which you may want to investigate to be sure: steady state and transients (when power-up and outboard external).
You are fine with steady state mode because as you see you have a voltage divider. And it is not so obvious with all types of transients. You may quite in a simple way look at power-up transients with an oscilloscope, I guess. And it is much more variants what you may get from external world (like battery loose contacts and any other possible outer influence.
 

Offline Jwillis

  • Super Contributor
  • ***
  • Posts: 1711
  • Country: ca
Re: Inconsistent Battery Reading under load
« Reply #62 on: February 22, 2024, 09:14:05 pm »
Arbitrary changing resistors on an opamp is'nt going to get you far. Know what gain you want. From the looks of it you are looking at a 2 gain for each opamp. so each resistor needs to be measured to give exactly 2 gain for each opamp. You work this out  a non-inverting design formula. So for a 2 gain Re 1,3, 5,and 6 need to be measured and matched to give a precise gain.
Another problem is the Input Offset Voltage. The MCP6497 has an input Offset Voltage of  -1.6mV min and +1.6mV max, That's a span of 3.2mV, which is quite a bit. That then  is multiplied by the gain. Then that error is multiplied again because your using 2 opamps to give a finale result. Compounding errors.
Do you know what the actual  Input Offset Voltage of each opamp?
The The MCP6497 has no Offset trim built in, so that has to be done externally. By being able to trim the offset and having a precise gain you can guarantee that the output will be correct.
« Last Edit: February 22, 2024, 10:14:33 pm by Jwillis »
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #63 on: February 23, 2024, 12:35:43 am »
There are two modes or two states which you may want to investigate to be sure: steady state and transients (when power-up and outboard external).
You are fine with steady state mode because as you see you have a voltage divider. And it is not so obvious with all types of transients. You may quite in a simple way look at power-up transients with an oscilloscope, I guess. And it is much more variants what you may get from external world (like battery loose contacts and any other possible outer influence.

Ok, I will check power up, connecting and disconnecting with my scope, so long as it doesn't go over Vdd-Vss, i should be good?

Arbitrary changing resistors on an opamp is'nt going to get you far. Know what gain you want. From the looks of it you are looking at a 2 gain for each opamp. so each resistor needs to be measured to give exactly 2 gain for each opamp. You work this out  a non-inverting design formula. So for a 2 gain Re 1,3, 5,and 6 need to be measured and matched to give a precise gain.
Another problem is the Input Offset Voltage. The MCP6497 has an input Offset Voltage of  -1.6mV min and +1.6mV max, That's a span of 3.2mV, which is quite a bit. That then  is multiplied by the gain. Then that error is multiplied again because your using 2 opamps to give a finale result. Compounding errors.
Do you know what the actual  Input Offset Voltage of each opamp?
The The MCP6497 has no Offset trim built in, so that has to be done externally. By being able to trim the offset and having a precise gain you can guarantee that the output will be correct.


I do know what I want, and I chose resistors to get the gain I want...  R1 and R2 are 11K5 and R3 and R4 are 10K.  This is what I am looking for.  Drop up to 4.35V to below 4.096V.  4.096V is my ADC reference.  I am using 0.1% resistors, and still matching them. 

Is there a mathematical way of determining the input offset, or is that just do some measurements?  As of right now, the measurement is within 3mV for both channels added together, and since I am using a 10 bit ADC, I'm not getting more accurate than that.  Well, without oversampling at least. 
 

Offline helius

  • Super Contributor
  • ***
  • Posts: 3643
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #64 on: February 23, 2024, 02:58:06 am »
A lot of advice about optimizing the circuit, but have you researched if you are just seeing normal battery voltage delay?
Lithium and lithium-ion cells have passivation covering the plates, and this causes voltage to dip and then recover when they are put under load.
 

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #65 on: February 23, 2024, 04:39:28 am »
A lot of advice about optimizing the circuit, but have you researched if you are just seeing normal battery voltage delay?
Lithium and lithium-ion cells have passivation covering the plates, and this causes voltage to dip and then recover when they are put under load.

Well that is interesting.  I will have to look into that as well.  How long would this delay happen for? 


There are two modes or two states which you may want to investigate to be sure: steady state and transients (when power-up and outboard external).
You are fine with steady state mode because as you see you have a voltage divider. And it is not so obvious with all types of transients. You may quite in a simple way look at power-up transients with an oscilloscope, I guess. And it is much more variants what you may get from external world (like battery loose contacts and any other possible outer influence.

Ok, I will check power up, connecting and disconnecting with my scope, so long as it doesn't go over Vdd-Vss, i should be good?

I checked this out on my scope and on my SDM3055 in fast mode.  I never saw the voltage go over 3.8V after the divider.  I performed quite a few manual tests and it just goes to 3.8V right away.  I tested at 2Hz sample rate and faster sample rates.  Attached is a screenshot of the scope output.  I tapped the plug to the terminal a few times to make sure I wasn't missing anything.
 

Offline Vovk_Z

  • Super Contributor
  • ***
  • Posts: 1419
  • Country: ua
Re: Inconsistent Battery Reading under load
« Reply #66 on: February 23, 2024, 11:50:34 am »
I checked this out on my scope and on my SDM3055 in fast mode.  I never saw the voltage go over 3.8V after the divider.  I performed quite a few manual tests and it just goes to 3.8V right away.  I tested at 2Hz sample rate and faster sample rates.  Attached is a screenshot of the scope output.  I tapped the plug to the terminal a few times to make sure I wasn't missing anything.
Seems fine to me. In general, when you have at least several kOhms between any opamp input and any potential harm source those several kOhms (11 k in your example) work as good enough resistance to make any possibly harmful opamp input current low enough (less than 1 mA), if it will arise somehow. Typically that is a quite safe current which must not harm typical opamp input.
So, this may be it ('Good enough for Australia'  :) :-+).
« Last Edit: February 23, 2024, 11:53:45 am by Vovk_Z »
 
The following users thanked this post: trilerian

Offline trilerianTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Re: Inconsistent Battery Reading under load
« Reply #67 on: February 27, 2024, 07:27:20 pm »
Got a new question, on the same subject, but not this design.  I opened up a premium charger/discharger to see how it handles the voltage sensing.  Looks like it is using components marked "E23", which after a search come up as biased resistor built-in transistor.  The inputs from the cells go into the transistors and the outputs go straight to the mcu. And nothing it seems to take care of the grounding issue...  Would this still be considered a 4 wire?  Also, this is dividing the voltage, or reducing the voltage on the output, I understand that it can act like a regulator on the output, just not sure how that is calculated.  All the cells use the same part, one for each cell. 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf