2020-05-09 03:29 AM
I have read STM32f1 Reference Manual and tested STM32CubeMx functions but have not found any solution.
Is there a way to change PWM polarity without Deinitializing Timer??
Solved! Go to Solution.
2020-05-10 11:11 AM
If the phase of the pwm signal is unimportant, write max - val instead of val to the ccr to invert the polarity.
2020-05-10 10:26 PM
I've just noticed that you have TIMx_CR2.CCPC set:
CCxE, CCxNE and OCxM bits are preloaded, after having been written, they are updated
only when a commutation event (COM) occurs (COMG bit set or rising edge detected on
TRGI, depending on the CCUS bit).
While RM does not mention the polarity bits (CCxP/CCxNP in TIMx_CCER), I wouldn't be surprised if they were preloaded too.
Try to clear this bit (or not set it at the beginning).
JW
2020-05-11 12:57 AM
I've tried but doesn't work as this. Thanks.
2020-05-11 12:59 AM
I tried this and it looks good. Thanks. It's solved my problem.
2020-05-11 09:54 PM
Yes, RM does not mention the polarity bits. Thanks
2020-05-12 09:17 AM
OK so have you tried whether clearing TIMx_CR2.CCPC allows you to change output polarity by flipping the CCxP bits in TIMx_CCER?
JW
2022-03-11 06:01 AM
__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_1, TIM_INPUTCHANNELPOLARITY_FALLING);
Use the above function inside the interrupt this will change the timer polarity during run time.