Foundations · Lesson 7 of 11 · about 10 min
ADC: reading the analog world
From a voltage to a number
Temperature, light and pressure change smoothly, but the CPU only understands numbers. The analog-to-digital converter (ADC) takes snapshots of a voltage and rounds each one to the nearest step.
- Resolution is how fine the steps are. A 12-bit ADC has 4096 steps: about 0.8 mV each at 3.3 V.
- Sample rate is how often it takes a snapshot. Too slow and fast changes are lost.
uint16_t raw = HAL_ADC_GetValue(&hadc1); // 0 .. 4095
float volts = raw * 3.3f / 4095; // 2048 -> 1.65 V
// volts -> temperature, light, pressure: the formula is in the sensor's datasheet
Interview questions
- What limits the accuracy of an ADC reading?
- What happens if you sample a signal too slowly?
- How do you turn a raw 12-bit reading into volts?
No answers here on purpose: try answering out loud first. In the BoardPilot app, the interview coach reads your own answer and tells you what was right, what is missing and what a senior interviewer would ask next (it uses the AI provider you choose in the app). Embedded systems interview questions →
Key terms
ADC (analog-to-digital converter) ADC resolution Sample rate DAC (digital-to-analog converter) Datasheet HAL (hardware abstraction layer)
In the app, the lessons come alive
The lessons have interactive demos and hands-on labs checked on your board in the app. These pages are the readable version: the demos are described in words, and the labs need the app.