Author Topic: Voltage divider/ADC for measuring battery voltage  (Read 8114 times)

0 Members and 1 Guest are viewing this topic.

Offline pugglewuggleTopic starter

  • Contributor
  • Posts: 10
Voltage divider/ADC for measuring battery voltage
« on: April 17, 2014, 04:43:03 pm »
Hi,

I've looked all over the internet over the last week and have seen all sorts of example circuits with different reasoning behind them for accomplishing this task. Here is my situation:

I want an onboard battery/input voltage monitoring capability for my device... right now I'm looking at using the onboard 12-bit ADC of the Atmel SAM4S ARM MCU. The power supply voltage can range anywhere from 9V to around 36V so I need to be able to measure this range. I'll be using an AVref of 2.5V. This doesn't need to be super accurate, really just to the hundredth of a volt, which 12-bit provides for just fine at this range plus a little LSB error which is okay.

There are a couple of factors I'm considering that I need to know if I should take into account or just ignore in this design:
  • Loading effect on the divider output voltage from ADC impedance/resistance
  • How am I to calculate the signal output impedance from the divider (Theverin resistance?) that's required to work with the ADC's internal impedance (rather relates to point 1)? not sure where to start on this one due to what isn't obvious to me in the SAM4S datasheet

Any help and and other thoughts is greatly appreciated.
 

Offline qno

  • Frequent Contributor
  • **
  • Posts: 422
  • Country: nl
Re: Voltage divider/ADC for measuring battery voltage
« Reply #1 on: April 17, 2014, 06:32:20 pm »
One option is to put a capacitor of about 10 nF in the mid point of the voltage divider.
Most microcontrollers A/D have a nasty sample pulse.

Do not expect more than 0.1V accuracy
Why spend money I don't have on things I don't need to impress people I don't like?
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #2 on: April 17, 2014, 07:14:34 pm »
You could also use a relatively strong voltage divider with a Pch on the high side to turn it on or off.  Turn it on to make your measurement, turn it off when done.  The divider would have a low enough output impedance to not significantly affect the A/D measurement, and then when you turn it off the current consumption drops to zero.  It does take an extra microcontroller pin though.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Voltage divider/ADC for measuring battery voltage
« Reply #3 on: April 17, 2014, 07:20:42 pm »
Quote
Loading effect on the divider output voltage from ADC impedance/resistance

Only if your adc's input impedance is comparable to the divider's output resistance - typically not the case, but check your device datasheet for sure.

In case that is the case, use a capacitor to minimize charge transfer.

Quote
How am I to calculate the signal output impedance from the divider (Theverin resistance?) that's required to work with the ADC's internal impedance (rather relates to point 1)? not sure where to start on this one due to what isn't obvious to me in the SAM4S datasheet

That would be the parallel of the two resistors. I usually use anything less than 1/10th of the adc's input impedance - anything less than 100k should work most of the times.

Quote
with a Pch on the high side to turn it on or off.

You will have a hard time to shut off that P-ch, without the use of another level shifter.

I usually just turn it on / off on the low-side (directly via a pin, or via another switch).
================================
https://dannyelectronics.wordpress.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #4 on: April 17, 2014, 07:49:23 pm »
Quote
with a Pch on the high side to turn it on or off.

You will have a hard time to shut off that P-ch, without the use of another level shifter.

I usually just turn it on / off on the low-side (directly via a pin, or via another switch).
With his voltages, yes.  Could always use an N/P pair though.  uC switches the N, N switches the P.  I would hesitate to use low-side switching in this application due to the voltages at play.  As soon as the resistor divider is cut off from ground, it's going to pull up to battery voltage, and start leaking through the uC's clamping diode.
 

Offline pugglewuggleTopic starter

  • Contributor
  • Posts: 10
