ADC input impedance - Page 1
Forum section: electronics / general

author: TomS_
author_rank: Frequent Contributor
timestamp: March 15, 2020, 11:55:25 pm
content: Hi all.Wanting to check my understanding of input impedance to an ADC on a PIC micro (16F887). My head is fine in the digital world, but still got a lot to learn in the analogue world.In the datasheet it says the maximum recommended input impedance is 10K.In my design, where I want to measure the voltage coming from a solar panel, I use a simple resistor divider to take a maximum of ~28V down to 5V for feeding in to the PIC, see attached image. Float voltage of the panel was about 22V, so I added some margin even though it is much less under load.Do I consider the middle of my resistor divider the voltage source, and thus I only have 1K input impedance? It seems to work ok on a breadboard.I want to duplicate this for a second ADC channel to also monitor the voltage of a battery, so would like to be able to minimise current draw as much as possible by using as high value resistors as possible. Or any suggestions for doing this a better way perhaps?Thanks in advance.

author: wraper
author_rank: Unknown
timestamp: March 16, 2020, 12:10:56 am
content: R10 resistor has no use. If you want higher output resistance, simply use higher resistor values in divider. Also everything depends on how often you sample. Usually there is input current to ADC only during sampling. If it's one off sample once in a while, you will be fine with high impedance. All you need is that capacitor holds enough charge for voltage to not sag significantly during sampling. But if you start sampling continuously at high rate, you'd better place opamp before ADC.

author: wraper
author_rank: Unknown
timestamp: March 16, 2020, 12:17:49 am
content: Quote from: TomS_ on March 15, 2020, 11:55:25 pmCompletely wrong. Assuming that signal source has negligible impedance, you should calculate R8 and R9 as parallel resistors and you will get output impedance of the divider. 1.8k in this case. Adding R10 (1k) increases it to 2.8k.

author: TomS_
author_rank: Frequent Contributor
timestamp: March 16, 2020, 12:40:55 am
content: Ah great, thanks.The plan is to only sample once per minute, and the result would feed into another process that would determine if some relays should be switched on to connect a battery charger.I suppose I added R10 just as an extra bit of safety to limit current into the PIC itself should anything go wrong with the divider. It was rather unscientific as an addition though.I'll do some more measurements with the scope when I am back from holidays and make sure the charge in the capacitor holds up during sampling. I started getting some alerts for low battery voltage shortly after I left, and I believe we had a few dull days in the UK around that time, so I presume that the solar panel didnt put out much power and the charger was just draining the battery to power itself. So I was planning to add an additional check to make sure the solar voltage was above some level before switching on this other battery charger to make sure it can actually charge.Then I thought, why not also check the battery itself and see if it even needs charging. Scope creep.

author: hesam.moshiri
author_rank: Regular Contributor
timestamp: March 16, 2020, 09:21:33 am
content: I suggest you put the RC filter before your resistor divider.also, the requested ADC input impedance is dependant on the sampling speed. if you sample slowly, you can manage higher input impedances and vice versa.also, it is dependant on the impedance on the input where you named it 1.one sample per minute is slow so you are fine don't worry

