View previous topic :: View next topic |
Author |
Message |
hayee
Joined: 05 Sep 2007 Posts: 252
|
Some queries about Timer0 |
Posted: Thu Sep 02, 2010 1:03 am |
|
|
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
|
|
Posted: Thu Sep 02, 2010 5:48 pm |
|
|
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
|
|
Posted: Thu Sep 02, 2010 11:58 pm |
|
|
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
|
|
Posted: Fri Sep 03, 2010 4:49 am |
|
|
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
|
|
Posted: Fri Sep 03, 2010 5:00 am |
|
|
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: 19520
|
|
Posted: Fri Sep 03, 2010 5:14 am |
|
|
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
|
|
Posted: Fri Sep 03, 2010 5:24 am |
|
|
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. |
|
|
|