Skip to main content
GSalo.1
Associate
Jul 24, 2020 8:55 AM UTC
Solved

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

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

This topic has been closed for replies.
GSalo.1
GSalo.1Best answer
Associate
Jul 24, 2020 12:05 PM UTC

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 :)

3 replies

waclawek.jan
Super User
Jul 24, 2020 9:10 AM UTC

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
GSalo.1Author
Associate
Jul 24, 2020 9:42 AM UTC

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
GSalo.1AuthorBest answer
Associate
Jul 24, 2020 12:05 PM UTC

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 :)