View previous topic :: View next topic |
Author |
Message |
cambo Guest
|
external interrupt (#int_ext) |
Posted: Mon Dec 17, 2007 2:20 am |
|
|
I wrote a interrupt program as below. When input pulse is lower than 100KHz, output pulse is fine(as i expected) but when input pulse is over than 100KHz, output pulse become slow... i dont know why. Please help me if u know it. Thanks
#include <16f873a.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#define SECMAX 4
int sec;
#INT_EXT
void ext_isr(void)
{
sec--;
if(sec==0)
{
sec = SECMAX;
output_low(PIN_B1);
}
else{
output_high(PIN_B1);
}
}
void main (void)
{
EXT_INT_EDGE(L_TO_H);
sec = SECMAX;
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
}
} |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Mon Dec 17, 2007 7:50 am |
|
|
Not sure about the output pulse become slow - do you mean it just doesn't get faster as expected? Anyway . . .
You're probably reaching the pic speed limit. The standard isr pre/post processing added by ccs saves/restores a lot of stuff. Use the FAST keyword on your isr (doesn't save/restore anything). Look at the generated asm code, and add code (if needed) to save/restore only the regs used in the isr.
Ken |
|
|
cambo Guest
|
|
Posted: Mon Dec 17, 2007 6:08 pm |
|
|
Yes, as input pulse frequency is faster(over100KHz), output pulse should also become faster too. But it is not.....
I dont make it yet, thanks for ur help anyway... i'm trying |
|
|
cambo Guest
|
|
Posted: Mon Dec 17, 2007 10:03 pm |
|
|
Can u give me some examples?
Thanks |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
external interrupt |
Posted: Tue Dec 18, 2007 4:15 am |
|
|
if the controller works at 20MHz with 200ns=PC, you have 50 pc between interrupts, 100khz will be more or less the limit in C, with FAST maybe more. In asembler, your program will be able to handle arround 400khz.
joseph |
|
|
|