Re: Voltage divider/ADC for measuring battery voltage
« Reply #5 on: April 17, 2014, 08:41:17 pm »
@Suicidaleggroll I have considered this and the only question I had is why everyone uses a P-channel instead of an N-channel before ground? Also, I'm a little concerned about leakage but I understand that to be usually just a couple of nA so it's really not a big deal, even in battery-powered systems (I think?)

@dannyf I don't know the input impedance nor can I find it in the datasheet. Can you look for me and see if I'm just missing something? The ADC electrical characteristics start on page 1131. Here's the link: http://www.atmel.com/images/atmel_11100_32-bit-cortex-m4-microcontroller_sam4s_datasheet.pdf

Regarding an N-channel on the ground side of the divider, can I just run the low side of the divider into a GPIO pin and drive it to ground/set it to output high when not using?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Voltage divider/ADC for measuring battery voltage
« Reply #6 on: April 17, 2014, 08:44:40 pm »
Quote
start leaking through the uC's clamping diode.

So you are using theh clamping diodes as they are supposed to be used.

Why worry about it?
================================
https://dannyelectronics.wordpress.com/
 

Offline pugglewuggleTopic starter

  • Contributor
  • Posts: 10
Re: Voltage divider/ADC for measuring battery voltage
« Reply #7 on: April 17, 2014, 08:48:05 pm »
Just wanted to clarify - I missed the Zin... it's 1Mohm at 500ksps with the 2pf Cin enabled from the gain mode in use.
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #8 on: April 17, 2014, 09:34:11 pm »
@Suicidaleggroll I have considered this and the only question I had is why everyone uses a P-channel instead of an N-channel before ground?
For the reason dannyf and I are currently discussing.

Regarding an N-channel on the ground side of the divider, can I just run the low side of the divider into a GPIO pin and drive it to ground/set it to output high when not using?
That wouldn't accomplish anything.  Remember, your battery is at up to 36v, and your resistors will be bleeding current through whatever the bottom is connected to.  If you set your GPIO low, you'll get (36-0)/(R1+R2) current.  If you set your GPIO high, you'll get (36-3.3)/(R1+R2) current (plus a little bit through the clamping diode of the ADC pin).  Not going to change much.  If you set your GPIO to a high impedance input, you'll get (36-3.3-Vf)/R1 as the resistor continues to dump current through the microcontroller's clamping diode.
« Last Edit: April 17, 2014, 09:41:29 pm by suicidaleggroll »
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #9 on: April 17, 2014, 09:36:54 pm »
Quote
start leaking through the uC's clamping diode.

So you are using theh clamping diodes as they are supposed to be used.

Why worry about it?

Two reasons

1) They're not "supposed" to be used at all.  Dumping current through the clamping diode can have unpredictable results since there's no clear ground path.  It can flip bits, lock up the CPU, and do other unpredictable things.  The current limit in the datasheet is just a damage limit, you can still get unpredictable and unexpected results with MUCH less current than the limit in the datasheet.

2) What's the point in shutting the fet off?  You haven't shut off the current draw, you've just redirected it.  Instead of dumping current from 36V through R1, R2, Nch, to ground, you're dumping current from 36V through R1, uC clamping diode, to ground.  Still wasting nearly as much current as if you just left the Nch on.

In this application, a Pch will shut off the current, while an Nch will just redirect it through the mcu's clamping diode, still wasting nearly as much current and possibly causing unpredictable behavior in the mcu.
« Last Edit: April 17, 2014, 09:42:29 pm by suicidaleggroll »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Voltage divider/ADC for measuring battery voltage
« Reply #10 on: April 17, 2014, 09:54:39 pm »
Quote
1) They're not "supposed" to be used at all. 

So those guys made something into a chip so that they are not "supposed" to be used at all? Then why design them?

Quote
Dumping current through the clamping diode can have unpredictable results

like what?

Quote
since there's no clear ground path. 

Unless your "clear" is different from my "clear", would the power supply work for you? or the adc? or those  thousands of little fets inside of that mcu?

Quote
It can flip bits,

So can a power supply; or your code; or lightening; or cosmic ray;...

