cancel
Showing results for 
Search instead for 
Did you mean: 

Generating PWM interrupts every specified number of pulses (using Repetition Counter)

GSalo.1
Associate II

Hello everyone,

I would like to know how to configure Timer1 to run at a certain frequency, but the interrupt will only generate a certain number of pulses (determined by the repetition counter).

I am using STM32CubeIDE and nucleo-l476rg. I tried to do this, but the HAL_TIM_PWM_PulseFinishedCallback interrupt is still generated every pulse.

I will be grateful if someone tells me how to configure it in CubeMX and which interrupts to use in my code.

Best regards,

Grzegorz

1 ACCEPTED SOLUTION

Accepted Solutions
GSalo.1
Associate II

Got it 🙂 I used wrong HAL functions. Instead of using the HAL_TIM_Base_Start_IT and HAL_TIM_PeriodElapsedCallback functions, I used HAL_TIMEx_PWMN_Start_IT and HAL_TIM_PWM_PulseFinishedCallback. Now everything works correct.

Thanks for your reply JW 🙂

View solution in original post

3 REPLIES 3

I don't know about CubeMX, but you simply set the repetition count to TIMx_RCR register and then the Update interrupt will happen only every N overflows of the timer.

JW

GSalo.1
Associate II

I set the RCR register to the desired value, but the interrupt keeps getting generated every pulse. The only difference I can see is that PWM generation will stop after a certain number of periods (equal to the number of RCs) when I set the timer in One Pulse Mode.

GS

GSalo.1
Associate II

Got it 🙂 I used wrong HAL functions. Instead of using the HAL_TIM_Base_Start_IT and HAL_TIM_PeriodElapsedCallback functions, I used HAL_TIMEx_PWMN_Start_IT and HAL_TIM_PWM_PulseFinishedCallback. Now everything works correct.

Thanks for your reply JW 🙂