2016-08-22 07:36 PM
I am using STM32F3 Discovery board to generate six-step PWM signals for BLDC motor drive. The switching was done in SysTick ISR by generating a SW COMG event. When I checked the PWM output on oscilloscope, however, I noticed that the very first PWM pulse generated was always much wider than the duty cycle I set, as shown in the picture attached.
I attached the code I used and would anyone please help to check why the wide first pulse could happen?2016-08-23 03:16 AM
It's the combination of
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_ForcedAction_Active);
andIn PWM mode 1 or 2, the OCREF level changes only when the result of thecomparison changes or when the output compare mode switches from “frozen� mode
to “PWM� mode.
JW
2016-08-23 04:59 AM
Hi David_Lin,
Try to set the UG bit of the TIMx_EGR register before enabling the timer. This will force the Update event generation once the timer is enabled and preload the shadow register' values. -Hannibal-2016-08-24 05:49 PM
Hi, Jan, thanks for the reply, and would you please suggest how I should change the code to avoid this problem?
2016-08-24 06:27 PM
Hi, Hannibal, do you mean adding TIM1 -> EGR |= 0x0001 to BLDCMotorPrepareCommutation() function?
The logic of the switching is to prepare the TIM1 register values first and when the next SysTick ISR happens, the register values will be updated. If I were to add TIM1 -> EGR |= 0x0001, will it change the switching logic?