View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
Timer2 calculations |
Posted: Mon Mar 07, 2022 11:53 pm |
|
|
hello
PIC18F67J60 25MHZ
Timer Period = (1/((Fosc / 4) / T divisor) ) * (PR2 + 1)
I wrote the formula used to calculate the timer period. Well, I want the timer period value to be 10ms. Now, since the period value is certain, what kind of formula should I create? Can you talk about it?
So how do you decide to create the T divisor and PR2 values? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Mar 08, 2022 6:19 am |
|
|
well, you could 'cheat'....
https://www.mikroe.com/timer-calculator
I've used it on and off for years..
with pres=1:16, psts=1:16, PR2=244 it computes to 9.9968ms
2.5 decades ago I wrote a QuickBasic4.5 program to 'do the math', I'd have to find my good old Win98SE machine to see just how I did it though...
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Mar 08, 2022 11:44 am |
|
|
On divisor, remember PR2+1 maxes at 256.
So ((Fosc/4)/256)/F, gives you the value that divisor must be bigger than:
So for 100Hz (10msec):
((25MHz/4)/256)/100) =244
So (given the available divisors), 256 must be used.
Then with this, you get ((25MHz/4)/256)/100 gives PR2+1=244. |
|
|
|