author: Siwastaja
author_rank: Super Contributor
timestamp: March 16, 2020, 10:01:37 am
content: Remove R10.When the ADC samples, it charges its own sampling capacitor (typically around 20pF; see the datasheet). Because the sampling event is short, you need a high current to charge this internal capacitor; if you have R in series, it charges more slowly, and doesn't charge up to the actual input voltage when the sampling time is over! This is why you need a small impedance driving the ADC.Now you have done the right thing: the 100n capacitor has a very low impedance. Especially if it's a low-ESR and low-ESL type like a small ceramic capacitor laid out right next to the pin, in which case it also filters high-frequency noise very well.Now consider the imaginary case ofincreasingthe resistor values (handy to reduce current consumption from the battery measurement); let's ignore the DC leak kind of losses for now, so even if you divider impedance is megaohms, they can stillfinallycharge your 100n cap - it takes time, but finally the 100n cap is at the correct voltage.Now comes sampling: charge transfer happens. The 100nF cap is connected to the internal 20pF cap. Assuming the internal cap was at 0V, and you had to charge it to 1V, you just removed 20pC of charge (to charge 20pF by 1V). The voltage change in the 100nF cap is, again, 20pC/100nF = 0.2 millivolts. So you are still quite close to the right value.Now, consider you sampleagain- the large input R haven't had time to recharge the 100nF cap, so you are losing charge again. The error starts to increase.Hence, the key for succesful, simple sampling of battery voltage is:1) Use high value resistors in the divider to prevent unnecessary battery drain (don't go overboard, though; there are DC leakages, although very small)2) Use a large enough capacitor to give the ADC the low impedance it needs. 1000 times the sampling capatitance would be good to 10 bits of accuracy, and so on. (Handwaving approximation, actual math is left as excercise.)3) Don't sample too often. Your resistor divider has an output impedance of the parallel combination of the two resistors; this forms an RC circuit with the filter capacitor, which stabilizes to less than 1% error after 5 * R * C (seconds)Needless to say, the both bandwidth and sampling rate sucks. But this is often OK with signals like battery voltage or temperature. The cost and the area of the solution are excellent.There are two different kinds of impedance requirements here: the low impedance required to drive the ADC pin during that short sampling period - this is often just a few tens of ohms!; and the higher impedance required to satisfy theaverageinput current consumption of the ADC, which depends on the duty cycle of sampling. The 100n cap satisfies the former; the impedance of the resistor divider only needs to satisfy the latter. If you remove the 100n capacitor, then the resistor divider network needs to satisfy both.For high-bandwidth, or high sampling rate applications, you want to drive the ADC with an opamp.

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2020, 10:39:23 am
content: Err.... That's all correct in principle but lets put the correct figures in place. First see PIC16F887 datasheet FIGURE 9-4: ANALOG INPUT MODEL, which gives Chold as 10pF. For less than 1/2 LSB worst case shift during sampling, I believe you need*an external capacitor at the pin >Chold*2(N+1), which for a 10 bit ADC and a 10pF Chold, is >204.8nF. Nearest preferred value is 220nF.* Unless you can give me proof that the the initial voltage on Chold is always close to 1/2 Vcc, I must assume that worst case, its fully charged or discharged.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 16, 2020, 11:02:05 am
content: You added +1 to the exponent because you specified the max error as 0.5LSB. I specified it (implicitly) at 1LSB. For such a 10-bit converter where the ENOB is likely around 9 bits, I agree with your choice of 0.5LSB. OTOH, for example, with a 16-bit integrated cheap MCU ADC with 13 bits of ENOB, I wouldn't start thinking about designing anything external to satisfy 0.5LSB condition (but maybe 4 LSBs instead, so Chold*2^14).That worst case assumption is fair in systems with multiplexed ADCs where the previous sample may have been from a source near the opposite rail than the input we are sampling currently. Yes, I have seen a system which works fine and is accurate enough, until the code is changed to read another input between. And now the inputs are cross-correlating.Yes, the required C value can be quite large; luckily large-value MLCCs are small and cheap (and there isn't a lot of loss of C due to the nonlinearity of the dielectric at the typical ADC input ranges).This is funny because when I have specified 100nF bare minimum in a few occasions, I have been aggressively corrected that this is way too excessive, that 10nF or less is definitely enough, on this forum. People like to handwave stuff without thinking about it. Yes you need to calculate it.

author: Circlotron
author_rank: Super Contributor
timestamp: March 16, 2020, 11:17:03 am
content: Make sure you switch the A/D input channel selector to the required channel, quickly take the reading, then switch it straight back to an unused channel. If you leave it constantly on the used channel, in some micros at least, it will somewhat discharge that capacitor across the input.

author: wraper
author_rank: Unknown
timestamp: March 16, 2020, 11:26:22 am
content: Quote from: Siwastaja on March 16, 2020, 11:02:05 amI have circuit where I switch ADC to GND between sampling different inputs to avoid exactly this.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 16, 2020, 11:40:03 am
content: Quote from: wraper on March 16, 2020, 11:26:22 amYeah, and I once had a case where I had a proper low impedance input A (buffered by a high-speed opamp), and high-impedance input B, and I couldn't either buffer/filter the input B (physical impossibility: it's an internal CPU temperature sensor, and they pitched a few pennies by omitting the buffer, "the programmer can always select a super long sampling time"), or use a long sampling time because I needed good sampling rates for the other signals muxed to that ADC (particularly input A). And that system couldn't shut down the normal operation periodically to sample input B sloooowly.So I had to calculate (with unit-to-unit calibration measurement) a correlation factor A -> B, so that I can calculate the "correct" B by knowing A and the distorted B. In order not to eliminate, but reduce the huge amount of correlated error. Tcpu is an approximation anyway, so if the error could be reduced from 50 degC to maybe 10 degC, it would be worth it.And the system had an automated calibration step anyway, so this correlation factor could be calibrated at the same time with zero extra cost.Sampling GND inbetween would make the math a bit simpler, now the distrubtive signal would be a constant zero value.Did I get this working properly? I don't remember.

