Author Topic: Battery Monitoring - Voltage Divider  (Read 11366 times)

0 Members and 1 Guest are viewing this topic.

Offline Nikos A.Topic starter

  • Regular Contributor
  • *
  • Posts: 238
  • Country: cy
Battery Monitoring - Voltage Divider
« on: July 02, 2019, 03:44:20 pm »
Hi everyone,

I want to monitor the battery level with my ESP32 using a voltage divider and ADC.. ESP32 is going to be at deep sleep mode for long periods (1h) before waking up to transmit data.

I want the voltage divider ON only while ESP32 is ON, in order to prevent wasting energy on the restive load.

Looking for a solution I found that I can implement the aforementioned using a n-channel and p-channel low Q mosfets and controlling the N-channel Gate.



Is there a single chip that integrates both n-channel and p-channel mosfet intended for this purpose?
Is there another solution to control the voltage divider?

Thanks in advance


 

Offline splin

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Battery Monitoring - Voltage Divider
« Reply #1 on: July 02, 2019, 07:30:19 pm »
You could drive the p-channel mosfet via a capacitor directly from a GPIO. The capacitor needs to be sized to keep it's charge voltage sufficiently low to fully turn on the mosfet after accepting the 7.6nC total gate charge required to turn the mosfet on.

The mosfet has .9V maximum threshold voltage. Assuming Vbatt and ESP32 supply voltage have a minimum of 2.3V, the capacitor can charge to a maximum of 1.4V with 7.6nC; Q= CV so capacitance must be > 5.4nC. The gate current of the mosfet will be negligible once the mosfet has turned on but the pull up resistor will continue to charge the capacitor - so increase its value, and/or the capacitance,  to keep the mosfet on long enough to take your measurement with the ADC.

Alternatively you might be able to use a zener instead of the capacitor, if you could find a suitable value that works with all combinations of battery and supply voltages and min and max midget gate threshold voltages.

[EDIT] Obviously the capacitor/ pull-up resistor time constant will determine the minimum time between measurements.
« Last Edit: July 02, 2019, 07:35:15 pm by splin »
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16712
  • Country: us
  • DavidH
Re: Battery Monitoring - Voltage Divider
« Reply #2 on: July 03, 2019, 03:29:06 am »
Q91 could be replaced with an I/O pin driven charge pump.
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1241
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #3 on: July 03, 2019, 03:38:17 am »
Can you not just use higher value resistors to achieve lower current drain without the complicated switching?
2M2 and 4M7
Where are we going, and why are we in a handbasket?
 
The following users thanked this post: thm_w

Offline Dubbie

  • Supporter
  • ****
  • Posts: 1115
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #4 on: July 03, 2019, 04:08:15 am »
Heh. I just designed this exact same circuit yesterday for the same purpose.

I just used a BSS138 and a BSS84.
I did consider using a GPIO instead of the N-Channel, but I wasn't confident enough to run with it.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16712
  • Country: us
  • DavidH
Re: Battery Monitoring - Voltage Divider
« Reply #5 on: July 03, 2019, 04:17:43 am »
The advantage of the charge pump, other than removing the need for the level shifting transistor, is that a stuck I/O pin in either state disconnects the divider.  It also removes any need to regulate the gate voltage although a zener shunt for protection is still a good idea no matter what method is used.

It works at 5 volts but diode voltage drops make it unsuitable at 3.3 volts and lower.
 

Offline Nikos A.Topic starter

  • Regular Contributor
  • *
  • Posts: 238
  • Country: cy
Re: Battery Monitoring - Voltage Divider
« Reply #6 on: July 03, 2019, 05:48:39 am »
Thank you for your answers

Can you not just use higher value resistors to achieve lower current drain without the complicated switching?
2M2 and 4M7

Yes I can but I am looking for a better (more optimized) solution.

You could drive the p-channel mosfet via a capacitor directly from a GPIO.

[EDIT] Obviously the capacitor/ pull-up resistor time constant will determine the minimum time between measurements.

I like this approach, I am going to test on the breadboard

Q91 could be replaced with an I/O pin driven charge pump.


I've never used a charge pump but thank you for letting me know about this technology!!
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1241
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #7 on: July 03, 2019, 06:55:13 am »
Thank you for your answers

