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

Timer0 problem

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



Joined: 22 Nov 2008
Posts: 11

View user's profile Send private message

Timer0 problem
PostPosted: Sat Jan 03, 2009 3:59 am     Reply with quote

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







PostPosted: Sat Jan 03, 2009 4:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 8:06 am     Reply with quote

Yes, the data sheet says it supports. PIC is 18F4550
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 8:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 9:05 am     Reply with quote

Then how can we configure the timer0 in 16bit mode?
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 10:21 am     Reply with quote

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
PostPosted: Sat Jan 03, 2009 10:17 pm     Reply with quote

hmmm, can anybody tell me the purpose""RTCC_DIV_256 "" ?
why we need divide 256?
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 11:56 pm     Reply with quote

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








PostPosted: Sun Jan 04, 2009 5:45 am     Reply with quote

Thanks... It worked. Smile
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