How to use an ADC peripheral with oversampling. This example is based on the STM32C0xx ADC HAL API. The peripheral initialization done using LL unitary service functions for optimization purposes (performance and size).
Description of ADC oversampling:
Perform automatically multiple successive ADC conversions and average computation, by ADC hardware, and therefore off-load the CPU for the equivalent task. This feature can be used for the functions: averaging, data rate reduction, SNR improvement, basic filtering.
This example uses 3 configurations of oversampling, for comparison of conversion data and evaluation of oversampling benefits.
Example configuration:
ADC is configured to convert a single channel, in single conversion mode, from SW trigger. ADC oversampling feature is used with 3 settings:
Example execution:
From the main program execution, the ADC group regular converts the selected channel successively with the 3 oversampling settings. Then, data are evaluated:
When all ADC conversions are completed, the cycle of 3 conversions restarts.
LED4 is used to monitor program execution status:
Debug: variables to monitor with debugger:
Connection needed:
Use an external power supply to generate a voltage in range [0V; 3.3V] and connect it to analog input pin (cf pin below). Note: If no power supply available, this pin can be let floating (in this case ADC conversion data will be undetermined).
Other peripherals used:
1 GPIO for LED4
1 GPIO for analog input: ADC channel 4 on pin PA.04 (Arduino connector CN8 pin 3 A2, Morpho connector CN7 pin 32)
1 DMA channel
ADC, analog digital converter, analog, conversion, voltage, channel, analog input, oversampling
This example runs on STM32C031C6Tx devices.
This example has been tested with NUCLEO-C031C6 board and can be easily tailored to any other supported device and development board.
In order to make the program work, you must do the following :