
I thought I'd throw a more comprehensive answer in here. 2 Hz frequency means two events every second, so the events are indeed 500ms apart. You are using frequencies in the formula, you are dividing the 84 MHz input frequency with some values, and get 2 Hz as a result. It can also happen that there are no precise integer solutions at all, then you can still loop through all possible prescaler values, and see which one gives the smallest error. If the desired ratio is not a nice round number, then you should resort to integer factorization, or write a small program to look for all possible divisors ( for(i=0 i<65536 i++). Luckily there are lots of zeroes at the end, you can just pick e.g.

Note that 2.3s is the period, not the frequency, so you'd need to put its inverse into the formula. Let's see an example, you'd want a 2.3 seconds delay. You'd have to find a factorization that satisfies these constraints. Unfortunately most timers have 16 bit registers only, so this is not going to work when TIMclk/Updatefrequency > 65535. PSC to 0, and ARR to the right hand side value - 1. The trivial solution would be to set one of them, e.g. Then you have a known value on the right hand side, but two unknowns on the left hand side. Rearrange it to (PSC+1)*(ARR+1) = TIMclk/Updatefrequency Take the simple formula, Updatefrequency = TIM clk/((PSC+1)*(ARR+1)) How this PSC = 41999 and Period = 1999 are selected? No, this is one second (1s) delay, or 1 Hz frequency.

This attempts to round the result, when no integer solution is possible. You can assume RCR=0, and omit *(RCR+1) from the formula. This one is better, but general purpose timers don't have RCR registers. The counters go from 0 to the register value (inclusive), there are always one more cycles than the register value, not one less.
#Time clock calculator f update
i.e 500msĪnd when i use PSC=39999 and Period =4199 The update event value is 0.5. Moreover when i used PSC=41999 and Period =999 The update event value is 2.īut my delay is twice in every sec.
#Time clock calculator f how to
OK so now i am trying to understand how this PSC = 41999 and Period = 1999 are selected? Is it purely based on assumption as in whatever formula i use i have to assume one variable.? How to calculate prescale and period if i want say 1.5 or 2.3 or 4.9 something like that precise timing.? So, PSC - 41999 ARR - 1999 Apllying this to the second formula
#Time clock calculator f code
The code uses prescale value of 41999 and a period of 1999. I have tried a code which generates 1 ms delay(said by the author) and after using that values for prescale and period i generated a code which also generates 1ms Delay(by intuition - no scope). So coming to the question, My core clock is running at 168 MHz But i can see the Timer are connected to APB1 Bus which is running at 84 MHz. There is lot of variations in the formula to calculate the value of period and prescale

So i was beginning with General purpose timers and i am stuck with prescale and period values.īasically i want to generate a timer interrupt every n(where n=1,2,3.) ms and perform some tasks.
