![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Somkiat
Joined: 30 Mar 2004 Posts: 8
|
How to setup timer 0 for... |
Posted: Mon Aug 16, 2004 12:38 am |
|
|
How to setup timer 0 for interrupt ever 2.8 mS at crystal 4 MHz?
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
chingB
Joined: 29 Dec 2003 Posts: 81
|
Re: How to setup timer 0 for... |
Posted: Mon Aug 16, 2004 1:56 am |
|
|
Somkiat wrote: | How to setup timer 0 for interrupt ever 2.8 mS at crystal 4 MHz?
Thanks |
Try dis code below....
Code: |
#include <18F452.H>
#fuses HS,NOPROTECT,NOWDT,NOLVP,PUT
#use delay(clock=4000000)
#int_timer0
void timer0_isr()
{
< add your routine here... >
set_timer0(62736);
clear_interrupt(int_timer0);
}
void init_mcu()
{
// 4M/(4*1*65536) = 65.536mSec.
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);
set_timer0(62736);
clear_interrupt(int_timer0);
enable_interrupts(int_timer0);
enable_interrupts(global);
}
void main()
{
init_mcu();
// < add your routine here... >
while (TRUE);
}
|
Hope this give you a startup.... |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: How to setup timer 0 for... |
Posted: Mon Aug 16, 2004 4:27 am |
|
|
Somkiat wrote: | How to setup timer 0 for interrupt ever 2.8 mS at crystal 4 MHz?
Thanks |
You don't say what chip...
This matters, since the 16family, only have an 8bit timer0. You also need to give an idea of the accuracy needed. The problem is that setting the counter 'forward', as suggested in the code posted, has a large error, because the counter wll have allready incremented by perhaps 50 instruction times, by the time the interrupt handler is reached.
If accuracy really is important, it'd be better to use a slightly different clock frequency, or if your chip supports it, one of the CTC channels, and it's associated timer.
A count at 2.048mSec, is easy with the 8bit timer module, using a prescaler of 8.
Switching to using a prescaler of 16, and then in the interrupt, setting the counter 'forward', by 81, should be close.
So, specify the 'criteria' (accuracy needed, and the chip involved), and some better solutions may be available.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Somkiat
Joined: 30 Mar 2004 Posts: 8
|
|
Posted: Wed Aug 18, 2004 11:15 am |
|
|
I use PIC16F877-04/P
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|