STM32H5 TIM1 PWM One-Pulse/Finite Pulse Generation Using RCR
- August 27, 2026
- 1 reply
- 25 views
I am using TIM1 CH1 in PWM mode with the TIM1 repetition counter (RCR) to generate a finite number of STEP pulses for a stepper motor. The desired step frequency is calculated from the motor speed, and ARR/CCR1 are configured accordingly. RCR is set to steps - 1 so that the PWM should generate the requested number of periods and then stop.
I am using HAL_TIM_PWM_Start() and the TIM1 update interrupt to detect when the required number of pulses has completed. The update callback is working correctly and HAL_TIM_PeriodElapsedCallback() is being called at the expected completion point.
However, TIM1 CH1 is not generating the PWM pulse train correctly, or in some cases no PWM is visible at all on the output pin. I have tried configuring PSC, ARR, CCR1, RCR and the update event/flags before starting PWM, but I am still unable to get the finite number of PWM pulses reliably.
I have attached my motor_driver.c file for reference. Could you please review the implementation and let me know if I am doing anything incorrectly in the TIM1 PWM and repetition counter configuration?
The TIM1 update callback is working correctly, but I am unable to get the expected finite number of PWM pulses on TIM1 CH1. The PWM is either not generated or is not behaving as expected.
Please review the attached code and let me know what could be causing this issue and whether the implementation approach is correct.
