AnsweredAssumed Answered

How best to turn PWMs ON and OFF from interrupt handler

Question asked by Jim Seymour on Jan 20, 2016
Latest reply on Jan 23, 2016 by wolff.roger
We have a design that drives 12 LEDs using PWM outputs spread out over five different timers on a STM32F030.  We further control the LED dimming by turning the PWMs ON and OFF from a timer interrupt handler.

I've found that sometimes turning a LED on or off will affect a different LED.  I'm wondering if I'm doing the right steps in my interrupt handler.

Because the PWMs in question may or may not be running when the interrupt fires, I do the following to turn them ON:  (Example is for channel 1 of TIM15)

if (htimp15.Instance->CCR1 != 0) {
   TIM_CCxChannelCmd(htimp15.Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
}

And then this to turn the PWMs OFF:
TIM_CCxChannelCmd(htimp15.Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);

Does this seem correct (and safe to do in an interrupt handler)?

Outcomes