Voltage scaling for ADC - Page 1
Forum section: electronics / beginners

author: Raj
author_rank: Frequent Contributor
timestamp: June 02, 2021, 05:58:20 pm
content: 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 bitWhy 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.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 02, 2021, 06:08:08 pm
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: June 02, 2021, 06:17:57 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: June 02, 2021, 09:33:32 pm
content: A reference such as the TL431 would be better, than a zener.

author: fcb
author_rank: Super Contributor
timestamp: June 02, 2021, 09:54:26 pm
content: 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!

author: RES
author_rank: Regular Contributor
timestamp: June 02, 2021, 11:31:15 pm
content: check this idea:VOLTAGE REFERENCE SCALING TECHNIQUE INCREASES ADC ACCURACY TO KEEP COSTS DOWNhttps://www.maximintegrated.com/en/design/technical-documents/app-notes/2/2013.html

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2021, 12:12:17 am
content: 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.

author: bdunham7
author_rank: Super Contributor
timestamp: June 03, 2021, 01:00:57 am
content: 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.

author: Caliaxy
author_rank: Frequent Contributor
timestamp: June 03, 2021, 05:27:56 am
content: Quote from: Raj on June 02, 2021, 05:58:20 pmI think you meant your zener diode be 7.5V or around. Other than that, as Ian.M says...

author: Kleinstein
author_rank: Super Contributor
timestamp: June 03, 2021, 08:08:58 am
content: 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).

author: BeBuLamar
author_rank: Super Contributor
timestamp: June 03, 2021, 09:45:04 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: June 03, 2021, 09:55:51 am
content: 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..

author: exe
author_rank: Unknown
timestamp: June 03, 2021, 09:57:41 am
content: 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.

author: Raj
author_rank: Frequent Contributor
timestamp: June 03, 2021, 11:55:46 am
content: 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)Quote from: BeBuLamar on June 03, 2021, 09:45:04 amQuote from: BeBuLamar on June 03, 2021, 09:45:04 amtook 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)

author: BeBuLamar
author_rank: Super Contributor
timestamp: June 03, 2021, 12:25:48 pm
content: 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.

author: bdunham7
author_rank: Super Contributor
timestamp: June 03, 2021, 12:49:00 pm
content: Quote from: Raj on June 03, 2021, 11:55:46 amWhat 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?

author: radiolistener
author_rank: Super Contributor
timestamp: June 03, 2021, 01:00:25 pm
content: Quote from: Raj on June 02, 2021, 05:58:20 pmif 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.

author: Zero999
author_rank: Super Contributor
timestamp: June 03, 2021, 01:27:39 pm
content: 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.

author: rstofer
author_rank: Super Contributor
timestamp: June 03, 2021, 01:57:22 pm
content: "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.pdfThis 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.

author: Ian.M
author_rank: Super Contributor
timestamp: June 03, 2021, 03:31:46 pm
content: 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 batteryChoose the OPAMP gain so that in combination with the R1:R2 divider ratio it gives the desired input range to output range scaling factorTweak 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 R5R5 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

author: Zero999
author_rank: Super Contributor
timestamp: June 03, 2021, 04:07:59 pm
content: 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

author: Raj
author_rank: Frequent Contributor
timestamp: June 03, 2021, 05:43:18 pm
content: 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.

author: exe
author_rank: Unknown
timestamp: June 03, 2021, 06:31:16 pm
content: Quote from: Raj on June 03, 2021, 05:43:18 pmIn 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.

author: David Hess
author_rank: Super Contributor
timestamp: June 03, 2021, 09:27:03 pm
content: Quote from: Raj on June 02, 2021, 05:58:20 pmSometimes 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.

author: Ian.M
author_rank: Super Contributor
timestamp: June 04, 2021, 03:56:40 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: June 04, 2021, 06:15:15 pm
content: Quote from: Ian.M on June 04, 2021, 03:56:40 pmOr run the op-amp off a higher voltage and use a single supply op-amp, such as the good old LM358.I've never understood why some people use rail-to-rail op-amps run off an LM7805, or whatever, when they can use cheaper, more widely available parts, run off whatever is powering the regulator. This scales 10V to 15V, to 0V to 5V, which is probably more useful, but if you want something different, change the resistor values.

