Skip to main content
GSalo.1
Associate
July 24, 2020
Solved

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

  • July 24, 2020
  • 3 replies
  • 2590 views

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.
Best answer by GSalo.1

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
July 24, 2020

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
July 24, 2020

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
July 24, 2020

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