The puzzle
A thermistor divider reads correctly when the board runs from USB and 2 °C off on battery. A second sensor, a 100 kΩ divider, reads correctly alone but is pulled toward the neighbouring channel’s voltage when both are sampled in turn. Neither is noise. What are the ADC’s reference and input really doing?
STEP 1
The reference is the ruler
Every code is a fraction of the reference: Vin = code × Vref / 2^N. A reference 1 % high makes every reading 1 % low. Microcontroller ADCs often use the analog supply (for the RP2040 examples, “ADC_VREF == 3.3 V”) or an internal reference, sometimes selectable per channel, as Zephyr’s ADC API shows. A supply-derived reference carries the supply’s tolerance, ripple and load-dependent drops into every measurement.
STEP 2
Ratiometric measurement
A resistive sensor in a divider produces a voltage proportional to the voltage feeding it. If the divider is fed from the same voltage the ADC uses as its reference, both scale together and cancel:
Potentiometers, thermistors and strain gauges are best measured this way. An absolute voltage, such as a battery or a sensor with its own output stage, needs an accurate reference instead.
A resistive sensor in a divider gives a voltage proportional to its supply. If the divider and the ADC reference are the same voltage, the code depends only on the resistor ratio: supply changes cancel. Feed the divider from a different supply, or measure an absolute voltage, and every change in the reference becomes a reading error.
STEP 3
How the input is sampled
A successive-approximation (SAR) ADC, like those in most microcontrollers, first connects the input to a small sampling capacitor through an internal switch for the sampling (acquisition) time, then disconnects it and converts the stored charge. During acquisition the capacitor charges through the source resistance plus the switch resistance, an RC circuit. If it starts from a different voltage, for example the previous channel’s, the error decays as
and, for a full-scale step (ΔV = Vref, the worst case), falls below half an LSB of an N-bit converter after
STEP 4
High-impedance sources
When the source is too resistive for the available sampling time:
- lengthen the sampling time, if the converter allows it (STM32F4 channels choose from 3 to 480 ADC clock cycles) and the sample rate can afford it;
- buffer the source with an op-amp follower, which presents a low output impedance to the ADC;
- add a reservoir capacitor at the ADC pin, much larger than the sampling capacitor, which supplies the charge; the divider then has to recharge it between samples, so the source must be slow or the sample rate low.
Internal channels (temperature sensors, internal references) often need a minimum sampling time from the datasheet; ST’s HAL gives the rough order as 4 µs.
STEP 5
Worked example: sampling the 10 kΩ divider
Take a source resistance of 10 kΩ, an illustrative 1 kΩ switch and 10 pF sampling capacitor: τ = 11 kΩ × 10 pF = 110 ns, and settling within ½ LSB at 12 bits needs 9.0 × 110 ns ≈ 0.99 µs. With a 21 MHz ADC clock, 15 cycles give 714 ns: only 6.5 τ, leaving about 6 LSB of a full-scale step unsettled. 28 cycles give 1.33 µs, enough. The conversion then takes 28 + 12 = 40 cycles, 1.9 µs, so the channel can be sampled at up to about 525 kS/s.
MYTHS AND FACTS
Common misconceptions
The reference is exactly 3.3 V
It is whatever the supply or reference actually delivers, with its tolerance and noise.
ADC inputs draw no current
They draw charging current pulses at every sample; averaged, that looks like a load resistance.
A higher resistance divider saves power at no cost
It lengthens the acquisition time and raises noise pick-up.
A capacitor at the input fixes everything
It provides the sampling charge but slows the input’s response to real changes.
Check yourself
Answer in your head, then open the card.
A potentiometer is fed from 3.3 V and read by an ADC whose reference is the same 3.3 V rail. The rail drops to 3.1 V. How much does the reading change?
Not at all (to within an LSB): the input and the reference drop together, so the code depends only on the wiper position.
With τ = 50 ns, how long must the acquisition be for ½ LSB at 10 bits?
ln(2^11) ≈ 7.6: t ≥ 7.6 × 50 ns ≈ 0.38 µs.
Why can a high-impedance channel read the voltage of the channel sampled just before it?
The sampling capacitor still holds the previous channel’s voltage; with too little acquisition time it cannot charge to the new input, so the reading lies between the two.
An STM32F4 ADC runs at 36 MHz and a channel uses 56 sampling cycles at 12 bits. What is its conversion time?
(56 + 12) / 36 MHz ≈ 1.89 µs.
Sources (3)
- STMicroelectronics, stm32f4xx-hal-driver, Inc/stm32f4xx_hal_adc.h — ADC_SAMPLETIME_3CYCLES … 15, 28, 56, 84, 112, 144, 480CYCLES; SamplingTime “Unit: ADC clock cycles”; “Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits …)”; internal channels need their datasheet minimum sampling time (“values rough order: 4us min”)
- Zephyr Project, include/zephyr/drivers/adc.h — struct adc_channel_cfg: reference (ADC_REF_VDD_1, VDD/2 … ADC_REF_INTERNAL, ADC_REF_EXTERNAL0/1) and acquisition_time, set with ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 20) or ADC_ACQ_TIME_DEFAULT: the reference and the acquisition time are per-channel choices
- Raspberry Pi Ltd, pico-examples, adc/onboard_temperature/onboard_temperature.c — “12-bit conversion, assume max value == ADC_VREF == 3.3 V”; conversionFactor = 3.3f / (1 << 12); T = 27 − (V − 0.706)/0.001721