2020-05-12 11:25 AM
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.)
2020-05-12 06:26 PM
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.
2020-05-13 02:16 AM
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.
2020-05-13 11:31 AM
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?
2020-05-13 11:34 AM
2020-05-13 12:07 PM
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
2020-05-13 12:16 PM
PWM generation doesn't need interrupts, the TIM can do this automatically, you might want to modulate the width or frequency, but at high speeds (>100 KHz) you would want to use DMA to service the TIM via a table/array.
2020-05-14 09:27 AM
Thank you for the advice on using the timers' PWM, but the problem I had was different, and wacky in general. The timer 1 interrupt, I assume, has no relation to the function of timers 2 and 3 PWM. There is no code in the interrupt that changes any settings of those timers. At this point I think the frequency of the interrupt somehow takes priority over loading the timer configuration values first. My friend is also working on a program that uses PWM at high-ish frequencies, so this information will be helpful to him as well.