Skip to main content
Associate II
August 28, 2025
Question

PWM generation in timer 2

  • August 28, 2025
  • 2 replies
  • 281 views

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.

 

2 replies

waclawek.jan
Super User
August 28, 2025

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

JW

Associate II
August 28, 2025

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
August 28, 2025

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