How to use an ADC peripheral with an ADC analog watchdog to monitor a channel and detect when the corresponding conversion data is outside the window thresholds. This example is based on the STM32C0xx ADC LL API. The peripheral initialization is done using LL unitary service functions for optimization purposes (performance and size).
Example configuration:
ADC is configured to convert a single channel, in continuous conversion mode, from SW trigger. Analog watchdog 1 is configured to monitor all channels on ADC group regular (therefore, including the selected channel).
Analog watchdog thresholds values:
high threshold is set to Vref+/2 (3.3V/2=1.65V on NUCLEO-C031C6), refer to literal ADC_AWD_THRESHOLD_HIGH.
low threshold is set to 0V, refer to literal ADC_AWD_THRESHOLD_LOW. ADC interruption enabled: Analog watchdog 1.
Example execution:
From the main program execution, the ADC converts the selected channel continuously. When conversion data is out of analog watchdog window, ADC interruption occurs and analog watchdog callback function is called to process the event. Every 5 seconds, the ADC analog watchdog is rearmed to be ready for another trig.
LED4 is used to monitor program execution status:
Note: In this example, analog watchdog low threshold is set to 0V for test simplicity purpose, therefore case of voltage below low threshold is not achievable unless cutomizing low threshold value.
Note: In case of noise on voltage applied on ADC channel input (due to connectors and wires parasitics), ADC analog watchdog may trig at a voltage level with an uncertainty of tens of mV.
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)
ADC, analog digital converter, analog, conversion, voltage, channel, analog input, trigger, analog watchdog, threshold, window
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 :