View previous topic :: View next topic |
Author |
Message |
harshanahnd
Joined: 22 Nov 2008 Posts: 11
|
Timer0 problem |
Posted: Sat Jan 03, 2009 3:59 am |
|
|
Hi,
I used the following code to setup a timer0 in 8bit mode,
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_256);
|
And I wanted to create a 16bit timer. So I changed the code into,
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_16_BIT|RTCC_DIV_256);
|
But the compiler gives an error on that.
I have gone through http://www.ccsinfo.com/forum/viewtopic.php?t=22467 and I think the correct way to set a 16bit timer is that. But it want work.
Please help me,
Thanks. |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 03, 2009 4:49 am |
|
|
What PIC?.
Have you looked at the data sheet for your chip?. Does it support 16bit mode?.
16bit mode for Timer0, is only generally available on PIC18 chips.
The compiler won't have RTCC_16_BIT defined fo chips that don't support this.
Best Wishes |
|
|
harshanahnd
Joined: 22 Nov 2008 Posts: 11
|
|
Posted: Sat Jan 03, 2009 8:06 am |
|
|
Yes, the data sheet says it supports. PIC is 18F4550 |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Jan 03, 2009 8:21 am |
|
|
Who told you, that RTCC_16_BIT is a valid keyword? Actually it isn't used by CCS C for any device nor have been mentioned in the said thread. In fact, not specifying RTCC_8_BIT defaults to 16 bit mode, that's all. |
|
|
harshanahnd
Joined: 22 Nov 2008 Posts: 11
|
|
Posted: Sat Jan 03, 2009 9:05 am |
|
|
Then how can we configure the timer0 in 16bit mode? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Jan 03, 2009 10:21 am |
|
|
As FvM said:
Quote: | In fact, not specifying RTCC_8_BIT defaults to 16 bit mode, that's all. |
He is saying to leave that declaration out of the Timer setup line and 16 bit mode is automatically the default.
When the compiler creates a "bit mask" it starts with 0x00 then ORs the specified parameters to create the control byte.
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
By leaving out RTCC_8_BIT you are omitting the 0x40 value (see the .H file) from the bit mask. This causes the corresponding 8 bit mode bit (Bit 6) to not be set in the T0CON register. If you read the datasheet, clearing bit 6 of T0CON is 16 bit mode. |
|
|
samantha Guest
|
RTCC_DIV_256 |
Posted: Sat Jan 03, 2009 10:17 pm |
|
|
hmmm, can anybody tell me the purpose""RTCC_DIV_256 "" ?
why we need divide 256? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Jan 03, 2009 11:56 pm |
|
|
How long you want the timer (counter) to run before it overflows and creates an interrupt? The technical answer is that it all depends on the main oscillator speed, prescaler, postscaler and whether it is an 8 bit (0-255) or 16 bit (0-65535) counter.
Timers can be used for a lot of things. For example, to make a real time clock in some of my projects I set up timer0 to interrupt every 10ms then count 100 of them to make one second then count the seconds to make minutes and hours. For that application I take the oscillator frequency then calculate how much it needs to be divided to get the proper input to the Timer0 counter so it will take 10ms to count to the highest count and "roll over" to zero.
Below is some info on PIC Timers:
http://ezinearticles.com/?PIC-Microcontroller-Timer-Calculation&id=220132
Another application is a "watchdog" timer which is explained here:
http://www.hobbyprojects.com/pic_tutorials/tutorial13.html |
|
|
Guest
|
|
Posted: Sun Jan 04, 2009 5:45 am |
|
|
Thanks... It worked. |
|
|
|