# Timer1 interrupt does not fire

#### Vaughanabe13

Joined May 4, 2009
102
This is a bizarre problem, something I have never come across before. I am trying to get Timers 0,1,3 all running and generating high-priority interrupts simultaneously. Timer0 works perfectly and generates an interrupt on rollover. Timers 1 and 3 do not. I used my debugger and stepped through the code line by line and I see everything working -> The timer is incrementing, then it gets to 65536 and rolls over to 0, and the TMR1IF flag gets set, BUT an interrupt is never called, and the timer just keeps counting up from 0 and the interrupt flag stays set. I have the interrupts configured correctly and the priority set as high. Here is the relevant setup:

Rich (BB code):
    T0CON = 0b00001000;                //Setup 16-bit timer0 to bypass prescaler (page 129 of datasheet)
T1CON = 0b00000000;                //Setup 16-bit timer1 to bypass prescaler (page 133) of datasheet
T3CON = 0b00000000;                //Setup 16-bit timer3 to bypass prescaler (page 141) of datasheet

//Enable timer overflow interrupts
INTCONbits.TMR0IF = 0;             //Clear Timer0 interrupt flag
INTCONbits.TMR0IE = 1;               //Enable Timer0 interrupts
INTCON2 = 0b00000100;
INTCON3 = 0b01001000;

PIR1bits.TMR1IF = 0;                  //Clear Timer1 interrupt flag
PIE1bits.TMR1IE = 1;                 //Enable Timer1 interrupts
IPR1bits.TMR1IP = 1;               //Set Timer1 interrupt priority

PIR2bits.TMR3IF = 0;                 //Clear Timer3 interrupt flag
PIE2bits.TMR3IE = 1;                 //Enable Timer3 interrupts
IPR2bits.TMR3IP = 1;               //Set Timer3 interrupt priority
After this I turn global interrupts ON, I turn the timers on and just wait for an interrupt in main(). Again, Timer0 works fine and generates interrupts, so I know the interrupts in general are working. They just do not work with Timer1 or Timer3. Is there something I have configured wrong or something I am overlooking?

The uC is a PIC18F4550 and here is the datasheet:

#### R!f@@

Joined Apr 2, 2009
9,647
or may be ur uC is faulty.
Just a thought.

#### Vaughanabe13

Joined May 4, 2009
102
I just soldered this one in a day ago. Everything else is working fine. So I think that's not the problem.

#### CVMichael

Joined Aug 3, 2007
419
I don't see the master interrupt (GIE) bit being set ?

#### CVMichael

Joined Aug 3, 2007
419
Here's one of mine configs, hopefully it helps (the timer interrupt part is at the beginning):
Rich (BB code):
void Config(void) {
T0CON = 0b11000000;
TMR0L = 106;
INTCON = 0b11100000;

PIE1.RCIE = 1;

PORTA  = 0b00000000;
LATA   = 0b00000000;
CMCON  = 0b00000111;
TRISA  = 0b00011111;
//         76543210

PORTB  = 0b00000000;
LATB   = 0b00000000;
TRISB  = 0b00000000;
//         76543210

UCON  = 0b00000000;
PORTC = 0b00000000;
LATC  = 0b00000000;
TRISC = 0b00000000;
//        76543210

PORTD = 0b00000000;
LATD  = 0b00000000;
TRISD = 0b00000000;
}
Maybe you should post the rest of your code ?

#### Vaughanabe13

Joined May 4, 2009
102
I figured it out. I had set INTCON <GIEH> high already, but when I also set INTCON <GIEL> The timer starts interrupting correctly. I'm not really sure what the difference is between the GIEH and GIEL bits. I thought they were just enabling different priority levels, but all of my interrupts are set to high priority...

#### retched

Joined Dec 5, 2009
5,197
GIEL enables all interrupts that have the priority bit cleared, and GIEH does the same for interrupts that have the priority bit set

#### Vaughanabe13

Joined May 4, 2009
102
Yes, and as I said, all of my interrupts were set as high priority (bit set).

#### BMorse

Joined Sep 26, 2009
2,675
GIEH/PEIE and GIEL/GIE have 2 different functions depending on if IPEN is set or cleared...

I don't see where you are setting the IPEN bit to enable this function..... If IPEN (RCON<7>) was set then the priorities would work as they should have with the GIEL and GIEH bits set the way you originally had them....

The interrupt priority feature is enabled by setting the
IPEN bit (RCON<7>). When interrupt priority is
enabled, there are two bits which enable interrupts
globally. Setting the GIEH bit (INTCON<7>) enables all
interrupts that have the priority bit set (high priority).
Setting the GIEL bit (INTCON<6>) enables all
interrupts that have the priority bit cleared (low priority).
When the interrupt flag, enable bit and appropriate
global interrupt enable bit are set, the interrupt will
vector immediately to address 000008h or 000018h,
depending on the priority bit setting. Individual interrupts
can be disabled through their corresponding
enable bits.
When the IPEN bit is cleared (default state), the
interrupt priority feature is disabled and interrupts are
compatible with PIC® mid-range devices. In
Compatibility mode, the interrupt priority bits for each
source have no effect. INTCON<6> is the PEIE bit
which enables/disables all peripheral interrupt sources.
INTCON<7> is the GIE bit which enables/disables all
interrupt sources. All interrupts branch to address
000008h in Compatibility mode.
So since you did not have IPEN set, you have to set the GIEL (which is the GIE) bit when in this mode....

My .02
B. Morse

Last edited:

#### Vaughanabe13

Joined May 4, 2009
102
GIEH/PEIE and GIEL/GIE have 2 different functions depending on if IPEN is set or cleared...

I don't see where you are setting the IPEN bit to enable this function..... If IPEN (RCON<7>) was set then the priorities would work as they should have with the GIEL and GIEH bits set the way you originally had them....

So since you did not have IPEN set, you have to set the GIEL (which is the GIE) bit when in this mode....

My .02
B. Morse

Thanks! That's exactly what I was looking for. I knew it was some dumb little detail I was forgetting...