View previous topic :: View next topic |
Author |
Message |
nehallove
Joined: 16 Jan 2008 Posts: 61
|
single common ISR routine and delay_ms causes problems |
Posted: Wed Jan 14, 2009 3:01 am |
|
|
I am trying to use one common routine for all interrupts and then manually check which interrupt is fired for easy debugging purpose; but instead it becomes more difficult and having more problems.
Part of code is as follow:
Code: |
#bit INT0IF = 0xFF2.1 //! External0 interrupt flag bit
#bit T0IF = 0xFF2.2 //! Timer0 interrupt flag bit
#bit T1IF = 0xF9E.0 //! Timer1 interrupt flag bit
#INT_DEFAULT
default_isr() { //! default routine to track of which interrupt fires
if(T1IF) { //! timer1 interrupt
clear_interrupt(INT_TIMER1);
overflow++; //! increment overflows
}
if(INT0IF) { //! extint0 interrupt
disable_interrupts(INT_EXT); //! don't reenable in ISR
clear_interrupt(INT_EXT);
//! timer 0 setup for debouncing time
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
clear_interrupt(INT_RTCC); //! enable debouncing timer0 interrupt
enable_interrupts(INT_RTCC);
set_timer0(0);
}
if(T0IF) { //! on fire of timer0 interrupt
disable_interrupts(INT_RTCC); //! execute debouncing
clear_interrupt(INT_RTCC);
}
} |
Now whenever I put delay_ms(someno.) in my main or other functions; it automatically sets T0IF bit to "1" and when other interrupt fires, it goes to default ISR and so to timer0 interrupt routine.
Can anybody explain to me what is happening in there?
Thank you very much,
Regards:
nehal _________________ nehal |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 14, 2009 3:55 am |
|
|
First thing to understand. To use INT_DEFAULT, it becomes _your_ responsibility to save and restore _every_ register used inside your interrupt code. Even a 'simple' thing like incrementing a counter, _will_ use several registers, and you _must_ protect these. Look at the example 'EX_GLINT.C', for the _minimum_ register saving necessary. If your code does more things, more _will_ be needed. Without this, your code "hasn't a hope".
Once you have this sorted, your problem will probably disappear.
Best Wishes |
|
|
nehallove
Joined: 16 Jan 2008 Posts: 61
|
|
Posted: Wed Jan 14, 2009 4:51 pm |
|
|
I changed code in a format of below... standard ccs compiler interrupt routine. Still delay_ms fires timer interrupt. Even if I use timer 3 or timer 0 ... it fires. If I remove delay_ms; it is gone. But if I don't then it is still there.
Code: | #bit INT0IF = 0xFF2.1 //! External0 interrupt flag bit
#bit T0IF = 0xFF2.2 //! Timer0 interrupt flag bit
#bit T1IF = 0xF9E.0 //! Timer1 interrupt flag bit
#INT_TIMER1
void wave_timer() { //!mesurement interrupt routine
clear_interrupt(INT_TIMER1);
overflow++; //! increment overflows
}
#INT_EXT
void ext_isr() { //!external interrupt routine
disable_interrupts(INT_EXT); //! don't reenable in ISR
clear_interrupt(INT_EXT);
......
......
} |
_________________ nehal |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 14, 2009 4:54 pm |
|
|
Post your compiler version. |
|
|
nehallove
Joined: 16 Jan 2008 Posts: 61
|
|
Posted: Wed Jan 14, 2009 4:59 pm |
|
|
Compiler version is:
PCWHD: 4.083 _________________ nehal |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 14, 2009 5:42 pm |
|
|
Also post your PIC. |
|
|
nehallove
Joined: 16 Jan 2008 Posts: 61
|
|
Posted: Wed Jan 14, 2009 5:55 pm |
|
|
PIC18F25K20 _________________ nehal |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 14, 2009 6:31 pm |
|
|
Here's a little test program. I compiled it with vs. 4.083 and then I looked
at the .LST file. I did not see any place in the ASM code where T0IF is
set to 0.
Can you post a small test program (similar to this one) that shows
the problem ? The program should be very short. Add the minimum
number of lines of code that are needed to show the problem.
Code: | #include <18F25K20.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#bit INT0IF = 0xFF2.1 //! External0 interrupt flag bit
#bit T0IF = 0xFF2.2 //! Timer0 interrupt flag bit
#bit T1IF = 0xF9E.0 //! Timer1 interrupt flag bit
int8 overflow = 0;
#INT_TIMER1
void wave_timer()
{
clear_interrupt(INT_TIMER1);
overflow++;
}
#INT_EXT
void ext_isr()
{
disable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
}
//===============================
void main()
{
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
delay_ms(1);
while(1);
}
|
|
|
|
nehallove
Joined: 16 Jan 2008 Posts: 61
|
|
Posted: Thu Jan 15, 2009 12:09 pm |
|
|
the routine you post it also work on my compiler too; so it means there is also something else wrong in my code too. let me figure out and if i still have a problem; i'll post it again _________________ nehal |
|
|
|