Introduction to STM32 ADC Principle

ampheoampheo
3 min read

Here’s a clear introduction to the STM32 ADC principle, covering what it is, how it works inside the MCU, and what you need to know as a developer.


1. What is an ADC?

  • ADC = Analog-to-Digital Converter

  • Converts a continuous analog signal (e.g., voltage from a sensor) into a digital value that the MCU can process.

  • STM32 microcontrollers integrate successive approximation (SAR) ADCs, which balance speed and resolution.


2. Key Features of STM32 ADC

  • Resolution: Commonly 12-bit (0–4095), but some families allow 6, 8, 10, 12, 14, or even 16 bits.

  • Input channels: Multiple (up to 16+), multiplexed into one ADC core.

  • Reference voltage (Vref+): Defines full-scale range.

    • Input range: 0 V → Vref+ (e.g., 0–3.3 V).
  • Sampling time: Adjustable — defines how long the ADC samples the input capacitor before conversion.

  • Conversion speed: Up to several MSPS (mega-samples per second) depending on the STM32 family.

  • Triggering: Can start conversions by software, timer events, or external pins.

  • Modes:

    • Single conversion (one sample)

    • Continuous mode (keep sampling same channel)

    • Scan mode (sample multiple channels sequentially)

    • Injected mode (priority sampling, often synchronized with events like PWM edges)


3. Principle of Operation

Inside STM32, the ADC works like this:

  1. Sampling:

    • Input voltage is connected to a sample-and-hold capacitor.

    • Sampling time allows the capacitor to charge to the input level.

  2. Quantization (SAR process):

    • Successive Approximation Register (SAR) compares the stored voltage against a reference (Vref) using a comparator + DAC.

    • Bit-by-bit, it decides if the input is above/below threshold, constructing a binary digital value.

  3. Digital Output:

    • After conversion, the result (e.g., 0–4095 for 12-bit) is stored in the ADC Data Register (ADC_DR).

    • CPU, DMA, or peripherals can read the result.


4. Example Conversion (12-bit, Vref = 3.3 V)

  • Formula:

  • If ADC result = 2048:

    Vin​=2048​/4095×3.3≈1.65V


5. Practical Use in STM32

  • Configure ADC in STM32CubeMX or register-level:

    • Enable ADC clock.

    • Select channel(s).

    • Configure resolution, sampling time, trigger source.

  • Start conversion:

    • By software (HAL_ADC_Start()),

    • or automatically by timer trigger/DMA.

  • Read result:

    • Polling (HAL_ADC_GetValue()),

    • Interrupt,

    • or via DMA (best for continuous multi-channel sampling).


6. Applications

  • Sensor interfacing (temperature, light, gas, etc.).

  • Reading potentiometers / analog controls.

  • Audio signal acquisition (low-to-mid speed).

  • Power monitoring (voltage, current sensing).

  • Motor control feedback (e.g., current shunt resistors).


In summary:
The STM32 ADC is a SAR-based converter that samples analog voltages, compares them against a reference, and outputs a digital value. With multiple channels, flexible triggering, and DMA support, it’s powerful for real-time sensing tasks.

0
Subscribe to my newsletter

Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ampheo
ampheo