Timer1 interrupt does not fire

Discussion in 'Embedded Systems and Microcontrollers' started by Vaughanabe13, Jun 21, 2010.

  1. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    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:

    Code ( (Unknown Language)):
    1.     T0CON = 0b00001000;                //Setup 16-bit timer0 to bypass prescaler (page 129 of datasheet)
    2.     T1CON = 0b00000000;                //Setup 16-bit timer1 to bypass prescaler (page 133) of datasheet
    3.     T3CON = 0b00000000;                //Setup 16-bit timer3 to bypass prescaler (page 141) of datasheet
    4.      
    5.     //Enable timer overflow interrupts
    6.     INTCONbits.TMR0IF = 0;             //Clear Timer0 interrupt flag
    7.     INTCONbits.TMR0IE = 1;               //Enable Timer0 interrupts
    8.     INTCON2 = 0b00000100;
    9.     INTCON3 = 0b01001000;
    10.  
    11.     PIR1bits.TMR1IF = 0;                  //Clear Timer1 interrupt flag
    12.     PIE1bits.TMR1IE = 1;                 //Enable Timer1 interrupts
    13.     IPR1bits.TMR1IP = 1;               //Set Timer1 interrupt priority
    14.  
    15.     PIR2bits.TMR3IF = 0;                 //Clear Timer3 interrupt flag
    16.     PIE2bits.TMR3IE = 1;                 //Enable Timer3 interrupts
    17.     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:
    http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
     
  2. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,753
    760
    or may be ur uC is faulty.
    Just a thought.
     
  3. Vaughanabe13

    Thread Starter Active Member

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

    Senior Member

    Aug 3, 2007
    416
    17
    I don't see the master interrupt (GIE) bit being set ?
     
  5. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    Here's one of mine configs, hopefully it helps (the timer interrupt part is at the beginning):
    Code ( (Unknown Language)):
    1.  
    2. void Config(void) {
    3.    T0CON = 0b11000000;
    4.    TMR0L = 106;
    5.    INTCON = 0b11100000;
    6.  
    7.    PIE1.RCIE = 1;
    8.  
    9.    PORTA  = 0b00000000;
    10.    LATA   = 0b00000000;
    11.    CMCON  = 0b00000111;  
    12.    ADCON0 = 0b00000001;
    13.    ADCON1 = 0b00001110;  
    14.    TRISA  = 0b00011111;  
    15.    //         76543210
    16.  
    17.    PORTB  = 0b00000000;
    18.    LATB   = 0b00000000;
    19.    TRISB  = 0b00000000;
    20.    //         76543210
    21.  
    22.    UCON  = 0b00000000;  
    23.    PORTC = 0b00000000;
    24.    LATC  = 0b00000000;
    25.    TRISC = 0b00000000;      
    26.    //        76543210
    27.  
    28.    PORTD = 0b00000000;
    29.    LATD  = 0b00000000;
    30.    TRISD = 0b00000000;  
    31. }
    32.  
    Maybe you should post the rest of your code ?
     
  6. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    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...
     
  7. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    GIEL enables all interrupts that have the priority bit cleared, and GIEH does the same for interrupts that have the priority bit set
     
  8. Vaughanabe13

    Thread Starter Active Member

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

    Senior Member

    Sep 26, 2009
    2,675
    234
    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
     
    Last edited: Jun 23, 2010
  10. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5

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