fermionboson Guest
|
period |
Posted: Fri Dec 14, 2007 10:01 am |
|
|
Hello, body:
I use timer2 as the interruption, but the actual period is more than the theoretic period.
For example, Fosc=8MHZ
The periode de Timer2=1/(8Mhz/4/2)=1us, but i have got about 44us, could anyone tell me why and how to avoid this problem?
Thx!
Code: | #include<18f458.h>
#device ICD=TRUE
#use delay (clock=8000000)
#fuses HS, NOWDT, NOPROTECT
#int_timer2
void IT_handler(void) {
static int x=0;
if (x==0) {
output_bit(PIN_D4,1);
x=1;
} else {
output_bit(PIN_D4,0);
x=0;
}
}
void main(void)
{
setup_timer_2(T2_DIV_BY_1,1,1);
set_timer2(0);
enable_interrupts (GLOBAL);
enable_interrupts(INT_TIMER2);
while(TRUE);
}
|
|
|