Author Topic: ADC input impedance  (Read 17324 times)

0 Members and 1 Guest are viewing this topic.

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
ADC input impedance
« on: March 15, 2020, 11:55:25 pm »
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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 19537
  • Country: lv
Re: ADC input impedance
« Reply #1 on: March 16, 2020, 12:10:56 am »
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.
 
The following users thanked this post: TomS_

Online wraper

  • Supporter
  • ****
  • Posts: 19537
  • Country: lv
Re: ADC input impedance
« Reply #2 on: March 16, 2020, 12:17:49 am »
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.
Completely 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.
 
The following users thanked this post: TomS_

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: ADC input impedance
« Reply #3 on: March 16, 2020, 12:40:55 am »
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.  ;D
 

Online hesam.moshiri

  • Regular Contributor
  • *
  • Posts: 212
  • Country: se
    • MyVanitar
Re: ADC input impedance
« Reply #4 on: March 16, 2020, 09:21:33 am »
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  ;)
 
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 11497
  • Country: fi
Re: ADC input impedance
« Reply #5 on: March 16, 2020, 10:01:37 am »
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 of increasing the 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 still finally charge 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 sample again - 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 the average input 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.
« Last Edit: March 16, 2020, 10:07:16 am by Siwastaja »
 
The following users thanked this post: thm_w, ajb, TomS_

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14140
Re: ADC input impedance
« Reply #6 on: March 16, 2020, 10:39:23 am »
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.
« Last Edit: March 16, 2020, 10:45:16 am by Ian.M »
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 11497
  • Country: fi
Re: ADC input impedance
« Reply #7 on: March 16, 2020, 11:02:05 am »
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.
 
The following users thanked this post: ajb, Ian.M

Offline Circlotron

  • Super Contributor
  • ***
  • Posts: 3569
  • Country: au
Re: ADC input impedance
« Reply #8 on: March 16, 2020, 11:17:03 am »
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.
 
The following users thanked this post: TomS_

Online wraper

  • Supporter
  • ****
  • Posts: 19537
  • Country: lv
Re: ADC input impedance
« Reply #9 on: March 16, 2020, 11:26:22 am »
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.
I have circuit where I switch ADC to GND between sampling different inputs to avoid exactly this.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 11497
  • Country: fi
Re: ADC input impedance
« Reply #10 on: March 16, 2020, 11:40:03 am »
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.
I have circuit where I switch ADC to GND between sampling different inputs to avoid exactly this.

Yeah, 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  |O.
« Last Edit: March 16, 2020, 11:43:19 am by Siwastaja »
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 7004
  • Country: nr
Re: ADC input impedance
« Reply #11 on: March 16, 2020, 12:29:19 pm »
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.
« Last Edit: March 16, 2020, 12:31:38 pm by imo »
Readers discretion is advised..
 
The following users thanked this post: wraper

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: ADC input impedance
« Reply #12 on: March 16, 2020, 09:32:53 pm »
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.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 10095
  • Country: us
Re: ADC input impedance
« Reply #13 on: March 17, 2020, 03:36:24 pm »
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.pdf

Done 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.
 

Offline RandallMcRee

  • Frequent Contributor
  • **
  • Posts: 550
  • Country: us
Re: ADC input impedance
« Reply #14 on: March 17, 2020, 04:44:29 pm »
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.pdf

Done 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.

Yes, good reference. I took a look and I think you might mean Chapter 12 particularly Figure 12-14. Very nice step-by-step. More real-life.

Thanks,
Randall
 

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: ADC input impedance
« Reply #15 on: March 17, 2020, 09:35:57 pm »
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.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 9952
  • Country: ca
  • Non-expert
Re: ADC input impedance
« Reply #16 on: March 17, 2020, 09:50:12 pm »
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.

They 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.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 
The following users thanked this post: TomS_

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: ADC input impedance
« Reply #17 on: March 17, 2020, 10:54:46 pm »
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. :-DD
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 10095
  • Country: us
Re: ADC input impedance
« Reply #18 on: March 17, 2020, 11:42:50 pm »
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.pdf

Done 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.

Yes, good reference. I took a look and I think you might mean Chapter 12 particularly Figure 12-14. Very nice step-by-step. More real-life.

Thanks,
Randall

No, 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.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 10095
  • Country: us
Re: ADC input impedance
« Reply #19 on: March 17, 2020, 11:46:46 pm »
I don't quite understand so you'll have to excuse my ignorance, but by adding an opamp, what would I be gaining?
If 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.
Quote
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.
That 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.
 
The following users thanked this post: TomS_

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3597
  • Country: ca
Re: ADC input impedance
« Reply #20 on: March 18, 2020, 12:32:53 am »
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.
 
The following users thanked this post: TomS_

Offline iMo

  • Super Contributor
  • ***
  • Posts: 7004
  • Country: nr
Re: ADC input impedance
« Reply #21 on: March 18, 2020, 08:20:18 am »
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.
« Last Edit: March 18, 2020, 09:07:17 am by imo »
Readers discretion is advised..
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 11497
  • Country: fi
Re: ADC input impedance
« Reply #22 on: March 18, 2020, 11:27:30 am »
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.
..
Done 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).

Such 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.
« Last Edit: March 18, 2020, 11:34:06 am by Siwastaja »
 
The following users thanked this post: thm_w

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5404
  • Country: nl
Re: ADC input impedance
« Reply #23 on: March 19, 2020, 11:36:24 pm »
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?
 

Offline TomS_Topic starter

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: ADC input impedance
« Reply #24 on: March 21, 2020, 01:57:29 am »
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.

Thats 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->