author: iMo
author_rank: Super Contributor
timestamp: March 16, 2020, 12:29:19 pm
content: The ADC in pic16f887 works such it disconnects the S/H capacitor C_hold=10pF during the ADC conversion only, otherwise it is always connected to the selected input.Also the internal charging/discharging S/H resistor R_ss is 5-11k (+R_ic) according to the datasheet (see below).On page 107 are the equations you need to consider when messing with source internal impedance Rs.

author: TomS_
author_rank: Frequent Contributor
timestamp: March 16, 2020, 09:32:53 pm
content: Thanks for all of your replies. Have some modifications to make to my design now: will remove R10 as that seems to be a popular mention, and also look into whether the 100nF cap should be any bigger.(I've seen a page in the datasheet full of equations which makes my head spin a bit)For monitoring the battery I'll do some homework (RC calcs etc) to figure out what kind of values I can use to keep the cap charged up minute to minute while drawing hopefully only some uA. Could also look at reducing the sample interval on that too as minute by minute might be a bit over the top, or at least average it out over some longer period.Application wise, some more detail: Although the PICs ADC is 10 bits, I'm choosing to ignore the two LSb for the sake of simplicity - easier to work with an 8 bit value, and I don't actually think I need those two extra bits of accuracy anyway. Im really only need a ballpark voltage to make a simple decision about whether something is getting too low, or if it's high enough.So Im looking to left justify my ADC result and take the value from the H register only.That said I would still like to implement the hardware side "correctly" as it would likely serve as a reference/inspiration for future designs.

author: rstofer
author_rank: Super Contributor
timestamp: March 17, 2020, 03:36:24 pm
content: Resolution may be important and it is sometimes necessary to map, say, 18V..28V to a 0V..5V ADC while still providing a low driving impedance.Chapter 4 of "Op Amps For Everyone" deals with this very issue:https://web.mit.edu/6.101/www/reference/op_amps_everyone.pdfDone badly, each bit represents too large of a change in voltage and many bits are used for useless information (like, say, 10V in a system that can't physically have a voltage that low).The solution probably takes one op amp and 4 resistors and provides very low driving impedance.

author: RandallMcRee
author_rank: Frequent Contributor
timestamp: March 17, 2020, 04:44:29 pm
content: Quote from: rstofer on March 17, 2020, 03:36:24 pmYes, good reference. I took a look and I think you might meanChapter 12particularly Figure 12-14. Very nice step-by-step. More real-life.Thanks,Randall

author: TomS_
author_rank: Frequent Contributor
timestamp: March 17, 2020, 09:35:57 pm
content: I don't quite understand so you'll have to excuse my ignorance, but by adding an opamp, what would I be gaining?As far as I *do* understand, with the 8 MSb's of the ADC result I can see the voltage to roughly 0.11V resolution (28V / 256), which I felt was going to be accurate enough for what I'm trying to achieve.

author: thm_w
author_rank: Super Contributor
timestamp: March 17, 2020, 09:50:12 pm
content: Quote from: TomS_ on March 17, 2020, 09:35:57 pmThey are suggesting, if you were say measuring only 20-28V then an opamp would be of use, but you are 0-28V. Its not relevant to your use case, so you don't gain anything here.What you understand is correct.

author: TomS_
author_rank: Frequent Contributor
timestamp: March 17, 2020, 10:54:46 pm
content: Ah ha. I should probably stop reading stuff like this in bed just after I wake up. I see what rstofer was getting at now.

author: rstofer
author_rank: Super Contributor
timestamp: March 17, 2020, 11:42:50 pm
content: Quote from: RandallMcRee on March 17, 2020, 04:44:29 pmNo, I meant section 4.3 specifically for the y=mx+b stuff. The fact that this chapter uses single power supply op amps makes it particularly useful for microcontroller projects.

author: rstofer
author_rank: Super Contributor
timestamp: March 17, 2020, 11:46:46 pm
content: Quote from: TomS_ on March 17, 2020, 09:35:57 pmIf you need to measure the entire range from 0V to 28V then nothing is gained except that an op amp has very low output impedance which is kind of handy when dealing with uC ADCs. You said you wanted to limit the divider current yet you still have to get to a low driving impedance. Whether it is better to use appropriately sized resistors by themselves or higher value resistors with a micropower op amp is a design decision.QuoteThat is correct if you need to map all the way down to 0V and as long as 0.11V resolution is adequate and it very likely is.

author: NorthGuy
author_rank: Super Contributor
timestamp: March 18, 2020, 12:32:53 am
content: If you wanted to use R10 for safety, consider replacing R8 with two or more resistors in series giving the same combined value (say two 5K resistors instead of 10K). Then, if one of them shorts, the other(s) will protect the MCU.

author: iMo
author_rank: Super Contributor
timestamp: March 18, 2020, 08:20:18 am
content: In case you are looking for a low impedance divider with "zero current" when not active - see below.The Pmos is switched on via an 1->0 pulse edge on the ENABLE_DIV signal (ie PIC16F output pin).Then you have some time (given by R3C1 time constant) to measure the Battery voltage via your ADC_INPUT.PS: adjust the divider ratio R1/R2 based on your voltage range. Also the Pmos' Max Vds should be considered as well.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 18, 2020, 11:27:30 am
content: Quote from: rstofer on March 17, 2020, 03:36:24 pmSuch measures were more regularly needed when ADCs were still expensive, but precision opamps were already commonplace, i.e., 1980's and 1990's.Now, ADCs are so cheap that if you require 13-bit actual accuracy, it's just way easier and cheaper to use a 16-bit ADC with unmatched range, than to design and build an opamp circuit which adds just the right offset and gain to get the same end result with a 12-bit ADC. To actually get the accuracy, you need to consider opamp offset voltages, possibly bias currents, and resistor tolerances; while a simple ADC brings you the DC accuracy no problem.The idea about "wasting" the ADC range is a feeling, not engineering. Make the choice based on the simplicity, area, part count, cost, and of course, the ability to perform to the required spec - and your design ability to make sure it performs as you expect.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: March 19, 2020, 11:36:24 pm
content: A fun and educational experiment:Put your uC on a breadboard and put a relatively "big" capacitor on one of it's ADC inputs. 100nF will do.Write a simple program to sample the ADC at 10Hz or so and output the value to a LCD, serial port or whatever is available.Momentarily charge the capacitor with some external voltage (A potentiometer between GND and Vcc will do), and when the capacitor is charged, remove the connection between between the capacitor and the voltage source. The uC keeps on sampling a single channel of the ADC.What happens? You are likely to see a pretty low drift on the capacitor voltage which suggests a high input impedance.Now connect another potentiometer to another ADC input channel, and modify your program to read both ADC channels.What do you think will happen?It's likely that the sampling capacitor inside the uC is charged each time to the voltage from the potentiometer.The ADC input connected to the capacitor is likely to drift towards the voltage of the other channel, because part of the charge of the sampling capacitor is transferred to or from the "big" 100nF capacitor.Next experiment:Put an opamp with Fet inputs (as a simple buffer) in between the 100nF capacitor and the input of the ADC, and repeat both experiments.Next experiment:Charge the capacitor to some voltage, and let it sit on the breadboard for some hours.What sort of drift do you see?What happens when you touch the thing?

author: TomS_
author_rank: Frequent Contributor
timestamp: March 21, 2020, 01:57:29 am
content: Quote from: NorthGuy on March 18, 2020, 12:32:53 amThats a good suggestion. Ive seen things like that done a few times, e.g. in multimeters where they put a lot of resistors in series.But if a resistor was going to blow, would it fail short or open? I suppose most that I have seen tend to fail open.If it were to fail short it would change the ratio of the divider, and with only one of the 5K resistors that would increase the output of the divider to around 8V. That most likely exceeds the abs max voltage for a pin, so in a case like that wouldnt I still blow my PIC?That said, the current would still be limited to around 5-6mA by the remaining 5K resistor, so maybe it would be ok... Readings would all be thrown off, but perhaps I could add some failure detection, since I dont expect the voltage to get anywhere near the top of the range, anything above a certain value could be considered an error and I could simply refuse to do anything at that point, or disregard the readings.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 21, 2020, 11:00:26 am
content: Resistors are put in series to increase the voltage rating (also, to share power dissipation over larger area).The circuit isn't safe for high voltages (exceeding the typical 100-200V rating of small SMD resistors) anyway, because the current through the protection diodes would be too much, unless you increase the value of R significantly. Hence, putting many in series has no benefits, and I fail to see the idea behind such suggestion.Resistors don't just blow for no reason.

author: NorthGuy
author_rank: Super Contributor
timestamp: March 21, 2020, 02:29:27 pm
content: Quote from: TomS_ on March 21, 2020, 01:57:29 amI don't know. I don't think they blow. I've seen few failed open. I haven't seen any failed short. You should ask people who do repairs.Quote from: TomS_ on March 21, 2020, 01:57:29 amI don't think so.After you remove R10, the input resistance will decrease. Then you can increase the values of the resistors forming the divider. This will make the input impedance the same as it was before R10 removal.