This project demonstrates the ADC Watchdog (AWD) feature in STM32 microcontrollers. Acting as a voltage window comparator, the watchdog continuously monitors ADC input channels against predefined thresholds. If the analog input goes outside the defined range, it triggers an interrupt, allowing immediate system response.
The system uses a potentiometer as the analog input. Threshold violations trigger an LED alert and send a message via UART. Simulation is implemented in Proteus 8.
STM32CubeMX Setup- MCU: STM32F103C6 (8 MHz system clock)
- GPIO Configuration
-
PB0 → Output (Status LED)
-
PB1 → Output (Alert LED)
- ADC1 Configuration
-
Regular Conversion Mode enabled
-
Channel: PA0 (Potentiometer input)
-
Enable Analog Watchdog [ Threshold Low = 500 ; Threshold High = 3000 ]
-
Enable ADC interrupts
- UART1 Configuration
-
Baud Rate: 115200
-
Asynchronous mode
-
8-bit data, 1 stop bit, no parity
- Code Generation
- ADC Initialization
-
Configure watchdog thresholds via HAL_ADC_AnalogWDGConfig()
- Interrupt Callback
-
HAL_ADC_LevelOutOfWindowCallback()
-
Trigger LED (PB1) and send UART alert when value exceeds threshold
- Main Loop
-
Poll ADC values and toggle PB0 LED
-
Transmit ADC values over UART
Required Components
- STM32F103C6 MCU
- Potentiometer (to PA0/ADC1)
- 2× LEDs (PB0, PB1)
- Virtual Terminal (connected to PA9 / UART1 TX)
Steps
- Connect potentiometer output → ADC IN0 (PA0)
- Connect PB0 → Status LED, PB1 → Alert LED
- Connect PA9 (TX) → Virtual Terminal
- Load compiled .hex file into STM32
- Run simulation:
-
Adjust potentiometer to vary input voltage
-
Observe ADC values in UART terminal
-
PB1 LED + alert message trigger when thresholds are violated
If you have any questions or suggestions don't hesitate to leave a comment below
Comments