Can you not just use higher value resistors to achieve lower current drain without the complicated switching?
2M2 and 4M7

Yes I can but I am looking for a better (more optimized) solution.


More optimized?
I tend to question your approach.
I think you are over complicating the solution.

3v7 / (2M2 + 4M7) = 536 nanoamps
This is less than peanut power.

The MCU uses a fairly standard sample and hold ADC. The low impedance issue only exists while sampling.
To overcome this issue, simply put a 0u1 capacitor across the 4M7 resistor.

I have done exactly this on numerous projects using ESP8266 and ESP32.


Where are we going, and why are we in a handbasket?
 

Offline Dubbie

  • Supporter
  • ****
  • Posts: 1115
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #8 on: July 03, 2019, 07:32:46 am »
Does such a high r value affect accuracy through leakage?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19603
  • Country: gb
  • 0999
Re: Battery Monitoring - Voltage Divider
« Reply #9 on: July 03, 2019, 07:57:50 am »
I believe the leakage into the ADC input is tiny. Check the data sheet.

Even higher value resistors can be used, if the potential divider is buffered with a FET input op-amp,
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14618
  • Country: fr
Re: Battery Monitoring - Voltage Divider
« Reply #10 on: July 03, 2019, 11:43:56 am »
You can definitely use much greater values for the resistive divider, several hundreds kohm or such. Add a bypass cap between the analog input and ground to make up for it (it will additionally low-pass filter VBAT, which probably makes sense).

A solution I already used for this, requiring no additional transistor, is the following: if your MCU has IOs that can be configured as open drain, use one to control the resistive divider. Connect the OD IO to the lower end of the resistive divider (instead of connecting it to ground), and connect the battery directly to the higher end of the divider. When not measuring VBAT, just set the IO to '1' (which will make it HI-Z): then the current draw through the analog input should be negligible. When you want to measure VBAT, set the IO to '0', which will switch the lower end of the divider to ground. You can then measure VBAT after a short settling time. You can disconnect the divider again once the measurement is done, you don't even need to do it only when you're putting the MCU to sleep.

Edit: for the solution above, it will of course depend on the voltage range of VBAT vs. VDD of your MCU. When the divider is disconnected, you'll get a power draw of (VBAT-VDD-Vf)/Rup, Vf being the Vf of the internal clamp diode of the IO (~0.3V to 0.6V) and Rup being the value of the upper resistor of the divider. So whether it's worth it compared to other solutions really depends on those parameters.

Otherwise, you can still use an OD IO instead of Q91 to save an extra transistor.

« Last Edit: July 03, 2019, 11:55:19 am by SiliconWizard »
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8219
  • Country: fi
Re: Battery Monitoring - Voltage Divider
« Reply #11 on: July 03, 2019, 12:06:18 pm »
Indeed much greater values can be used, but don't go too far - even PCB surface contamination leakage could cause issues.

I have seen people intuitively think that if you have a leakage resistance of, say, around +/-1GOhm, then having a measurement impedance of, say, 10Mohm would be fine as it would be "two orders of magnitude less". But this two orders of magnitude less would translate into generating a 1% measurement error, which probably is already significant for a battery SoC measurement.

(Surface leakage seems to be hard to quantify reliably.)

The same goes for the ADC input leakage current, even if it's tiny, you need to be at least 3 orders of magnitude away from it to keep the error below 0.1%. Of course, if the leakage is constant, it can be calibrated out, but how do you know it's constant?

All this being said, I'm still almost 99% sure you could just increase the divider values to solve the problem in a simpler way.

Note that while the ADC's DC leakage is small, it consumes considerable charge every time you measure. There is a cheap, passive way, and a slightly more expensive, active way to deal with this:
1) a capacitor at the ADC pin (say, 10nF, or a BOM reuse power decoupling cap of 100nF),
2) an opamp driving the ADC input.

1) suffers from the fact that the driving source needs to replenish the cap after each measurement, and if your resistor divider values are big, this takes time. Otherwise, the results start to drift.

For example:
With a ADC sampling capacitance of 20pF, a 10n capacitor would cause approximately an error of 20/10000 = 0.2 percent (the chance of voltage in the 10n cap) during sampling. So we don't want to go much below 10nF, it starts making a difference.

