Author Topic: Voltage scaling for ADC  (Read 8773 times)

0 Members and 1 Guest are viewing this topic.

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 702
  • Country: in
  • Self taught, experimenter, noob(ish)
Voltage scaling for ADC
« on: June 02, 2021, 05:58:20 pm »
What fact am I missing?
I noticed, most people use a voltage divider for reducing voltage to safe level for ADC to read.
Eg, "divide by 3" voltage divider for reading 12v battery using 5v microcontroller.
if V-ref is 5v,for 10bit adc, the resolution would be 0.0146484375 per bit

Why don't we use the lower (in photo) setup with 11v zener diode deducing the voltage.
if V-ref is 5v,for 10bit adc, the resolution would be 0.0048828125 per bit AKA 3x more accurate.

forgive me is someone actually already use it and it just happened to be that I've never seen it being done.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 4671
  • Country: nl
Re: Voltage scaling for ADC
« Reply #1 on: June 02, 2021, 06:08:08 pm »
The problem here is with temperature and current stability of the zener diode.

You could improve in that with better diodes or even reference voltage IC's, but in practice a simple voltage divider is good enough, low in parts count and cheap.
 
The following users thanked this post: Raj

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13864
Re: Voltage scaling for ADC
« Reply #2 on: June 02, 2021, 06:17:57 pm »
If you need better, (e.g. if you only care about the input range 10V to 15V) use an OPAMP to subtract an offset, derived from your ADC reference, so that the desired input range is expanded to the full scale range of the ADC.  Adding an OPAMP in front of the ADC also has the benefit of allowing a far higher resistance potential divider to be used, minimizing battery drain, without violating the ADC's max. source impedance requirements.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 21893
  • Country: gb
  • 0999
Re: Voltage scaling for ADC
« Reply #3 on: June 02, 2021, 09:33:32 pm »
A reference such as the TL431 would be better, than a zener.
 
The following users thanked this post: Raj

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2152
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Voltage scaling for ADC
« Reply #4 on: June 02, 2021, 09:54:26 pm »
The errors introduced by the temperature co-efficient of a normal zener would exceed any gain in resolution from the ADC from the technique.

The issue with a TL431 (Zero999 suggestion) would be the current required to make it operate (typically around 1mA, although there are lower current versions).

If you need to scale/offset your input to better match the capability of your ADC then consider an opamp (Ian.M suggestion) configured as a differental amplifier - probably the most common way of solving this issue.

Don't forget that your ADC is only as good as it's reference!
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 
The following users thanked this post: Raj

Offline RES

  • Regular Contributor
  • *
  • Posts: 109
  • Country: 00
Re: Voltage scaling for ADC
« Reply #5 on: June 02, 2021, 11:31:15 pm »
check this idea:

VOLTAGE REFERENCE SCALING TECHNIQUE INCREASES ADC ACCURACY TO KEEP COSTS DOWN
https://www.maximintegrated.com/en/design/technical-documents/app-notes/2/2013.html
 
The following users thanked this post: Raj

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13864
Re: Voltage scaling for ADC
« Reply #6 on: June 03, 2021, 12:12:17 am »
Typical Maxim - add three more chips to try to make a silk purse out of a sows ear.   Also you need to check if reducing the reference voltage decreases the ADC's accuracy.  Its very easy to end up in the situation where decreasing the reference looses you reliable bits at the LSB end faster than decreasing the range increases the precision.
 
The following users thanked this post: fcb, Raj

Offline bdunham7

  • Super Contributor
  • ***
  • Posts: 9313
  • Country: us
Re: Voltage scaling for ADC
« Reply #7 on: June 03, 2021, 01:00:57 am »
 I'm not an MCU expert, but I haven't seen this done in anything I've worked on.  There's probably some good reasons you won't commonly see this.

First, in a very low cost device, reading a 12V battery to 15mV is probably good enough, getting 3X the resolution at the expense of additional complication and not seeing very low voltages just isn't worth it.

Second, almost any solution that would work well enough to take advantage of that resolution would probably be more complicated and expensive than just switching to an MCU with a 12-bit ADC.

Third, even a 10-bit ADC implies a resolution of 0.1% of full scale (of the ADC).  Are your voltage divider resistors, reference voltage and the ADC itself going to be that accurate and stable in the first place?  Are you going to have a calibration procedure?  While some applications might benefit from increased resolution beyond the actual accuracy, I don't think battery monitors or temp sensors generally fall into that category.
« Last Edit: June 03, 2021, 11:15:31 am by bdunham7 »
A 3.5 digit 4.5 digit 5 digit 5.5 digit 6.5 digit 7.5 digit DMM is good enough for most people.
 
