2025-12-10 9:15 AM
I want to stop generating a PWM signal after 22 clock edges. It seems like the TIMx_RCR register (repetition counter register) should work for this.
My code started from the CubeMX generated code but I have had to remove a lot of it for performance reasons. I am running an STM32H523 with a SYSCLK of 250MHz. The PWM is about 650 KHz so I need to disable the output about 33 us after I start it. That timing is a little tight to do with an interrupt counting down from 22 to zero; however, that seems to be exactly what the TIMx_RCR register does in hardware.
My current code uses the HAL_TIM_PWM_PulseFinishedCallback() function but it seems that it is being called for every pulse, not every 22 pulses.
Does anyone have some pointers or code examples for how to setup TIM1 on an STM32H523? I am using STM32CubeIDE v 1.19.0 (because 2.0.0 broke my build).