Skip to main content
JShel.1
Associate II
May 12, 2020
Question

Timers other than timer 1 don't have functioning PWM? (Blue pill)

  • May 12, 2020
  • 4 replies
  • 1983 views

This problem just popped up for me. I'm not sure if I'm doing anything wrong, but timers other than timer 1 don't have functioning PWM. I configured the timers the exact same (aside from ignoring timer 1's special features,) making sure to include HAL_TIM_PWM_Start() and HAL_TIM_Base_Start(). I even triple-checked the pin I was connecting my oscilloscope to. Still, no timer other than timer 1 wants to output PWM. If necessary, I can put my old code (working code, which I tested today,) and new code (non-functioning) here. I tried searching for my problem, but nothing came up.

And as a last note, the new code WAS working about a month ago when I last tested it (I'm sure I have not made any changes to the timer configuration since.)

This topic has been closed for replies.

4 replies

TDK
Super User
May 13, 2020

It's unlikely that PWM mode doesn't work for other timers, so there is probably a bug in your code.

It's also unlikely that code which worked a month ago no longer works today.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Nikita91
Lead II
May 13, 2020

You said new code without any change to the timer configuration.

So your problem comes from the other new part of the application...

A modification made less than a month ago.

JShel.1
JShel.1Author
Associate II
May 13, 2020

So there does seem to be an issue with the configuration, because I got the PWM to work again.

The difference was, when it wasn't working, timer 1 update event interrupt was on, and because I had an auto reload of 12, was occurring at ~6MHz (assuming timer 1 runs with the base clock of 72MHz.) This time, I disabled the update event, and the PWM started working.

Unfortunately, part of my code requires those updates to happen very often, so I need it to happen. My question now is: why does having interrupts stop timers 2 and 3 PWM from working? Is there a way I can fix it, or do I have to find a way around the very frequent interrupts?

TDK
Super User
May 13, 2020
The way around very frequent interrupts is it disable the interrupts or reduce their frequency. It doesnt stop other timers from working but it will prevent you from running any code in the main loop since your mcu is always in the interrupt handler.
"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
May 13, 2020

There's no way your interrupts would execute at 6MHz rate at all; the entry sequence alone is 12 clocks (and that's without FLASH latency, software overhead in the ISR itself, exit, and the body of ISR itself). You may be able to see some toggling at that frequency, but that's just those interrupts tail-chaining on each other, which is a completely useless thing.

JW