The following users thanked this post: Ian.M, Raj

Offline Caliaxy

  • Frequent Contributor
  • **
  • Posts: 307
  • Country: us
Re: Voltage scaling for ADC
« Reply #8 on: June 03, 2021, 05:27:56 am »
Why don't we use the lower (in photo) setup with 11v zener diode deducing the voltage.
if V-ref is 5v,for 10bit adc, the resolution would be 0.0048828125 per bit AKA 3x more accurate.

I think you meant your zener diode be 7.5V or around. Other than that, as Ian.M says...
 
The following users thanked this post: Raj

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 16236
  • Country: de
Re: Voltage scaling for ADC
« Reply #9 on: June 03, 2021, 08:08:58 am »
Simple zener diodes are not stable enoug. A stable reference usually needs more current than one is willing to accepts from the input. The resistor also is part of the protection in case the votlage goes higher than normal or negativ.
With many µC intenal ADCs one can use relatively high values resistors for the divider if there is an additional capacitor (e.g. 10-100 nF) to buffer the ADC input. Battery votlage usually does not change that fast.

The idea with the zener may habe been an option in the old days of analog meters (e.g. to show the charging state of a lead based battery).
 
The following users thanked this post: Raj

Offline BeBuLamar

  • Super Contributor
  • ***
  • Posts: 1809
  • Country: us
Re: Voltage scaling for ADC
« Reply #10 on: June 03, 2021, 09:45:04 am »
Assuming the zener diode works perfectly in the first case you can measure the battery voltage as it varies between 0 to a maximum of 15V. In the case of the diode you can measure the voltage of the battery between 11 and 12V only. If that is what you want you can use an op amp instead of the zener.
 
The following users thanked this post: Raj

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 21893
  • Country: gb
  • 0999
Re: Voltage scaling for ADC
« Reply #11 on: June 03, 2021, 09:55:51 am »
If quiescent current draining the battery is an issue, just add a P-channel MOSFET to only connect the battery, when a reading is being taken..
 

Offline exe

  • Supporter
  • ****
  • Posts: 2866
  • Country: nl
  • self-educated hobbyist
Re: Voltage scaling for ADC
« Reply #12 on: June 03, 2021, 09:57:41 am »
Yes, you can do that. It's called something like "match signal levels to the input range of ADC" (signal conditioning?). Just be careful about more resolution != more precision. A precise voltage divider may work better than a sloppy drifting voltage subtractor.

Also, do you really need that extra resolution?

PS One thing to think about is what should happen when input signal is not in range.

 
The following users thanked this post: Raj

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 702
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Voltage scaling for ADC
« Reply #13 on: June 03, 2021, 11:55:46 am »
Got it. zeners aren't stable and there are other ways to doing the same....like opamps and inbuilt "negative input mux" like in atmega32u4 (just have a stable source of 11v at negative input)

Assuming the zener diode works perfectly in the first case you can measure the battery voltage as it varies between 0 to a maximum of 15V. In the case of the diode you can measure the voltage of the battery between 11 and 12V only. If that is what you want you can use an op amp instead of the zener.
Assuming the zener diode works perfectly in the first case you can measure the battery voltage as it varies between 0 to a maximum of 15V. In the case of the diode you can measure the voltage of the battery between 11 and 12V only. If that is what you want you can use an op amp instead of the zener.

took some liberty in writing those numbers...
like typical lead acid can go upto 14.4v, so a V ref of 14.4v- 11 will yield more accurate results and if the reading is either 0v or 11v, in both cases, the battery is as good as not being there ( missing or dead)
 

Offline BeBuLamar

  • Super Contributor
  • ***
  • Posts: 1809
  • Country: us
Re: Voltage scaling for ADC
« Reply #14 on: June 03, 2021, 12:25:48 pm »
Higher resolution is better I don't argue but really should we go thru the trouble to do that. I don't think it's needed.
 

Offline bdunham7

  • Super Contributor
  • ***
  • Posts: 9313
  • Country: us
Re: Voltage scaling for ADC
« Reply #15 on: June 03, 2021, 12:49:00 pm »
like typical lead acid can go upto 14.4v, so a V ref of 14.4v- 11 will yield more accurate results and if the reading is either 0v or 11v, in both cases, the battery is as good as not being there ( missing or dead)

