cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Center aligned pwm timer

BRaff
Associate

I configured timer1 for pwm generation center aligned like below in cube ide.

I update duty cycle writing directly CCRx register asyncronously in the code.

Most of the time pulses are effectively center aligned but sometimes not (nor left or right aligned). Please, a suggestion.

Raffaele

0693W000003RkwqQAC.jpg0693W000003Rkv9QAC.jpg

2 REPLIES 2
TDK
Guru

When you update CCRx, the value may take effect immediately, in which case you shouldn't expect a center-aligned pulse. You'll need to update it during the idle portion of the pulse.

You can enable preload, but the change will take effect on both the overflow and underflow event, which isn't what you want.

If you feel a post has answered your question, please click "Accept as Solution".

> You can enable preload, but the change will take effect on both the overflow and underflow event, which isn't what you want.

This is why updating CCRx in center-aligned mode is tricky and you may want to use the interrupt from one of the Compare channels (maybe even an unused one) set to a suitable level (maybe close to or at some of the endpoints) and maybe use one of the "CC interrupts only in one direction" modes in CMS.

(I don't understand ST's design decision in this particular issue - they might've have 3 behaviours in respect to Update Event as well).

JW