Quote
lock up the CPU,

ditto.

Quote
and do other unpredictable things. 

like?

Quote
The current limit in the datasheet is just a damage limit,

No one suggested that you run that much current through the clamping diodes.

Quote
you can still get unpredictable and unexpected results with MUCH less current than the limit in the datasheet.

I still don't know what those "unpredictable and unexpected results" are.

Quote
2) What's the point in shutting the fet off? 

Complexity for one.

Quote
Still wasting nearly as much current as if you just left the Nch on.

No argument there.
================================
https://dannyelectronics.wordpress.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #11 on: April 17, 2014, 10:26:44 pm »
So those guys made something into a chip so that they are not "supposed" to be used at all? Then why design them?
To protect against damage in the case of unforeseen or accidental reverse or over voltage.  Not so the designer can be lazy and hope for the best.

Quote
Quote
Dumping current through the clamping diode can have unpredictable results
like what?
Like latching the chip, or reversing current from the power supply, raising Vcc and damaging the mcu itself or other circuitry.  They're great for protecting the chip from damage caused by ESD, brain farts, etc., but they shouldn't be "used" as part of a design.  It's like relying on the automatic distance checking/breaking system on a car to stop you at every red light.
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #12 on: April 17, 2014, 10:49:06 pm »
Also, I'm a little concerned about leakage but I understand that to be usually just a couple of nA so it's really not a big deal, even in battery-powered systems (I think?)

Leakage current is different than dumping current through a pin's clamping diode.

Leakage current is when you apply a voltage within the 0-Vcc spec of the mcu, and the mcu leaks a little bit of it through.  It willl be very small, as you said typically in the pA/nA range, and is more or less insignificant for what you're looking at here.

The clamping diode is another animal altogether.  When you raise the voltage applied to a pin above Vcc (or below Gnd), there's a diode (or a diode-like combination of substrates) that keeps the voltage from going more than 1 diode drop beyond Vcc or Gnd.  When it does, the diode begins to conduct, and starts dumping current into the nearest rail.

The reason you don't often see low-side switching for resistor divider voltage monitoring like this is because the low-side switch serves no real purpose.  If the switch is on, the resistors conduct current from the battery to ground.  If the switch is off, the voltage applied to your ADC pin jumps up to your battery voltage, and the resistors (at least the high side resistor) conducts current from the battery through the mcu's clamping diode to Vcc.  The net effect is basically the same.  You might drop the current draw by 10-20% (depending of course on battery voltage and mcu Vcc), but you're still going to be pulling nearly as much current from the battery as you were with the switch on (AND you might even damage the mcu, see above).  In which case, you might as well just drop the switch and ground the resistors directly.  Of course if you do that, you're back to square one...unnecessarily dumping current from the battery through a resistor divider and wasting power.

A high-side switch lets you cut off the current draw of the resistor divider completely, without dumping anything through the mcu's clamping diode (since when you cut the resistors off from battery voltage, the voltage applied to your ADC pin just drops to Gnd).
« Last Edit: April 17, 2014, 10:50:56 pm by suicidaleggroll »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Voltage divider/ADC for measuring battery voltage
« Reply #13 on: April 18, 2014, 12:03:01 am »
Quote
Like latching the chip, or reversing current from the power supply, raising Vcc and damaging the mcu itself or other circuitry.

Many things you do with a mcu will expose it to the risks listed above, and more.

Having a reality check would be helpful.
================================
https://dannyelectronics.wordpress.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #14 on: April 18, 2014, 12:25:35 am »
Many things you do with a mcu will expose it to the risks listed above, and more.

Having a reality check would be helpful.

Yeah, most of the time those things are beyond the designer's control.  But purposely designing the circuit to do something with the mcu that it's not supposed to do, could damage the mcu itself or the rest of the circuit, and on top of that, serves absolutely no logical purpose, is just asinine.