With a 10n cap and a 2M2 + 4M7 divider talked about earlier, the RC time constant is 1/(1/2200000+1/4700000)*10*10e-9 = 15 milliseconds. After 5 time constants, i.e., 75ms, the capacitor is charged to 99.3% of the final value, assuming it started from zero, of course, which is a fair assumption to handle the edge cases like startup. Of course, in practice, the ADC reading only diminished 0.2 percent of the capacitor, so there's less charge needed to be replenished. In any case, this means you can only trig the ADC every 75ms. Put it in a free-running conversion mode at 10ksps by accident, and you'll likely see severely drifted measurements!

Circuit-wise, such a capacitor is simplest, by far, and often analog filtering is desirable. This is often the best for battery measurement, unless you need to measure and trace voltage spikes, i.e., sample at higher rates. If this is the case, you'll need an opamp to buffer the divided signal for the ADC.
« Last Edit: July 03, 2019, 12:09:28 pm by Siwastaja »
 
The following users thanked this post: thm_w

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1516
  • Country: gb
Re: Battery Monitoring - Voltage Divider
« Reply #12 on: July 03, 2019, 04:28:20 pm »
If using an op-amp buffer, you can get ultra-low-power op-amps that have an enable/select pin that can put it in to a standby mode, where quiescent current is typically in the order of nA.

Although, one caveat with those is that after asserting the enable/select pin it can take tens of milliseconds for the output to stabilise, so not too useful for frequent sampling.
 

Offline Dubbie

  • Supporter
  • ****
  • Posts: 1115
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #13 on: July 03, 2019, 05:49:40 pm »
Thanks for the tips everyone. I think I will switch to high value resistors + cap for my design. I have no need to sample quickly as it is just battery voltage I am measuring. I just didn’t want my device to destroy batteries if they were left on the shelf for 6 months. I think I should be fine.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7089
  • Country: ca
Re: Battery Monitoring - Voltage Divider
« Reply #14 on: July 03, 2019, 05:55:52 pm »
Final note, the ESP32 has a sloppy ADC spec accuracy is +/-6% unless you do calibration, and there is no spec for ADC input current/capacitance that I could find. They just say use a 0.1uF cap.
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1241
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #15 on: July 03, 2019, 07:57:07 pm »
Final note, the ESP32 has a sloppy ADC spec accuracy is +/-6% unless you do calibration, and there is no spec for ADC input current/capacitance that I could find. They just say use a 0.1uF cap.

Yes it does have a sloppy spec.

The OP says that the MCU will sleep for an hour at a time.
This infers that the battery monitoring will be done once only after the MCU wakes up each time.
This means that the 2M2 + 4M7 divider, with 0u1 capacitor is perfectly suitable for the application.
With the ADC accuracy being +/-6%, telling the exact battery voltage is difficult.
In the projects I have done using ESP8266 and ESP32, I was quite happy with 'About Full', 'About Half', Getting Low' indications...
Where are we going, and why are we in a handbasket?
 

Offline Nikos A.Topic starter

  • Regular Contributor
  • *
  • Posts: 238
  • Country: cy
Re: Battery Monitoring - Voltage Divider
« Reply #16 on: July 04, 2019, 07:05:43 am »
Thank you for your answers!! I've convinced to proceed with high resistor values and cap for my project also :)
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14618
  • Country: fr
Re: Battery Monitoring - Voltage Divider
« Reply #17 on: July 04, 2019, 12:46:47 pm »
Note that using a measurement of the battery voltage to estimate its state of charge is per se a difficult/slippery problem and highly depends on the type of battery being used.
I don't think I have seen what type of battery you're going to use, but for instance a +/-6% error on a single-cell LiPo, assuming you have set your divider to give a full scale at 4.2V, will yield a ~250mV error, which is IMO way too much for a LiPo battery to get even just a remote idea of its approximate SoC.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8219
  • Country: fi
Re: Battery Monitoring - Voltage Divider
« Reply #18 on: July 04, 2019, 12:50:48 pm »
For li-ion (except LFP), voltage measurement tends to be good enough, because the curve has a large span, and it's almost linear from about 100% to 10%: 4.2V-3.2V is 27% of the nominal voltage, a massive difference between full and empty!

