Would you like to be notified by email when Jason Sachs publishes a new blog?
Imagine the following scenario:
You're a successful engineer (sounds nice, doesn't it!) working on a project with three or four circuit boards. More than even you can handle, so you give one of them over to your coworker Wayne to design. Wayne graduated two years ago from college. He's smart, he's a quick learner, and he's really fast at designing schematics and laying out circuit boards. It's just that sometimes he takes some shortcuts... but in this case the circuit board is just something to digitize some thermistor measurements -- he says he's putting on a microcontroller with a built-in analog-to-digital converter, which will then send the measurements to the rest of the system via a CAN bus. What could go wrong?
Three weeks later the prototypes for Wayne's board are fully assembled and ready to test. You drop by that afternoon to see how things are going.
"Well, I've got two ADC channels for thermistors, and a third one sensing 1.8V. It works fine," he says, "except... well, it's the funniest thing. I heat up one channel's input from 0 degrees C to 100 degrees C, and the measurements are what I expect... but the other channel increases in temperature by about 10 degrees."
You offer to give him a hand, but he says he'll come see you after he does some more investigating.
Later he drops by. "I don't get it," he says. "The first channel affects the second one, but then I heated up the second channel's input from 0 degrees C to 100 degrees C, and it doesn't affect the first. But they're the same circuit!"
Here's the relevant part of Wayne's design (a third channel AIN2 sensing a voltage is not shown):
What's going on?
Well, the first thing to know is what the analog-to-digital converter looks like electrically. Most multichannel sampling ADCs are really just a combination of an analog multiplexer, a small sample-and-hold capacitor, and one ADC. They connect the capacitor to the selected input channel for a brief period of time (the sampling time), and then connect the capacitor to the ADC to digitize the capacitor voltage (the conversion time).
The sampling capacitor sees different voltages from one channel to the next, and during its sampling time, the capacitor has to charge/discharge from its previous voltage to the voltage it's supposed to have. So there's a certain maximum source impedance you have to provide to the ADC. If you use a high-resistance voltage divider, at the end of the sampling time, the capacitor will not completely charge to the voltage you intended, and instead, it will retain a voltage that is influenced by its previous voltage.
Let's throw some numbers here.
Suppose the sampling capacitor is 10pF, your voltage divider has 100K output impedance, and the sampling time is 1usec. The RC time constant in the sampling capacitor is 1usec. The important calculation here is K = e-T/RC which in this case is K = 0.368. The voltage seen at the end of the sampling time = (K * previous voltage) + (1-K) * intended voltage -- you're measuring 63.2% of the voltage you intended, and 36.8% of the old voltage.
If you can increase the sampling time, you can alleviate this situation. For T = 2usec, K = 13.5%, so that's still a lot. You generally want to make sure that K is less than 1/2 LSB of the ADC, so that the effect is minimal. For a 10-bit ADC, that translates into T = about 7.6*tau. (12-bit: 9tau; 8-bit: 6.2tau; 14-bit: 10.4tau; 16-bit: 11.8tau)
That's one way to solve the problem. The other way is to use an external capacitor as a charge reservoir.
Suppose you have a capacitor C1 charged to a voltage V1, and you have a capacitor C2 charged to a voltage V2, and you connect the two in parallel. What's the voltage Vfinal after you connect them?
Well, you have a total charge Q = C1*V1+C2*V2, and a net capacitance Cfinal = C1 + C2, so Vfinal = Q/Cfinal = (C1*V1+C2*V2)/(C1+C2).
Again, let's throw in some numbers.
The sampling capacitor is C1=10pF, and it's at V1 = 1V. An external capacitor C2 = 0.01uF = 10000pF is at 0V. The end voltage is (10pf*1V)/(10pF+10000pF) = 1mV. Connecting a small sampling capacitor to an external capacitor that is 1000 times larger will change the external capacitor's voltage by 1/1000 of the difference between the initial voltages. (This is true in general for any ratio K that's much larger than 1.)
The upside of this approach is that the external capacitor automatically charges up the sampling capacitor and is barely affected by the switching transient. The downside is that the time constant for it to recharge to its original value is much longer: the voltage divider still has 100K output impedance, but now C = 0.01uF so tau = 1 millisecond.
For this approach to work, you have to make sure the charge reservoir capacitor is large enough so that the transient caused by its connection to the sampling capacitor is small, usually less than 1/2LSB of the ADC. For a 10-bit ADC, that means the external capacitor should be 2048 times larger than the sampling capacitor (for 12-bit the ratio is 8192, for 14-bit, 32768, and for 16-bit, 131072).
With a large external charge reservoir capacitor, you can use short sampling times.
After a discussion with Wayne on the subject, he decides to add a charge reservoir capacitor, and goes back to the lab to try it. An hour later he comes back.
"I put a 0.1uF capacitor across each of the ADC inputs, and that helped somewhat, but it still has the same problem; the second measurement gets affected slightly by the first one."
"What sample rate are you using?" you ask. "Not the sample rate between samples, but the rate at which you repeat sampling the entire sequence of channels."
"10kHz," he says.
"Aha, there's your problem."
Let's look at the sampling capacitor again. Suppose the ADC runs from 0 to Vref, and one channel is at V1 and the next one is at V2. The capacitor needs to be charged up by its input; the electrical charge Q transferred = C*(V2-V1), where C is the sampling capacitance. This happens not just once but every time it is sampled; if the sampling frequency is f, then the rate at which charge is transfered is C*deltaV*f. This is a current, that presents itself as impulses or "gulps" of charge C*deltaV, but the average current is C*deltaV*f. This is true no matter what external capacitor is used.
When the circuit driving the sampling capacitor is a voltage divider with output resistance R, then the voltage divider's output node sees an average voltage drop of R times this current, or R*C*deltaV*f.
Without an external capacitor, this happens only during the switching transient, and if you wait the 8-12 time constants until the voltage settles back down, then you see the proper voltage. But if you add an external capacitor to keep the transients small, then it low-pass filters the voltage and there's no way to avoid the voltage drop -- which is proportional to the voltage difference between channels, so it is unpredictable and time-varying.
Again, some numbers:
C = 10pF, deltaV = 3V, R = 100K, f = 10kHz. The average voltage drop is 0.03V, or deltaV * 1%.
This amount is higher (and therefore worse) when the sampling capacitance is higher, or the external impedance is higher, or the repeat rate is faster.
Fast sampling is your enemy here. If you want to use high-impedance voltage sources with an ADC, you have to either avoid external capacitance and use long sampling times to wait for the sampling capacitor to settle, or use external capacitance intentionally but avoid fast sampling repeat rates. (High impedance voltage sources are bad for another reason: ADCs usually specify their input leakage current, which is separate from this charge-transferring current, but it also can cause a voltage drop.)
You discuss this with Wayne.
"So I have to put an op-amp to buffer the voltage?" he asks.
"Well, basically, yes, if you want to sample fast, that is. You could sample more slowly, you know."
"Yeah, but I want to do oversampling and filtering in software. Besides, it sounds like I should probably have the op-amp in there anyway."
"Good thinking. There's one more problem you should know about, though...."
So you buffer your voltage divider with an op-amp and connect that to the ADC input. The problem with op-amps is that they like to see "nice" (i.e. resistive) electrical loads, and if you whack their output by connecting and disconnecting a capacitor, there's not really a good guarantee of how long the op-amp will settle down to a buffered version of the voltage divider. Remember, the sampling capacitor wants a fast gulp of charge. For example, if you want a 1 microsecond settling time, and the sampling capacitor is 10pf, and needs to change from 0V to 3V, then the current during this period is Q/T = CV/T = 30uA. That's not that much for the op-amp to deliver, but the dynamics need to be fast and aren't specified in op-amp datasheets -- they typically spec what happens when you put voltage transients on the op-amp input, which is a completely different situation from a fast change in output load. In any case, for a 1 microsecond settling time you'll need more than a 1MHz gain-bandwidth op-amp, probably one in the 10-20MHz range at least.
The best way to deal with this is to put a simple RC filter on the op-amp output. Pick an R and C so that by the end of the sampling period, the sampling capacitor has settled to within 1/2 an LSB of its final value. But you also need to make sure there's enough resistance R so that the op-amp is stable. Many op-amps aren't stable with excessive capacitive loads. I usually find that something around R = 499 ohms, C = 470pF will work fine. That creates a time constant of about a quarter-microsecond, and adds enough external capacitance so that it delivers most of the charge needed by the sampling capacitor, and keeps the op-amp from having to do so. And *please* remember when you get to circuit board layout to place the external capacitance as close as possible to the ADC.
This is a trade-off for driving ADC inputs: if you want the time between sampling input channels to be very short (i.e. finish an ADC sampling sequence quickly), you have to add a buffer and an RC filter on the ADC input. If you don't want to have to go to the trouble to do so, you can't expect to sample at a fast rate, and you need to do the analysis to make sure you're not introducing cross-coupling from one channel to another.
Add a Comment