Embedded HandbookApps
All sections › XXI. Analog building blocks
STM32F103, STM32F407, STM32G431, STM32L431 · level intermediate · 7 min read
Open in the interactive handbook

180. The analog path around the ADC: sampling capacitor, buffer, multiplexer, driver

Section 50.6 explained why the ADC input needs a capacitor, and section 14 how the converter itself works. Here we look at what happens in the first few hundred nanoseconds after the ADC closes its sampling switch, and why a high-impedance sensor must not be connected straight to the input.

The numbers below come from an ngspice model: sampling capacitor 5 pF, switch resistance 1 kΩ, sampling time 200 ns, a 2.0 V source with 10 kΩ resistance; before the switch closes, the sampling capacitor holds 1.0 V from the previous measurement.

Terms used in the documentation

Term Meaning
sample and hold (S&H) the circuit that samples the input and holds it during conversion
sampling capacitor (CADC) the capacitor inside the ADC that takes the sample
sampling time / acquisition time how long the switch stays closed to charge it
input impedance / source impedance the impedance of the input / of whatever drives it
ADC driver the amplifier stage that drives the ADC input
charge injection / kickback the charge spike at the input when the switch closes
multiplexer channel crosstalk one channel leaking into the next
settling to N bits settling until the error is below N-bit resolution
reconstruction filter the filter that smooths the DAC output steps

180.1 What happens during sampling

Inside the ADC a switch connects the sampling capacitor to the input. The capacitor still holds the charge from the previous measurement, and within the sampling time it has to charge to the new voltage through the source and switch resistance. The time constant is (Rsrc + Rsw) · Cs = (10 kΩ + 1 kΩ) · 5 pF = 55 ns; to settle to 12 bits it takes ln 2¹³ ≈ 9 time constants, that is 496 ns. The sampling lasts 200 ns:

What drives the ADC After 200 ns Error In codes
10 kΩ source directly 1.973 V −26.6 mV 33
source plus 100 nF at the input 1.99995 V −0.05 mV 0.06
op-amp buffer 2.00001 V +0.01 mV 0
buffer, 100 Ω and 1 nF 1.99921 V −0.79 mV 1

ADC input equivalent during sampling: 10 kΩ source, 1 kΩ switch and 5 pF sampling capacitor — time constant 55 ns

After 50 ns the difference is even clearer: straight from the source the capacitor holds 1.594 V instead of 2.0 — there is nothing to measure yet — while with the buffer it is already 2.000 V.

Voltage on the sampling capacitor after the switch closes


180.2 A capacitor at the input or a buffer

A 100 nF capacitor at the input works as a local charge reservoir: the sampling capacitor is 20000 times smaller, and recharging it pulls the capacitor down by only 0.05 mV. It is cheap and needs no amplifier — but it has a price:

A buffer solves both problems: it keeps a low output impedance both for DC and for a fast signal. A typical ADC driver is a buffer, followed by a 100 Ω isolation resistor and a 1 nF capacitor right at the input: the resistor isolates the capacitance from the amplifier output (section 163.3), and the capacitor supplies the charge to the sampling capacitor. In the model this driver gives an error of 0.79 mV — one code.

ADC driver: buffer, isolation resistor and capacitor at the input


180.3 Multiplexer: the neighbouring channel catches up

A microcontroller has one ADC for many channels: an internal multiplexer switches the input. What stays charged from the previous channel is the capacitance behind the multiplexer. For the internal one that is the sampling capacitor and the switch itself — a few picofarads, while the trace and protection at each pin are separate and charged by their own signal. If several sensors share one ADC pin through an external multiplexer, the common node also carries the trace, the protection and the capacitance of the multiplexer chip itself — 20 pF in the model. We switch such a multiplexer from a 3.0 V channel to a 0.5 V channel with 10 kΩ sources:

Time after switching Voltage at the ADC input Error in codes
200 ns 1.431 V 1155
400 ns 0.846 V 429
1 µs 0.518 V 22
2 µs 0.500 V 0.1

External multiplexer: the 20 pF common node at the ADC pin recharges through the 10 kΩ source and a 100 Ω switch

The time constant here is (10 kΩ + 100 Ω) · 20 pF = 202 ns, and after switching you have to wait the same nine time constants. If you don't, the neighbouring channel "shows through" into the measurement — on a large step that is hundreds of codes. There are three cures: increase the sampling time in the ADC settings, lower the source impedance (a buffer), or measure each channel twice and keep the second value.

ADC input after a channel switch: the neighbouring channel does not go away at once


180.4 Source impedance: what the documentation says

The microcontroller documentation has a "maximum source impedance" table for each sampling time. Its meaning is the same as in 180.1, only the margin is stricter: the documentation uses ln 2^(N+2) — for 12 bits that is 9.7 time constants (settling to a quarter of a code), not 9: 9.7 · (Rsrc + Rsw) · Cs must fit into the sampling time. The practical conclusions:


180.5 At the DAC output — the same thing in reverse

The DAC also has resistors inside. The STM32 DAC has its own output buffer (section 15.3): with it the output drives loads from 5 kΩ, but does not reach the rails by about 0.2 V; without it the output impedance is up to 15 kΩ, and for 1 % accuracy the load must be 1.5 MΩ or more. An external buffer is added for a heavier load or for a signal that starts right at ground, and after it, if the signal is stepped, comes a reconstruction filter (section 178) that smooths the steps up to the update rate. PWM with an RC from section 50.5 is the same trick in a cheaper form.


180.6 Pitfalls

ADC readings are low and depend on the previous channel. Not enough sampling time: in the model with an external multiplexer, 200 ns after switching the input is at 1.431 V instead of 0.5.

A high-impedance sensor gives low codes. The source impedance is higher than allowed for the chosen sampling time — use a buffer.

After adding a 100 nF capacitor the signal became "blunt". The time constant with a 10 kΩ source is 1 ms; a fast signal needs a buffer.

The op-amp driver oscillates with the capacitance at the input. The isolation resistor is missing (section 163.3).

The DAC is wrong under load. The DAC output has its own impedance — it needs a buffer.


180.7 Summary

Next: section 181 "Analog layout: common ground, interference, shielding".

Open in the interactive handbook