Skip to main content
BRaff
Visitor II
September 15, 2020
Question

STM32F4 Center aligned pwm timer

  • September 15, 2020
  • 2 replies
  • 3470 views

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

This topic has been closed for replies.

2 replies

TDK
September 15, 2020

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""."
waclawek.jan
Super User
September 15, 2020

> 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