For all other battery types, voltage measurement is almost useless, unless combined with a lot of other information.

6% error is of course too much for any battery type, including the easiest (li-ion), but such error can be easily calibrated out. Do the bog standard two-point calibration and calculate offset and gain correction and that's it. For best result, average the battery voltage in software (for example, cumulative average filter) over a minute or two, and apply nonlinear lookup table to transform from voltage to a percentage (you'll find battery measurement curves online, so no need to measure yourself), and you have a very capable system.
« Last Edit: July 04, 2019, 12:54:34 pm by Siwastaja »
 

Offline Dubbie

  • Supporter
  • ****
  • Posts: 1115
  • Country: nz
Re: Battery Monitoring - Voltage Divider
« Reply #19 on: July 04, 2019, 07:22:29 pm »
That was my plan exactly siwastaja. Thanks for confirmation.
 
The following users thanked this post: Siwastaja

Offline GamingUnleashed

  • Newbie
  • Posts: 5
  • Country: au
Re: Battery Monitoring - Voltage Divider
« Reply #20 on: June 09, 2022, 08:26:52 am »
does anyone know how much current is needed to be available for a esp sensor to read the voltage ?

unsure if I should be using k or m Ω

wanting to monitor 4x 12v batteries in 48v banks
to keep an eye out for dead cells
had a bit of a melt down when 1 cell died and the other batteries boiled away @ 17v

100k with 25k,11k,7.1k,5.3k = 1.5Ma
1m with 250k,111k,71.4k,53,3k = 150μa
then of-cause I could do 10m but I am assuming that will lead to false readings

I did buy those 25v voltage sensors from ebay but they just popped smoke when trying to read more than 1 battery while using the same esp they had 30k + 7.5k  smd resistors , so just going to make a VD in series and try again
 :horse:
« Last Edit: June 09, 2022, 08:33:16 am by GamingUnleashed »
 

Online gamalot

  • Super Contributor
  • ***
  • Posts: 1326
  • Country: au
  • Correct my English
    • Youtube
Re: Battery Monitoring - Voltage Divider
« Reply #21 on: June 09, 2022, 08:44:49 am »
Use a high-value resistor in the voltage divider circuit and put a capacitor in parallel with the low-side resistor.

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2265
  • Country: ca
Re: Battery Monitoring - Voltage Divider
« Reply #22 on: June 09, 2022, 02:15:06 pm »
does anyone know how much current is needed to be available for a esp sensor to read the voltage ?

unsure if I should be using k or m Ω

wanting to monitor 4x 12v batteries in 48v banks
to keep an eye out for dead cells
had a bit of a melt down when 1 cell died and the other batteries boiled away @ 17v

100k with 25k,11k,7.1k,5.3k = 1.5Ma
1m with 250k,111k,71.4k,53,3k = 150μa
then of-cause I could do 10m but I am assuming that will lead to false readings

I did buy those 25v voltage sensors from ebay but they just popped smoke when trying to read more than 1 battery while using the same esp they had 30k + 7.5k  smd resistors , so just going to make a VD in series and try again
 :horse:
First, some people here get their knickers in a bunch when units and prefixes are used incorrectly.
Volts is V not v
Ampere is A not a
Mega is M not m (m is definitely milli, and milliohms is used as much as Megaohms so don't swap M/m).

With those cheap "sensors" (expensive voltage dividers), did you connect one across each battery then connect them all together (i.e. connect their grounds together)? That is a recipe for flash/bang/smoke. Every one needs its ground at the '-' terminal of the battery bank, not the '-' terminal of each battery. So one measures battery 1; the next measures battery 1 and 2; the next 1,2, and 3, etc.  Then you do the simple math to calculate the voltage of each individual battery.

As gamalot said, you can use quite high value resistors and put a cap across the lower one (effectively from the ADC input to ground) to provide a low impedance for the ADC to read accurately. 1 MOhm is fine. Using 0.01 µF to 0.1 µF would be fine. As above, each voltage divider connects to the same ground reference, not directly across each battery.
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2440
  • Country: gb
  • Recovering Electrical Engineer
Re: Battery Monitoring - Voltage Divider
« Reply #23 on: June 09, 2022, 03:31:26 pm »
Leakage currents in MOSFETS can give rise to significant errors high Z dividers
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf