ADCs Explained: Resolution, Reference Voltage, Sampling Rate, and Why Your Readings Drift
An analog-to-digital converter measures a ratio, not a voltage. Here is how resolution, the reference, sampling rate, and source impedance decide whether a microcontroller reading means anything, with a worked battery-monitor example.
Almost every embedded project eventually needs to read something analog: a battery voltage, a potentiometer, a thermistor, a light sensor, a microphone. The analog-to-digital converter (ADC) built into the microcontroller turns that voltage into a number, and the API makes it look trivial: call one function, get an integer. The trouble is that the integer depends on more than the voltage on the pin. The reference voltage, the sampling rate, the impedance of whatever drives the pin, and the converter's own errors all leak into the result. Understanding those four factors is the difference between a reading you can trust and one that wanders whenever the USB cable is swapped.
An ADC measures a ratio, not a voltage
A converter does not know what a volt is. It compares the input against a reference voltage and reports where the input falls between zero and that reference. Microchip's ATmega328P datasheet, for the chip inside the Arduino Uno, states the single-ended result directly: the code equals the input voltage multiplied by 1024 and divided by the reference voltage. A code of 0 represents ground, and the top code of 1023 represents the reference minus one step.
That one formula explains most surprises. If the reference moves, every reading moves with it, even when the input is perfectly steady. Converting a code back into volts is only as accurate as the reference value used in that conversion, so the reference deserves as much attention as the input itself.
Resolution and the size of one step
Resolution is the number of bits in the output. An N-bit converter divides the reference range into 2 to the power N steps, and one step is called the least significant bit (LSB). The Arduino documentation gives the classic example: the Uno's 10-bit converter on a 5 V reference yields 1024 steps of about 4.9 mV each. A 12-bit converter on a 3.3 V reference has 4096 steps of roughly 0.81 mV.
Because every voltage inside one step maps to the same code, there is an unavoidable quantization error of plus or minus half an LSB. For an ideal converter fed a full-scale sine wave, that quantization noise sets the best possible signal-to-noise ratio. Analog Devices' long-standing ADC tutorials express it as SNR = 6.02 × N + 1.76 dB, where the 6.02 comes from 20 log10(2). Each extra bit buys about 6 dB.
Resolution is not accuracy
A converter's bit count describes how finely it divides the range, not how close each code is to the truth. Real parts add offset error, gain error, and non-linearity on top of quantization. The ATmega328P datasheet lists 10-bit resolution alongside an absolute accuracy of plus or minus 2 LSB, which it defines as the combined effect of offset, gain, non-linearity, and quantization errors.
The effective number of bits (ENOB) captures this in one figure. Working the SNR formula backwards gives ENOB = (SINAD − 1.76) / 6.02, where SINAD is the measured signal-to-noise-and-distortion ratio. The Raspberry Pi Pico SDK documentation describes the RP2040's converter as 12-bit with an ENOB of 8.7, and 9.2 for the RP2350. In practice the bottom three bits of an RP2040 reading are mostly noise, so displaying a battery voltage to four decimal places would be false precision.
The reference voltage is part of every measurement
Many boards use the supply rail as the default reference. The Arduino reference notes that the Uno maps input voltages between zero and its operating voltage onto codes 0 to 1023, and that the range can be changed with analogReference(). If that 5 V rail is really 4.8 V because of a long USB cable, every absolute voltage computed with 5.0 in the formula is about 4% high.
Some chips also have a loose internal reference. Espressif's ESP-IDF calibration documentation says the ESP32's ADC reference is designed to be 1100 mV but can range from 1000 mV to 1200 mV between chips. That is why ESP-IDF ships a calibration driver that reads per-chip correction data burned into eFuses, and why raw ESP32 codes should not be converted to volts with a single hard-coded constant. MicroPython makes a similar point in its machine. ADC documentation: read_u16() returns the raw reading scaled to 0–65535, while read_uv() returns microvolts, and whether that value is calibrated is up to each port.
There are two good strategies. For sensors that are themselves powered from the reference, such as a potentiometer or a resistive divider across the same rail, the measurement is ratiometric: supply drift scales the input and the reference equally and cancels out. For absolute measurements, such as a battery voltage, use a stable dedicated reference or a calibrated read, and measure the real reference value with a multimeter rather than trusting the nominal number.
Sampling rate and aliasing
A converter takes discrete snapshots, and the sampling theorem limits what those snapshots can represent: signal content above half the sample rate (the Nyquist frequency) does not disappear but folds back as a false lower frequency. Sampling a 1,100 Hz tone at 1,000 samples per second produces data that looks like a 100 Hz tone. No amount of software filtering afterwards can tell the alias from a real signal. The ATmega328P datasheet is explicit that components above the Nyquist frequency should not be present at the input and advises removing them with a low-pass filter before the pin.
Conversion speed varies enormously between chips. The ATmega328P needs an ADC clock between 50 kHz and 200 kHz for full 10-bit resolution, and a normal conversion takes 13 ADC clock cycles (25 for the first one after enabling the converter). With a 16 MHz CPU clock divided by 128, the ADC clock is 125 kHz, which works out to roughly 9,600 conversions per second. The RP2040, by comparison, runs its converter from a dedicated 48 MHz clock and takes 96 cycles per conversion, giving the 500,000 samples per second listed in the Pico SDK documentation.
Source impedance and the sample-and-hold capacitor
Inside most microcontroller ADCs, the selected input briefly connects to a small sample-and-hold capacitor, which must charge to the input voltage before the conversion begins. The ATmega328P's capacitor is listed at 14 pF. The datasheet says the converter is optimized for sources with an output impedance of approximately 10 kΩ or less; with a higher-impedance source, the capacitor may not finish charging in time and the reading comes out wrong, especially right after switching channels.
This catches people building voltage dividers with large resistors to save battery current. Two 1 MΩ resistors draw almost nothing, but the source impedance seen by the pin is their parallel combination, 500 kΩ, far above the recommendation. The fixes are to use smaller resistors and accept the current draw, slow the sampling down so the capacitor has time to settle, or put a unity-gain op-amp buffer between the divider and the pin.
Worked example: a battery monitor in MicroPython
Suppose a single lithium-ion cell, which tops out around 4.2 V, needs to be monitored by a Raspberry Pi Pico whose ADC input range is 0 to 3.3 V. A divider made of two equal 10 kΩ resistors halves the voltage to at most 2.1 V, comfortably inside the range. The parallel combination is 5 kΩ, low enough for a sample-and-hold input to settle, at the cost of about 0.21 mA of continuous drain at full charge. The code below averages many readings to reduce noise and converts the result using a reference value that should be measured on the actual board.
from machine import ADC, Pin
import time
adc = ADC(Pin(26)) # GP26 is ADC input 0 on a Raspberry Pi Pico
R_TOP = 10_000 # ohms, between battery + and the ADC pin
R_BOTTOM = 10_000 # ohms, between the ADC pin and ground
VREF = 3.3 # volts; replace with the value measured on your board
def read_battery(samples=64):
total = 0
for _ in range(samples):
total += adc.read_u16() # 0..65535 regardless of native resolution
time.sleep_us(50)
v_pin = (total / samples) * VREF / 65535
return v_pin * (R_TOP + R_BOTTOM) / R_BOTTOM
while True:
print("battery: {:.2f} V".format(read_battery()))
time.sleep(1)Two details are worth noticing. First, the output is printed to two decimal places, which matches what roughly 9 effective bits can honestly support: referred back to the battery side of the divider, the full-scale range is 6.6 V, so one effective step is about 13 mV. Second, the divider ratio and VREF are explicit constants, so calibrating the monitor means measuring the battery with a meter once and adjusting VREF until the two agree.
What averaging can and cannot do
Averaging reduces random noise: when the noise in each sample is uncorrelated, averaging N samples improves the signal-to-noise ratio by 10 log10(N) dB, the same processing-gain idea the Analog Devices tutorials apply to oversampling. Averaging four samples gains about 6 dB, roughly one bit. It does nothing for systematic errors. A wrong reference value, gain error, a high-impedance source, or an aliased interference tone will be averaged just as faithfully as the real signal.
A checklist before trusting an ADC reading
- Know the reference: is it the supply rail, an internal reference, or an external part, and what is its tolerance?
- Prefer ratiometric measurements when the sensor can be powered from the same rail as the reference.
- Check the datasheet's recommended maximum source impedance and keep divider resistances below it, or buffer the signal.
- Low-pass filter the input so nothing above half the sample rate reaches the pin.
- Judge the converter by its effective number of bits and absolute accuracy, not its nominal resolution.
- Discard the first reading after enabling the converter or switching channels if the datasheet says it is slower or less accurate.
- Average to fight random noise, and calibrate against a meter to fix gain and reference errors.
An ADC reading is the product of the input, the reference, and the converter's imperfections. Treat each of those as a design decision rather than a default, and the numbers coming out of that one-line read call start to mean what they appear to mean.
Enjoyed this?
Get the next deep dive in your inbox. No spam — just the stories worth reading.
Subscribe to the newsletter