cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Up count vs center aligned - wrong frequency

oeliks
Senior

Hi ! Stm32f103 TIM3

Counting: UP

Clock 72Mhz​

Prescaler: 36-1

Period: 10-1

Pulse : 5

Result: 200khz 50% duty, ok !

But

​Counting: center aligned

Clock 72Mhz​

Prescaler: 18-1

Period: 10-1

Pulse : 5

Result: 222khz 50% duty

Why? Schould be 200khz also.

Checked with multimeter, confirmed with scope.

1 ACCEPTED SOLUTION

Accepted Solutions

In the first case, the counter's prescaled clock frequency is 2MHz i.e. input clock period is 0.5us; in one period counter counts 0-1-2-3-4-5-6-7-8-9 i.e. 10 input clock periods = 5us => frequency 200kHz.

In the second case, the counter's prescaled clock frequency is 4MHz i.e. period is 0.25us; in one period counter counts 0-1-2-3-4-5-6-7-8-9-8-7-6-5-4-3-2-1 that's 18 input clock periods = 4.5us => frequency 222kHz, exactly as you've experienced.

JW

View solution in original post

4 REPLIES 4

In the first case, the counter's prescaled clock frequency is 2MHz i.e. input clock period is 0.5us; in one period counter counts 0-1-2-3-4-5-6-7-8-9 i.e. 10 input clock periods = 5us => frequency 200kHz.

In the second case, the counter's prescaled clock frequency is 4MHz i.e. period is 0.25us; in one period counter counts 0-1-2-3-4-5-6-7-8-9-8-7-6-5-4-3-2-1 that's 18 input clock periods = 4.5us => frequency 222kHz, exactly as you've experienced.

JW

oeliks
Senior

Thank You very much !​

Can You tell me one more thing? How to set Pulse value​? Still = 5 ?

​low-high-low pulse?

0-1-2-3-4 low -- 5-6-7-8-9-8-7-6-high -- 5-4-3-2-1-low

And update event - at every - 0​

?

In RM0008, the timer chapters, in description of TIMx_CCMR1 register, the behaviour of OCxM signal (from which the output of the channel is derived) is described in the description of PWM modes set by the OC1M bits. See also the  Center-aligned PWM waveforms figure.

Yes, update event happens when the counter reaches 0 (unless there are other circumstances preventing this, e.g. Repetition counter (TIMx_RCR) nonzero in the Advanced timers, or TIMx_CR1.UDIS bit set).

JW

oeliks
Senior

Thank You, I will read thids RM chapters then !

Szczęśliwego Nowego Roku Janie :)​