ADC_AnalogWatchdog_Init Example Description

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:

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)

Keywords

ADC, analog digital converter, analog, conversion, voltage, channel, analog input, trigger, analog watchdog, threshold, window

Directory contents

Hardware and Software environment

How to use it ?

In order to make the program work, you must do the following :