Skip to Content

ADC Peripheral Block Description

This block handles the ADC (Analog-to-Digital Converter) peripheral in STM32 microcontrollers. It enables the conversion of analog signals to digital, which is crucial for reading data from various sensors and external devices.



ADC Block

Table of Contents

Inputs

This block does not have any inputs.

Outputs

Output NameTypeDescription
Channel Nuint16Digital value read from the ADC channel, where N represents the channel number. This value is scaled to the range of, in example, 0-4095 for a 12-bit ADC. The number and numbering of output channels depend on the Number of channels parameter.

Block Parameters

Block Parameters for I2C

ParameterDescription
ADC NumberThe number of the ADC module.
Number of channelsThe number of ADC channels to be read. This parameter determines the quantity of outputs for the ADC block.
Buffer size per channel [samples]The number of samples stored in the buffer for each ADC channel. This setting allows the accumulation of multiple ADC readings, which can be useful for signal analysis or data filtering.
Sample timeThe refresh period of the block’s outputs. This is not the ADC conversion time, which is set in the CubeMX configuration.


Block parameters for I2C

CubeMX Configuration for a Given MCU Model

The CubeMX configuration and interface appearance may differ between individual MCU models within given families. Below are example CubeMX settings for selected MCU models. For other models, settings should be adjusted according to the manufacturer’s documentation and project requirements.

CubeMX Settings

No.NamePathSettingDescriptionScreenshot
1ModePinout & Configuration > ADC* > Mode > ChannelDifferential or
Single-ended or
Checked
Setting the ADC operating mode for the selected channel. Different channels can have different operating modes. Select all channels that are to be used in the ADC block.ADC Mode setting
2ADC ClockClock Configuration > ADC Clock MuxValue depending on the target ADC frequencySetting the clock source for the ADC interface. This value depends on the target ADC frequency and the system clock configuration.ADC Clock setting
3ADC PrescalerPinout & Configuration > ADC* > Parameter Settings > ADC_Settings > Clock PrescalerValue depending on the target ADC frequencySetting the prescaler for the ADC interface. This value depends on the target ADC frequency and the system clock configuration.ADC Prescaler setting
4Add DMAPinout & Configuration > ADC* > DMA SettingsAddAdding DMA support for the ADC interface.ADC DMA setting
5Select ADC Module for DMAPinout & Configuration > ADC* > DMA Settings > DMA Request > SelectSelected ADC module, e.g., ADC1, ADC2 etc.Selecting the ADC module used in the ADC block.ADC DMA setting
6DMA ModePinout & Configuration > ADC* > DMA Settings > DMA Request Settings > DMA ModeCircularSetting the DMA operating mode. Circular mode allows continuous reading of data from the ADC and storing it in a buffer, which aligns with the operation of the ADC block.ADC DMA setting
7DMA Address and Data WidthPinout & Configuration > ADC* > DMA Settings > DMA Request Settings > Increment Address and Data WidthMemory
Half Word
Setting the data transfer direction and data width for DMA. The Memory direction means that data will be transferred from the ADC peripheral to memory, and the Half Word width means data will be transferred in 16-bit units.ADC DMA setting
8Continuous Conversion ModePinout & Configuration > ADC* > Parameter Settings > ADC_Settings > Continuous Conversion ModeEnabledEnabling continuous conversion mode for the ADC interface. This mode allows uninterrupted data reading.ADC Continuous Conversion setting
9Conversion Data Management ModePinout & Configuration > ADC* > Parameter Settings > ADC_Settings > Conversion Data Management ModeDMA Circular ModeSetting the conversion data management mode for the ADC interface. DMA Circular mode allows continuous reading of data from the ADC and storing it in a buffer.ADC Conversion Data Management setting
10End Of Conversion SelectionPinout & Configuration > ADC* > Parameter Settings > ADC_Settings > End of Conversion SelectionEnd of single conversion
or
End of sequence conversion
Selecting the conversion completion condition for the ADC interface.ADC End of Conversion setting
11Number of ConversionPinout & Configuration > ADC* > Parameter Settings > ADC_Regular_ConversionMode > Number of ConversionEqual to the number of selected channelsThe number of conversions to be performed in the ADC conversion sequence. This value should be equal to the number of channels selected for conversion.ADC Number of Conversion setting
12RankPinout & Configuration > ADC* > Parameter Settings > ADC_Regular_ConversionMode > RankAppropriate for the desired sequenceThe order in which the ADC channels will be converted within the conversion sequence. Each channel should be assigned a unique rank number that defines its position in the sequence. Select the appropriate channel.ADC Rank setting
13Sampling TimePinout & Configuration > ADC* > Parameter Settings > ADC_Regular_ConversionMode > Rank > Sampling TimeCalculated valueThe duration (expressed in clock cycles) for which the ADC sampling capacitor charges from the selected channel before its conversion begins.ADC Sampling Time setting

Calculating Sampling Time

Tadc≤(TmN⋅S)⋅fadc−CT_{adc} \le \left( \frac{T_m}{N \cdot S} \right) \cdot f_{adc} - C

Where:

  • TadcT_{adc} – ADC sampling time (in ADC clock cycles);
  • TmT_m – model step time (model sample time, expressed in seconds);
  • NN – number of channels used;
  • SS – number of samples per channel (Buffer size per channel parameter);
  • fadcf_{adc} – ADC clock frequency (expressed in Hz);
  • CC – constant conversion time overhead (to be verified in the processor’s Reference Manual, typically around 10.5 to 12.5 cycles).

Important: It is recommended to set the sampling time to the highest possible value that satisfies the above condition. This provides a more stable reading and significantly reduces processor load.

Interrupts for the ADC are not mandatory.

ADC* - the asterisk (*) symbol represents the number of the ADC module used in the model, e.g., ADC1, ADC2 etc.

See Also

Last updated on