Skip to main content
Associate II
Aug 28, 2025 6:21 AM UTC
Question

PWM generation in timer 2

I am using stm32g431c8u6 microcontroller . I have enabled timer 2 channel 3 for alternative pin of PB10 and I have enabled channel 4 for PA3 pin. I set counter perioud 499 and prescaler value =0.

Tashenlrana_0-1756361739173.png

Tashenlrana_1-1756361772126.png

When I plug the debugger and run the code only channel 4 generate PWM signal and channel 3 does not generate PWM signal.

I am using DRV8845 motor drive to control 2 motors. It has two direction pins t control two motors. Below I linked the MCU pin configuration.

Tashenlrana_2-1756361921155.png

This is my code to move forward the 2 motors.

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,0);

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,1);

 

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,1);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,1);

TIM2->CCR3 = 400; //out_pid;

TIM2->CCR4 = 400;//out_pid;

 

Please guide me to how to enable PWM signals for both channels. Thank you.

 

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
Aug 28, 2025 6:45 AM UTC

Read out and check/post content of TIM and relevant GPIO registers.

JW

Associate II
Aug 28, 2025 6:54 AM UTC

In above MCU pin configuration timer1 and timer8 are used to count pulse count for encoders and nSLEEP pin is a low power mode pin.

Motor direction pins are PA7 and PB0. 

 

 

waclawek.jan
Super User
Aug 28, 2025 8:05 AM UTC

I don't think these were information relevant to the problem in original post, i.e. no PWM output signal on PB10 as TIM2_CH3.

Read out and check/post content of TIM2 and GPIOB registers.

JW