Hello

I've a question concerning the correct timings of center aligned PWM signals. Now it's pretty clear that usually when calculating timer bases one has to set the actual register to "period - 1" since the timer starts counting at zero.

A nice example of this can be found in figure 103 of the RM0090 (stm32f4) reference manual where the ARR value gets set to 8 and the counter ticks 9x times from 0 to 8. This is also true for edge aligned PWM where the counter only counts up or down.

Now when we take a look at figure 104 on the next page things get a bit tricky. Again the ARR is set to 8, but now we're dealing with center aligned PWM which means the counter counts up and down. According to the figure it counts from 0 to 8 and then back down to 1 before the next period starts. This only makes a total of 16 ticks for 2x periods and as a result one period is one tick shorter than compared to the edge aligned version.

So... in theory, let's say I work with 168MHz clock and want to set my center aligned PWM to 10kHz, I'd have to set the ARR to 16800 instead of the "usual" 16799?

Of course this wouldn't matter here at all, but let's assume someone uses lower clocks and therefor lower values...

/edit

The referred figures are at page 376/377.

/update

Ok, I've just spend some time re-checking my assumptions and as it turns out I'm right. When using center-aligned PWM, the period value for the ARR register is calculated by:

Period = Timer Clock / PWM Frequency

No -1 whatsoever.

I've a question concerning the correct timings of center aligned PWM signals. Now it's pretty clear that usually when calculating timer bases one has to set the actual register to "period - 1" since the timer starts counting at zero.

A nice example of this can be found in figure 103 of the RM0090 (stm32f4) reference manual where the ARR value gets set to 8 and the counter ticks 9x times from 0 to 8. This is also true for edge aligned PWM where the counter only counts up or down.

Now when we take a look at figure 104 on the next page things get a bit tricky. Again the ARR is set to 8, but now we're dealing with center aligned PWM which means the counter counts up and down. According to the figure it counts from 0 to 8 and then back down to 1 before the next period starts. This only makes a total of 16 ticks for 2x periods and as a result one period is one tick shorter than compared to the edge aligned version.

So... in theory, let's say I work with 168MHz clock and want to set my center aligned PWM to 10kHz, I'd have to set the ARR to 16800 instead of the "usual" 16799?

Of course this wouldn't matter here at all, but let's assume someone uses lower clocks and therefor lower values...

/edit

The referred figures are at page 376/377.

/update

Ok, I've just spend some time re-checking my assumptions and as it turns out I'm right. When using center-aligned PWM, the period value for the ARR register is calculated by:

Period = Timer Clock / PWM Frequency

No -1 whatsoever.