This project explores how to combine ADC and TIMER trigger functionalities in STM32 microcontrollers, focusing on Timer Trigger Output Events (TRGO). By synchronizing ADC conversions with timer events, the system achieves precise timing control for analog data sampling.
The STM32F103C6 is configured to read data from a potentiometer every 10 seconds, triggered by TIM3 update events, with results displayed via UART. An LED indicates conversion activity. The simulation is implemented in Proteus 8.
STM32CubeMX Setup- Target MCU: STM32F103C6Tx
- Clock Configuration: System clock = 8 MHz
- GPIO Configuration
-
PA1 → Output (Status LED)
-
TIM3 Configuration
-
Internal Clock, One Pulse Mode
-
Channel 1: PWM Generation (not routed physically)
-
Prescaler = 10000
-
Counter Period = 8000 → 10-second interval
-
Trigger Output = Update Event (TRGO)
- ADC1 Configuration
-
Channel: IN7
-
Mode: Regular Conversion
-
External Trigger Source = TIM3 TRGO
-
Enable ADC1 global interrupts
- UART1 Configuration
-
Baud Rate: 115200
-
Asynchronous mode
-
8-bit word length, 1 stop bit, no parity
- Generate and open project in STM32CubeIDE
- Initialize ADC, TIMER3, UART, and GPIO
- Start ADC in interrupt mode with TIM3 TRGO trigger
- Implement ADC conversion complete callback:
-
Read ADC value
-
Send data via UART
-
Toggle LED (PA1) to indicate conversion
- Build and generate .hex file
- Create a new project
- Add components:
-
STM32F103C6 MCU
-
Potentiometer → ADC IN7 (PA7)
-
LED → PA1
-
Virtual Terminal → USART1 TX (PA9)
- Load compiled .hex file into STM32
- Run simulation:
-
Observe UART output every 10 seconds with new ADC value
-
LED toggles on each conversion event
If you have any questions or suggestions don't hesitate to leave a comment below
Comments