What I and others have posted above is relevant to the technique you are exploring, but since you mention lead-acid monitoring specifically, I think some of your assumptions may be off.

First, even assuming you go to the effort and expense of achieving better than 0.1% accuracy, measuring a six-cell LA battery to 0.005V vs 0.015V is pointless unless you also have an accurate temperature reading and probably individual cell measurements.  You see this sort of thing in Li-ion battery packs in cars and such where careful monitoring and cell balancing are important, but not in typical 12V LA batteries, whether it be a UPS or a car.

Second, it's not true that there's no distinction between 0V and 11V.  If you are only making a 'fuel gauge' type of monitor and the battery is not heavily loaded, then perhaps this assumption is good enough--but then why would you need such accuracy?  If this is for a charge/discharge system like a car or UPS, then there's a big difference between a battery discharged to 6 volts vs. 10.8 volts.  And not much difference  between a battery at 12.900 vs 12.905.  Is there a specific reason you think you need the resolution or are you just experimenting with measuring techniques?
« Last Edit: June 03, 2021, 01:20:07 pm by bdunham7 »
A 3.5 digit 4.5 digit 5 digit 5.5 digit 6.5 digit 7.5 digit DMM is good enough for most people.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5388
  • Country: Earth
Re: Voltage scaling for ADC
« Reply #16 on: June 03, 2021, 01:00:25 pm »
Why don't we use the lower (in photo) setup with 11v zener diode deducing the voltage.

if you want to measure difference between measured voltage and 11V, then you will be unable to measure battery voltage when it drops below 11 V. With such measurement you will be unable to detect if the battery is discharged to 8 V (which means that battery is dead and needs to be replaced) or if the battery is discharged to 11 V (which means that battery needs to be recharged). In both case your ADC will show 0. ;)

For a lead-acid batteries, resolution 0.015 V is good enough. If you're needs to control Li-Ion battery, just use better ADC with better resolution.
« Last Edit: June 03, 2021, 01:08:34 pm by radiolistener »
 
The following users thanked this post: Raj

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 21893
  • Country: gb
  • 0999
Re: Voltage scaling for ADC
« Reply #17 on: June 03, 2021, 01:27:39 pm »
One thing to note, if you opt for the voltage reference is, the output voltage can never go to zero. Suppose the reference is set to 11V, to give 0V to 4V, out with 11V to 15V in. If we pick the TL431, the current must be >1mA over this voltage range, which isn't possible near 0V.

You could set the reference to 10.5V, for a range of 0.5V to 4V. A 470R could be selected for just over 1mA, at 0.5V, but the current would be 8.5mA, at 4.5V, which would drain the battery, so a MOSFET would be required to shut it down, when not in use.
 
The following users thanked this post: Raj

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10020
  • Country: us
Re: Voltage scaling for ADC
« Reply #18 on: June 03, 2021, 01:57:22 pm »
"Op Amps For Everyone" Chapter 4 covers offset and scaling with an op amp and 4 resistors.

http://web.mit.edu/6.101/www/reference/op_amps_everyone.pdf

This works well when you are only interested in a range that doesn't start at 0V and allows the ADC to measure only the range of interest.
 
The following users thanked this post: Raj, Caliaxy

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13864
Re: Voltage scaling for ADC
« Reply #19 on: June 03, 2021, 03:31:46 pm »
Here's what a non-inverting* version of the OPAMP solution may look like, for 10V-15V in and 0V-3.3V out.



Design considerations are:
  • Choose R1:R2 divider resistors to keep the OPAMP +in voltage within the rails and for acceptable quiescent current in the divider if its going to be permanently connected to a battery
  • Choose the OPAMP gain so that in combination with the R1:R2 divider ratio it gives the desired input range to output range scaling factor
  • Tweak the R3:R4 divider ratio for the desired offset then R5, R6 for the required gain# , allowing for the Thevenin equivalent resistance of the R3:R4 divider in series with R5

R5 isn't theoretically necessary, as the gain could be purely set by R6 and R3||R4, and there is some flexibility as the R1:R2 input divider ratio can also be varied, but it reduces the constraints on the solution space allowing the use of more readily available resistor values.  A high volume design is likely to omit it, but for small runs, possible BOM minimization and reduced design time can justify its inclusion.

