Hi Dumitru I am very interested in your problem but unfortunately I don't have a solution. I did not have time to examine the code closely but I think there might be trouble with the C18 compiler loading two ISR events high. I have two ISRs in my current program that work fine if you load one high and the other low but if you load both high I get strange undefined behavior across my program. I'm using an 18F6520 and a 6520 both devices give me the same trouble. My guess is that these parts are close/ near the same family as the one you are working on. (I'm no expert I don't even live near an expert on PIC devices I have only done three products in the last three years two in asm one in C18..........................but they are working fine in the field) I have asked Microchip to look at my ISR code but they can find nothing wrong. They say it should work but all I know is that it doesn't. It is very difficult for me to debug because like I said the darn things work fine with only one loaded high. I didn't really need to have both ISRS loaded high for this product that I'm beta testing today but in the next version I will not be so lucky so I might end up with a different device or hiring a smart guy to help me figger it out. The thing that lept out at me was two things happening in the high priority ISR. Could you try an experiment where you try loading one high and one low? Phillip Things should be as simple as possible but no simpler Phillip Coiner CTO, GPS Source, Inc. Your source for quality GNSS Networking Solutions and Design Services, Now! -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Dumitru Stama Sent: Monday, December 04, 2006 12:13 PM To: piclist@mit.edu Subject: [PIC] Problems with C18 interrupt code Hi guys, I have problems with the folowing piece of code. I modified the original example from Microchip C18 which implements TIMER0 interrupt and i added PORTB on-change interrupt. The code does only one thing : it increments pulse_count.b1234 which is an unsigned long (this being made inside ISR) when it detects a change from 0 to 1 on RB4 and in the main loop sends the value to PORTC so i can see it. I tested this code using Proteus VSM and it works well. I applied an impulse train on RB4 and the programs acts as it shoul with only one problem : after ~30 seconds it behaves erratically for a few moments and starts to count again from 0 ! I disabled watchdog timer (even from VSM), i disabled LVP, i disabled BOR, i disabled Stack overflow reset, no luck whatsoever. Can anyone see if i am doing something wrong with the folowing piece of code ? I have the .lst as well as .hex files if that might help. I have been doing this for the last 10 hours and i feel like i am loosing my mind. Thank you for your understanding, //-------------------------------------------------------------------------- -- #include #pragma config OSC = XT, OSCS = OFF, PWRT = ON, BOR = OFF, WDT = OFF, STVR = OFF, LVP = OFF, DEBUG = OFF //-------------------------------------------------------------------------- -- void main (void); void InterruptHandlerHigh (void); union { struct { unsigned Timeout:1; //flag to indicate a TMR0 timeout unsigned None:7; } Bit; unsigned char Byte; } Flags; //========================= union { struct { unsigned char B0; unsigned char B1; unsigned char B2; unsigned char B3; } byte; unsigned long b1234; } pulse_count; //========================= union { struct { unsigned RB0:1; unsigned RB1:1; unsigned RB2:1; unsigned RB3:1; unsigned RB4:1; unsigned RB5:1; unsigned RB6:1; unsigned RB7:1; }; unsigned char old_portb; } old_portb_bits; //-------------------------------------------------------------------------- -- // Main routine void main () { Flags.Byte = 0; INTCON = 0x28; //disable global and enable TMR0 interrupt and RB INTCON2 = 0x85; //TMR0 high priority RCONbits.IPEN = 1; //enable priority levels TMR0H = 0; //clear timer and set TMR0H TMR0L = 0; //clear timer low byte and also updates high byte from TMR0H T0CON = 0x88; //set up timer0 - no prescaler INTCONbits.GIEH = 1; //enable interrupts TRISB = 0x7E; //PORTB bits 0 and 7 are output, the rest are input TRISC = 0; //PORTC bits are output PORTC = 0; old_portb_bits.old_portb = 0; pulse_count.b1234 = 0; while (1) { PORTC = pulse_count.byte.B0; } } //-------------------------------------------------------------------------- -- // High priority interrupt vector #pragma code InterruptVectorHigh = 0x08 void InterruptVectorHigh (void) { _asm goto InterruptHandlerHigh //jump to interrupt routine _endasm } //-------------------------------------------------------------------------- -- // High priority interrupt routine #pragma code #pragma interrupt InterruptHandlerHigh void InterruptHandlerHigh () { if (INTCONbits.TMR0IF) { //check for TMR0 overflow INTCONbits.TMR0IF = 0; //clear interrupt flag } if (INTCONbits.RBIF) { PORTB = PORTB; INTCONbits.RBIF = 0; if (PORTBbits.RB4 == 1 && old_portb_bits.RB4 == 0) (unsigned long)pulse_count.b1234++; old_portb_bits.old_portb = PORTB; } } -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist