jack0218
Joined: 10 May 2008 Posts: 1
|
Unreliable Interrupt |
Posted: Sat May 10, 2008 10:55 pm |
|
|
I have a device that, among other things, uses the Timer0 interrupt to operate a one second duration LED "metronome" at a period of 5s. The "metronome" itself works as it is supposed to, but sometimes has an initial delay of around 1.5 minutes before it begins its cycle. This only happens occasionally, happens more often for some chip writings than others, and can sometimes be resolved by turning the power off and on once or a few times. I think that this may be due to a problem with initialization or some related topic, but the consistency of the delay is concerning. I would just like this function to be reliable; thanks in advance for your help.
Code: | #include "18F2321.h"
#fuses INTRC_IO,NOFCMEN,NOIESO,NOPUT,NOBROWNOUT,NOWDT,CCP2C1,NOPBADEN,LPT1OSC,NOMCLR,NOSTVREN,NOLVP,NOPROTECT,NOCPB
#use delay(clock=8000000)
#INT_TIMER0
int metronome(int two_Hz_timing_interrupt)
{
two_Hz_timing_interrupt=two_Hz_timing_interrupt+1;
if (two_Hz_timing_interrupt==1)
{
output_high(PIN_A5);
}
else if (two_Hz_timing_interrupt==3)
{
output_low(PIN_A5);
}
else if (two_Hz_timing_interrupt==10)
{
two_Hz_timing_interrupt=0;
}
return two_Hz_timing_interrupt;
}
void main(void)
{
int two_Hz_timing_interrupt=0;
SETUP_TIMER_0(RTCC_DIV_16|RTCC_INTERNAL);
ENABLE_INTERRUPTS(INT_TIMER0);
ENABLE_INTERRUPTS(GLOBAL);
SET_TIMER0(0);
while (TRUE)
{***other unrelevant stuff***}
} |
|
|