View previous topic :: View next topic |
Author |
Message |
AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
CCS Manual INT_RTCC Explanation? |
Posted: Fri Jul 27, 2007 7:33 am |
|
|
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
|
|
Posted: Fri Jul 27, 2007 8:43 am |
|
|
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?
Ronald |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 27, 2007 9:51 am |
|
|
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
|
|
Posted: Fri Jul 27, 2007 11:18 pm |
|
|
I feel better now.
Thank you. |
|
|
|