Skip to main content
RMurt.3
Associate II
May 8, 2023
Solved

How to configure TIM1 PWM for repetition mode

  • May 8, 2023
  • 2 replies
  • 1444 views

Im using a STM32F030C8T6 with PWM output to generate a sound output. I would like to use the repetition mode of the TIM1 so it will output the same PWM period 6 times.

If I configure the timer and use both HAL_TIM_Base_Start_IT() and HAL_TIM_PeriodElapsedCallback(), I do get a interrupt after 6 repeats. ...... But the PWM output is not switching.

Alternatively I can configure the system for HAL_TIM_PWM_Start() and HAL_TIM_PWM_PulseFinishedCallback() and the PWM output generates a waveform BUT I get an interrupt every cycle (not every 6th).

Everything I have seen online seems to suggest that it should easily be able to generate several pulses and then interrupt once done.

My thoughts are that this might be related to the output pin of the PWM not being initialized properly, but I'm open to any thoughts.

This topic has been closed for replies.
Best answer by waclawek.jan

Cube is open source, so you can read the sources, compare, and find the reason yourself. A better method is to observe the TIM and related GPIO registers' content, check/compare to working case, and find out what the differences are and why.

> But the PWM output is not switching.

My blind guess is, that the sequence of calls you use does not include setting of TIMx_BDCR.MOE.

I don't use Cube/HAL so don't know what's the incantation for that.

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
May 8, 2023

Cube is open source, so you can read the sources, compare, and find the reason yourself. A better method is to observe the TIM and related GPIO registers' content, check/compare to working case, and find out what the differences are and why.

> But the PWM output is not switching.

My blind guess is, that the sequence of calls you use does not include setting of TIMx_BDCR.MOE.

I don't use Cube/HAL so don't know what's the incantation for that.

JW

RMurt.3
RMurt.3Author
Associate II
May 9, 2023

Thanks Jan. You were indeed correct that the MOE bit was not set. - Awesome work !!!

That lead me to find the function I was missing -

HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_4);

I had been using the HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4); previously but had got rid of that when I was changing over to the timer update IRQ method.