View previous topic :: View next topic |
Author |
Message |
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
Timer0 and interrupt questions. |
Posted: Sat Apr 30, 2005 6:32 am |
|
|
I would like to ask if how to initialize and start timer0 in CCS C.
In 8051, after loading the Timers ans setting the interrupts, you can set TR register equal to 1 to start the timer running.
IN PIC, how to start timer running and what is the difference between set_timer0() and setup_timer_0().
Another if I already enabled interrupt and i have the loop f(;;) will the system run forever and interrupt when needed?
Thanks. |
|
|
Ttelmah Guest
|
|
Posted: Sat Apr 30, 2005 6:50 am |
|
|
The timer runs all the time if a clock is present.
Setup_timer_0, deterines where the clock is to come from, what prescaler is to be used etc..
Set_timer_0, puts the value into the counter register. It can be pretty useless in some cases, since at faster rates, the register will change by the very next instruction. Loading the counter registers, is something to only do with 'care'. Look for a lot of threads about this...
Best Wishes |
|
|
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
|
Posted: Sat Apr 30, 2005 7:03 am |
|
|
You have not answered my question, I am asking if how to get a timer running after loading it. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1938 Location: Norman, OK
|
|
Posted: Sat Apr 30, 2005 7:16 am |
|
|
Ttelmah,
You try to help him and all he does is "smart mouth" you! I'd leave him to find his own answers..... |
|
|
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
|
Posted: Sat Apr 30, 2005 7:24 am |
|
|
Hey, what is your problem, I only told him that I am asking is the start of timer.
You are the big mouthed fool here. |
|
|
Ttelmah Guest
|
|
Posted: Sat Apr 30, 2005 7:28 am |
|
|
The timer is already running. There is nothing else to do. You can change the clock source, but the timer _keeps running all the time_. There is no secret instruction to start it, or magic involved.
Hence the comments about your reply.....
Best Wishes |
|
|
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
|
Posted: Sat Apr 30, 2005 7:55 am |
|
|
Hi,
I hope you get not offended my reply as someone interpreted it as offensive.
Now, how to stop the timer from counting?
Thanks. |
|
|
Ttelmah Guest
|
|
Posted: Sat Apr 30, 2005 8:22 am |
|
|
All you do is ignore the interrupt, if using this.
Understand, that Timer0, is a very basic counter indeed. Some of the other timers (assuming your chip has them), have more features, such as the ability to be used with the CCP, to give automatic resetting at particular counts, possibly interrupts after multiple rollovers (on ones that support a postscaler), and gate control. Potentially, if you are not using the T0CKI pin, and timer0 on your chip supports thus, you can switch timer0, to be clocked from this pin, and it will then stop (though make sure you have the pin pulled high/low, with an external resistor to avoid potential noise problems before doing this).
I suggest you pull the application note from the Microchip site, on using the timers. Basic 'rule' with CCS, is to look first at what your chip's hardware supports, and therefore the chip's data sheet, and then ask how to use the feature in CCS.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Apr 30, 2005 11:18 am |
|
|
Quote: | Now, how to stop the timer from counting? | By default all timers are running, stopping depends on the chip family you are using, as far as I know you can only disable the timers in the PIC18 series. For the PIC16 series instead of stopping the timer, why worry about this? Just let the timer continue and disable the resulting functions you don't like, for example disable the timer0 interrupt.
See the documentation for the setup_timer_0() function for more details, this will also point you to some example programs. Also read the header file for your processor in the PICC\devices directory, here you will see all allowed parameters for your processor. |
|
|
bb
Joined: 06 Apr 2005 Posts: 7 Location: Germany
|
|
Posted: Sat Apr 30, 2005 12:59 pm |
|
|
Quote: | By default all timers are running, stopping depends on the chip family you are using, as far as I know you can only disable the timers in the PIC18 series. |
No, only TMR0 is running. All other timers are disabled after a POR (PIC16 and PIC18 series).
Best regards,
Bernd |
|
|
|