I suggested he could use a stronger resistor divider to take care of the impedance problem when feeding an ADC and use a Pch to shut it off so it doesn't drain the battery when it's not in use.  You suggested he switch the ground side of the divider instead, which could damage the mcu, the rest of the circuitry on the board, and wouldn't even shut off the resistor divider anyway.

Where exactly are you going with this argument?
« Last Edit: April 18, 2014, 12:27:35 am by suicidaleggroll »
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: Voltage divider/ADC for measuring battery voltage
« Reply #15 on: April 18, 2014, 12:27:22 am »
How about using a high resistance divider and a large cap? The input leakage of the ADC is mostly dynamic due to capacitive switching. When sampled slowly enough you'll only get an error of the capacitive divider.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Voltage divider/ADC for measuring battery voltage
« Reply #16 on: April 18, 2014, 12:42:26 am »
Perhaps use an R-R opamp to buffer the high impedance voltage divider?  Microchip has some opamps (MCP6421 for example) that have pretty low Iq figures.  All depends on how much current draw is acceptable.
 

Offline pugglewuggleTopic starter

  • Contributor
  • Posts: 10
Re: Voltage divider/ADC for measuring battery voltage
« Reply #17 on: April 18, 2014, 01:50:45 pm »
I've got to agree with the eggroll on the clamping diodes... my understanding is that while they're there they are to be used as a safety measure in the case of external circuit failures or brain farts to prevent total system failure/burning up the chip by feeding it more V than it can handle.

@David_AVD and @nctnico... I'd like to keep this simple with passives like resistors/caps if possible. Also, I'd obviously like to minimize waste as much as possible. The high-side P-channel FET sounds like the best plan to me as far as turning the battery monitor on and off for sampling. Can you elaborate more @nctnico?
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Voltage divider/ADC for measuring battery voltage
« Reply #18 on: April 18, 2014, 03:15:54 pm »
@David_AVD and @nctnico... I'd like to keep this simple with passives like resistors/caps if possible. Also, I'd obviously like to minimize waste as much as possible. The high-side P-channel FET sounds like the best plan to me as far as turning the battery monitor on and off for sampling. Can you elaborate more @nctnico?
The three primary methods, in my experience, are:

1) high resistance with a cap to hold the value through the A/D sampling.  This is simple and cheap, but you need to balance resistor size with cap size.  Make the cap too big and you'll smooth through all transients in your battery voltage (this may or may not matter to you).  Make the cap too small and the voltage will drop as the A/D does its sampling.  You'll also be limited on how quickly you can sample it, since you need to give the cap time to recharge between samples.  You'll also be constantly burning off power from the battery.  How much power, and whether or not it's significant, depends on the resistors you choose and the application.

2) high resistance with an opamp buffer.  This is more complex than #1 and still has the constant current draw, but you eliminate the smoothing error and you can sample it as fast as you want.

3) low resistance with a high side switch to shut it off when not in use.  This is about the same level of complexity as #2, but you eliminate the smoothing error, the constant current draw, and you can sample it as fast as you want.  However, the faster you sample it, the more power you pull from the battery.


All three have their place, and I've used all three in different applications.  Which one you should use depends primarily on how often you'll be sampling the voltage and how accurate your measurements need to be.  If you'll be sampling at 10 Hz or faster, I would lean toward #1 or #2.  If you'll be sampling slower, say once per minute, then I would lean toward #3, but that's just me.
 

Offline pugglewuggleTopic starter

  • Contributor
  • Posts: 10
Re: Voltage divider/ADC for measuring battery voltage
« Reply #19 on: April 18, 2014, 10:41:46 pm »
Yeah I'll probably do this once an hour or so. I don't care about the transients but I might take a few samples and average them just to make sure no coupled noise screws up the measurement. What do you mean by low resistance and high resistance in orders of magnitude? 10k? 100k? 1M? 10M? Also, what would you say on cap size. They're so cheap I'm just going to put one on the darn thing to make sure it never sags.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf