CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Timer2 calculations

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCUprogrammer



Joined: 08 Sep 2020
Posts: 218

View user's profile Send private message

Timer2 calculations
PostPosted: Mon Mar 07, 2022 11:53 pm     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 08, 2022 6:19 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Tue Mar 08, 2022 11:44 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group