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

Some queries about Timer0

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

Some queries about Timer0
PostPosted: Thu Sep 02, 2010 1:03 am     Reply with quote

Hi,
I have some questions about timer0, I have read different articles related to timer's but not clearing my mind.
I am using CCS compiler and 18f252.

1- As in 8-bit mode we can use the prescaler values from 1 to 256, In 16 bit mode what are the values of prescalers.

2- How can I use timer0 as an counter?
3- How should I start and stop the timer? Are the terms "start" and "stop" referred to "enable" and "disable" interrupts respectively or something else.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 02, 2010 5:48 pm     Reply with quote

Quote:

1- As in 8-bit mode we can use the prescaler values from 1 to 256,
in 16 bit mode what are the values of prescalers.

The same as for 8-bit mode.

Quote:
How can I use timer0 as an counter?

Look in the .h file for your PIC, in the Timer0 section, and find a suitable
parameter for the setup_timer_0() function that will set it up the way you
want.

Quote:
How should I start and stop the timer?

Look in the .h file (again). Find the parameter for setup_timer_0() that
will turn off the Timer. To turn it on, simply call that function without
the "off" parameter. (Use the normal parameters).
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Thu Sep 02, 2010 11:58 pm     Reply with quote

Quote:

The same as for 8-bit mode.

I have somewhere read that prescaler values available for timer0 in 16-bit mode are 1,2,4,8.

In the hex file of PIC (PIC18f252) i found something like that
Code:

////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER_0(),
//                              SET_TIMER0() or SET_RTCC(),
//                              GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER_0() are:
#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
               
#define RTCC_DIV_1      8
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7

#define RTCC_OFF        0x80 

#define RTCC_8_BIT      0x40               


If I use RTCC_8_BIT, then the timer will run in the 8-bit mode and if I not use this line then the timer will run in 16-bit mode.
To stop the timer RTCC_OFF will be used, but what about to turn it ON again.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Sep 03, 2010 4:49 am     Reply with quote

Quote:
I have somewhere read that prescaler values available for timer0 in 16-bit mode are 1,2,4,8.
Reading is good, but 'somewhere' we can not check.
When in doubt read the datasheet, and here it is clear that for your PIC18F252 there is no difference for the prescaler between 8- or 16-bit mode.

Quote:
In the hex file of PIC (PIC18f252) ...
Header file you meant?

Quote:
To stop the timer RTCC_OFF will be used, but what about to turn it ON again.
Read the previous post of PCM Programmer again. It is in the last sentence.
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Fri Sep 03, 2010 5:00 am     Reply with quote

Quote:
Header file you meant?

Means the file (18f252) which is in the device folder of the ccs compiler.

Quote:
Read the previous post of PCM Programmer again. It is in the last sentence.

I read what PCM Programmer said and what i understand from hex file is that
to stop the timer "RTCC_OFF" is used and as said by the PCM Programmer call the function without parameter off, so i understand it as RTCC but there is no thing like that.
What to do.
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Fri Sep 03, 2010 5:14 am     Reply with quote

Stop talking about a 'hex file'. The header file, is simple text. Nothing to do with 'hex'. The problem is that if you start talking about the hex file, we will think you are talking about the 'intel hex' file generated as the compiler output, which is a very different thing ....

If you send a setup_timer_0(), like:

setup_timer_0(RTCC_8_BIT|RTCC_DIV_8|RTCC_EXT_L_TO_H);

This sets the prescaler to 8, the timer to 8bits, tells the timer to count low to high transitions on the external input, _and enables the timer_.

setup_timer_0(RTCC_OFF);

disables the timer.

Best Wishes
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Fri Sep 03, 2010 5:24 am     Reply with quote

Maybe I am unable to deliver my question,
As all of you said that RTCC_OFF is the function/command to stop the timer. OK right I understand it.
Quote:
setup_timer_0(RTCC_OFF);


Now I want again to start the time now what should I write again to start the timer.
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