AnsweredAssumed Answered

STM32 Series - Calculations of Timer Variables.

Question asked by ChrisO on Oct 5, 2014
Latest reply on Oct 6, 2014 by Clive One
This is a subject that seems to have a lot of confusion (I do not fully understand). How to calculate the Variables:
       
  • Period
  •    
  • Prescaler
  •    
  • Duration

if only a few other variables are known. At higher frequencies, for example 1000000Hz simple rules work. At lower Frequencies like 1281Hz things get a little more complicated.

As an example: if we aim for an output frequency of 1281Hz, we need to set the ARR Register to: 32785. We need to set the PSC Register to: 3 and if we want a 50% DutyCycle, we need to set the CCRx Register to: 16393. Where the x in CCRx is the specified Channel one is going to use. 1, 2, 3 or 4.

The Registers need to see values of 16 BITs, Integer Values(65535 or less).

Equations exist so calculations can be made, for example:

TIM_Update_Frequency(Hz) = Clock / (PSC - 1) * (Period - 1)

1281.11273792094 = 84000000 / ((3) * (32785)) 

now, the problem becomes more complicated, for a desired frequency of 840Hz:

425.946209078739 = 84000000 / ((167) * (1189))

Here in lies the problem, how does one find the value of PSC when one knows only the values for "Clock" and "Period"? The value "TIM_Update_Frequency(Hz)" is not always the actual Desired Frequency.

Other equations must exist so as to calculate the "PSC" Value, or to calculate the "TIM_Update_Frequency(Hz)" so as to deduce the other values.

Guess work is just not a logical approach here.

Can anyone help with more equations for solving for the other variables?

Thank you

 Chris

Outcomes