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

CCS Manual INT_RTCC Explanation?

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



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

CCS Manual INT_RTCC Explanation?
PostPosted: Fri Jul 27, 2007 7:33 am     Reply with quote

I need a little help in uderstanding the INT_RTCC time settings.
While going through CCS compiler reference manual for Setup_Timer0, I landed on the page describing the setup_timer0.
I have confusion regarding the text of the reference manual, which says :
Example Code:
For PIC18F452
setup_Timer0(RTCC_INTERNAL| RTCC_DIV_2|RTCC_8_BIT);
The text written as explanation with the above statement:
“sets the internal clock as source and prescale 2.At 20 MHz, Timer0 will incerement every 4us in this setup and overflows every 1.245ms.”
What I do not understand, how does timer0 shall increment in 4micro seconds.
According to my understanding so far got so far, Timer0 has to incerement every (4*2)/20,000,000=0.4micro sec. So an 8 bit overflow shall occur in 256*0.4=0.1024ms.
Pl. correct me....
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jul 27, 2007 8:43 am     Reply with quote

Timer0 (RTCC) is an 8-bit timer(or depending on the PIC it can be a 16-bit timer). In other words, as an 8-bit timer it has a register that is incremented and when it turns over from 255 to 0 it sets an interrupt flag. As a 16-bit timer it turns over from 65535 to 0.

It also has what's called a 'pre-scaler' that acts as a divisor for the input clock.

The way to calculate the timing as an 8-bit timer is:

Fosc/4 /prescaler/256 = freq.

The main oscillator is divided by four. This is a hardware design and cannot be changed. the prescaler is an 8-bit register that can be programmed to one of nine settings to be a 1:1 to 1:256 divider. the 8-bit value in the setup statement tells the compiler to configure the timer as an 8-bit timer.

So, if you have a 20MHZ oscillator running, with the prescaler set to 8 the formula is:

20MHZ/4/8/256

This will give you aproximately 2441 interrupts each second or an interrupt every 409uS.

Clear as mud? Wink

Ronald
Ttelmah
Guest







PostPosted: Fri Jul 27, 2007 9:51 am     Reply with quote

Except he has the prescaler set to 2, which as he correctly says gives just under 10000 interrupts/second (0.1024mSec/interrupt).
I'm afraid the decimal point is simply missing in the manual page, for the first figure, and then the second carries this error forwards. CCS are as accurate in the manual at times, as they are at writing compilers...

Best Wishes
AdamkT1



Joined: 21 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Fri Jul 27, 2007 11:18 pm     Reply with quote

I feel better now.
Thank you.
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