author: bdunham7
author_rank: Super Contributor
timestamp: June 04, 2021, 06:48:44 pm
content: Quote from: Zero999 on June 04, 2021, 06:15:15 pmI think you've won the design competition here--that's pretty good! I think the reason for unnecessarily using regulator-supplied op-amps is either not understanding or not trusting the PSRR spec.

author: Ian.M
author_rank: Super Contributor
timestamp: June 04, 2021, 07:24:10 pm
content: The penalty is: it no longer limits the output voltage to within the ADC's supply rails, so if there is any possibility whatsoever of the input voltage exceeding the upper limit of the range, you are going to need a clamping circuit between the OPAMP and the ADC. That's probably why the single supply OPAMP powered from the same supply as the ADC remains so popular.

author: voltsandjolts
author_rank: Unknown
timestamp: June 04, 2021, 08:17:06 pm
content: erm, any noise on that 12V rail gets coupled straight to output via R3/R4.

author: Zero999
author_rank: Super Contributor
timestamp: June 04, 2021, 08:29:56 pm
content: Quote from: Ian.M on June 04, 2021, 07:24:10 pmThat's also the case with a potential divider. The spare op-amp in the LM358 could be made into a clamper, with a diode, but I'd just use a current limiting resistor.Quote from: voltsandjolts on June 04, 2021, 08:17:06 pmErm, well it is measuring the voltage on that 12V rail, along with any noise, so that's to be expected and is the case for all of the other circuits posted in this thread. It can easily be low pass filtered by putting a capacitor across R4 and perhaps also R2.

author: wizard69
author_rank: Super Contributor
timestamp: June 05, 2021, 10:23:55 pm
content: Like a lot of things it depends.Quote from: Raj on June 03, 2021, 05:43:18 pmMaybe, maybe not. For example some battery charge profiles and monitoring circuits, operate in the hundredth of a volt range. A test profile might suggest a discharge voltage of 2.75 VDC on a lithium cell. Some test engineers would tell you you need to be able to read that 10X more accurately or to 0.005 VDC. Personally 4X is probably good enough so maybe 0.0125 VDC per bit. Then you need to consider instrument and test rig stability.For more general usage I'm not sure if there is value in reading a battery voltage out to 0.001 VDC. Probably somebody at Tesla will describe why I'm completely wrong about that. It would vary with chemistries though. In general though batteries only have a fixed useful voltage range so does it really make sense to try to measure the voltage of a lead acid batter down to zero volts. A 12 VDC battery is pretty dead at around 8 volts DC so why bother below that voltage? You will get pretty high resolution just by limiting your measurement range to the useful voltage of the battery.For more general A to D work the required resolution depends upon what you are doing. Even here a sensor might not have a useful range that starts at zero.QuoteWell again it depends. A simple battery voltage monitor probably doesn't need high resolution. For lithium cells the charging cut off voltages are often spec'ed to a tenth of a volt, say 4.2±0.05 volts. 0.05 VDC is not high resolution in most books. So if you are DIYing a battery charger for lithium than measuring voltage to one hundredth of a volt is likely good enough. For 12 VDC lead acids I'd have to look up the specs but I really doubt it is that critical considering how crude some automotive charging circuits are (where).QuoteActually it is a good example because if you are working with other transducers they may only be linear over a fixed length of their entire output range. Sometimes you are only interested in a portion of the linear range so the input gets conditioned around that usable range. So yeah it is an example that can drive the discussion.QuoteMaybe. Again it depends but in the case of a joystick, assuming you are designing from the ground up, you would design such that you don't have such issues in the first place. That is if you are making an angle encoder why would it have a voltage output that exceeds what your A to D can handle? If the voltage output was an issue a voltage divider still makes sense for simplicity.

author: exe
author_rank: Unknown
timestamp: June 06, 2021, 07:55:39 am
content: If the goal is to make a battery charger, esp. for li-ion batteries, then I recommend buy an IC that does just that -- charge controller. I don't recommend beginners to reinvent the wheel and do it in software: one software bug and it may degrade, catch fire or explode.I don't see a huge difference in resolution when comparing, e.g., 8...15V and 0..15V. Anyway, one can use a higher-resolution ADC to compensate for that, like 16-bit sigma-delta ADCs are quite cheap. For a one-off project I'd suggest not to try to spare every single cent on BOM, but just buy good parts.