Interrupts no longer being called.

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Feb 13, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Can anyone see what the heck I am doing wrong? This code for Timer1 interrupt used to work now it no longer interrupts :

    The chip is a Pic 18F27J53 running 8MHZ internal OSC.


    Code ( (Unknown Language)):
    1.  
    2. void main()
    3. {
    4.     TRISBbits.TRISB3 = 0;
    5.     LATBbits.LATB3 = 0;
    6.  
    7.     // 8MHZ  for 18F27J53
    8.     OSCCONbits.IRCF0 = 1;  
    9.     OSCCONbits.IRCF1 = 1;
    10.     OSCCONbits.IRCF2 = 1;
    11.  
    12.     // Set up global interrupts
    13.     RCONbits.IPEN = 1;              // Enable priority levels on interrupts
    14.     INTCONbits.GIEL = 1;            // Low priority interrupts allowed
    15.  
    16.    
    17.     IPR1bits.TMR1IP = 0;    // Timer1 is low priority interrupt  
    18.     PIE1bits.TMR1IE = 1;    // Enable interrupts for Timer 1
    19.    
    20.     //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    21.     T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    22.     T1CONbits.T1CKPS0 = 0;   // bit 4
    23.     T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    24.     T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    25.     T1CONbits.TMR1CS = 0;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    26.     TMR1H = 255;             // preset for timer1 MSB register
    27.     TMR1L = 195;             // preset for timer1 LSB register
    28.     T1CONbits.TMR1ON = 1;    // bit 0 enables timer
    29.    
    30.  
    31.     while(1);
    32.  
    33.  
    34. }
    35.  
    Here is the interrupt routine:

    Code ( (Unknown Language)):
    1.  
    2.  
    3. void InterruptServiceLow(void);
    4.  
    5.  
    6. // Low priority interrupt vector
    7. #pragma code InterruptVectorLow = 0x18
    8. void InterruptVectorLow (void)
    9. {
    10.   _asm
    11.     goto InterruptServiceLow //jump to interrupt routine
    12.   _endasm
    13. }
    14.  
    15. /** D E C L A R A T I O N S *******************************************/
    16. #pragma code    // declare executable instructions
    17.  
    18.  
    19. #pragma interruptlow InterruptServiceLow
    20. void InterruptServiceLow(void)
    21. {
    22.     int i;
    23.    
    24.     i=1;    
    25.  
    26.     // Check for Timer1 Overflow Interrupt
    27.     if  (PIR1bits.TMR1IF)
    28.     {        
    29.         i = 1;
    30.         LATBbits.LATB3 =~ LATBbits.LATB3;
    31.         TMR1H = 255;             // preset for timer1 MSB register
    32.         TMR1L = 195;             // preset for timer1 LSB register
    33.         PIR1bits.TMR1IF = 0;          // clear flag        
    34.     }
    35.  
    36. }
    37.  
    38.  
    39.  
    40.  
    I set a breakpoint in on i=1 and it never breaks there. Plus LATB3 is not being toggled though I can toggle in in a loop in my main code.
     
    Last edited: Feb 13, 2012
  2. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    BTW I know the timer is running because I have additional code that enables and displays an RTC output and the clock is indeed being updated though not accurate at all because Timer 1 interrupt is not pre loading.

    And yes I plan to add an external 32.768K xtal but just want to get it working on the internal rc for now.
     
  3. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
    Have you tried moving the timer ISR configs after the timer configuration?


    Code ( (Unknown Language)):
    1. IPR1bits.TMR1IP = 0;
    2. PIE1bits.TMR1IE = 1;
    3. INTCONbits.GIEL = 1;
    4.  
    5. while(1);
     
  4. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Tried that and it doesn't work. I have never had to do that before.

    I'm going to build a new project with just some test code for the timer interrupt.

    Is there any chance something happened to the Pic where the interrupts are permanently disabled but everything else works???
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I would seriously doubt that.
     
  6. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    I'm not seeing the Global Interrupt Enable bit, INTCON.7, getting set. Is it in there somewhere?
     
  7. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Oh rats! I can't believe I did not see that! Thanks!

    But now I am back to my original problem. Something (with my full code) is turning interrupts back off again. I was messing with then code to figure that one out and accidentally removed the Global interrupt setting.

    Now I need to go back and figure out what is turning off interrupts. I think it is the UART library.
     
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
    It's always the small things that get you. One of things I really like about MPLABX is the version control modules that keep track of all code changes.
    Making a standard framework of subroutines for processor types that splits the module configuration bits from the interrupt configuration bits helps keep things organized.
     
Loading...