AnsweredAssumed Answered

Discovery board PWM output example period value

Question asked by hill.jonathan on Apr 14, 2014
Latest reply on Apr 15, 2014 by Clive One
Hi all, just a simple question hopefully,

In the peripheral example for configuring TIM3 for PWM output, calculations for working out PSC and ARR values are given, comments supposing to explain them.

The bit thats confusing me is:

 To get TIM3 counter clock at 28 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /28 MHz) - 1
                                              
    To get TIM3 output clock at 30 KHz, the period (ARR)) is computed as follows:
       ARR = (TIM3 counter clock / TIM3 output clock) - 1
           = 665

If I'm understanding it right, the first calculation sets the counter clock at 28MHz.
The second one should then be that value divided by the output frequency you want, which seems to be 30kHz.

But 28000000/ 30000 =/= 666!!!!! It should be 933.3!!

I tried to consider what the value written to Auto-reload should be, by considering how many periods of 28MHz fit into one period of 30MHz and arrived at the same calculation as given above (2nd one).

Obviously I'm missing or misunderstanding something which is making my maths go off course here, because I'd assume they wouldn't publish such a crazy random and misleading mistake... Any help would be appreciated 

Outcomes