Its very similar to fig. 4-8 of "Op Amps For Everyone" Chapter 4 (Rstofer's excellent recommendation), and the equations presented there will be helpful if you wish to attempt a purely analytic solution.

Filtering is likely to be required - add a capacitors across R2 (and possibly R6 as well for a steeper rolloff)  for the desired bandwidth.

Finally pick a rail-to-rail output OPAMP with an input bias current at least three orders of magnitude smaller than the R1:R2 divider current, and low enough offset voltage for the required accuracy.  Check the voltage range at its inputs will be within its common mode range, and that the max. input current through R1 during fault conditions (e.g HV input transients) or if the OPAMP is powered down will be acceptable.

If the MCU has EEPROM or self-writable FLASH, a production line self-calibration step that applies input voltages at 10% and 90% of the design input range, then calculates and saves the actual scaling factor and offset, may allow the use of lower precision resistors without loss of accuracy.

* Non-inverting: the output increases with increasing input.

# the signal gain is:

$$Gain=1+\frac{R6}{R5+R3||R4}$$

Edit: corrected gain equation
« Last Edit: June 03, 2021, 05:51:09 pm by Ian.M »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 21893
  • Country: gb
  • 0999
Re: Voltage scaling for ADC
« Reply #20 on: June 03, 2021, 04:07:59 pm »
I agree that using an op-amp is the best approach.

Here's a handy calculator site, which helps with the calculations and resistor values.
http://earmark.net/gesr/opamp/gain_offset.htm
 
The following users thanked this post: Ian.M, ledtester

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 702
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Voltage scaling for ADC
« Reply #21 on: June 03, 2021, 05:43:18 pm »
Now I get it...
Neither do you need a resolution that high, like ever.
nor will zener be that accurate.
Nor is it worth it to have special components like op amps cause again, you don't need that accuracy for practical reasons.

So, giving a battery for measurement, was a bad example.

But I guess... you can still use it for like, angle encoder for joysticks cause zener accuracy isn't that important and you can have it in the firmware to calibrate the "min" and "max" on the fly, so zener inaccuracy won't be an issue.
 

Offline exe

  • Supporter
  • ****
  • Posts: 2866
  • Country: nl
  • self-educated hobbyist
Re: Voltage scaling for ADC
« Reply #22 on: June 03, 2021, 06:31:16 pm »
But I guess... you can still use it for like, angle encoder for joysticks cause zener accuracy isn't that important and you can have it in the firmware to calibrate the "min" and "max" on the fly, so zener inaccuracy won't be an issue.

In my experience zeners are horribly drifty and inaccurate unless it's lm399 or ltz1000, and even those need extra circuitry to be accurate (like current source and output buffer). My advice is to avoid it if possible. Use tl431 instead. It's and "adjustable zener" (the name is misleading because there is no zener inside) or any other bandgap floating shunt reference.

Often doing digital trimming is a better option because there is no parts are needed. Less parts == more precision, less complexity, smaller costs. Often extra resolution can be get with oversampling (but not always).

Anyway, you can build two circuits and evaluate their performances.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 18746
  • Country: us
  • DavidH
Re: Voltage scaling for ADC
« Reply #23 on: June 03, 2021, 09:27:03 pm »
Why don't we use the lower (in photo) setup with 11v zener diode deducing the voltage.
if V-ref is 5v,for 10bit adc, the resolution would be 0.0048828125 per bit AKA 3x more accurate.

Sometimes they do for exactly the reason you identify; a level shift rather than attenuation allows for a higher resolution measurement.  But there are practical difficulties which make a resistive attenuator more appealing.

Instead of a zener diode, a precision shunt voltage reference can be used for the level shift, and there are other ways as well.
 
The following users thanked this post: Raj

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13864
Re: Voltage scaling for ADC
« Reply #24 on: June 04, 2021, 03:56:40 pm »
A further note on the OPAMP circuits:  my version is overkill with two extra resistors vs the four resistor circuit ("Op Amps For Everyone" Chapter 4, fig. 4-8), and the circuit generated by the calculator Zero999 linked in reply #20.

I've already discussed R5 above, I'm now going to discuss the R3:R4 reference divider.  If you omit it, and use the four resistor circuit, you save two passives.  However the reduction in the number of resistors comes at a price - at the top end of the output range, both inputs will be at the reference voltage, which means if the reference is, or is close to, the OPAMP Vcc supply you need a true RRIO OPAMP to avoid violating its input common mode range.   Using a divider for the reference as I did may well let you use a cheaper 'jellybean' OPAMP, that only has a rail-to-rail output.
 
The following users thanked this post: Raj


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf