This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PROBLEM IN TIMER MATCH REGISTER INTERRUPT.

hi,
I have written code that generate Interrupt on Timer-0 match.(LPC2138)
But problem is that when I debuge the code in Keil Complier it does not go to ISR.
I aslo use the Sample code from keil that genrate interrupt on Timer match.But that aslo give same problem.
Does it need to change Start up code before you write code for Interrupt.

Below I have given code that I hvae written.

#include<LPC21xx.H>

void T0isr(void) __irq;

unsigned int x;

int main(void)
{ IO0DIR=0XFFFFFFFF;
T0TCR=0X00000000 //TIMER0 COUNTER DISABLE
T0TC=0X00000000; //TIMER0 COUNTER SET TO 0
T0PR=0X00000001; //PRESCLAR FOR TIMER0 SET TO 1
T0PC=0X00000000; //PRESCLAR COUNTER FOR TIMER0 SET 0
T0MCR=0X00000003; //MR0 SET TO RESET AND GENERATE INT
T0EMR=0X00000000; //MRO SET DO NOTHING ON MATCH
T0MR0=0XFFFF; //MR0 SET 0XFFFF

VICVectAddr4 = (unsigned)T0isr; //Set the timer ISR vector address

VICVectCntl4 = 0x00000024; //Set channel

VICIntEnable = 0x00000010; //Enable the TIMER-0 interrupt

T0TCR=0X00000001; //TIMER0 COUNTER ENABLE

for(;;);

}

void T0isr (void) __irq
{ T0TCR=0X00000000; //TIMER0 COUNTER DISABLE
IO0PIN=0XFFFFFFFF; //HIGH THE OUTPUT
for(x=0;x<10000;x++); // DELAY
IO0PIN=0X00000000; //LOW THE OUTPUT
for(x=0;x<10000;x++); // DELAY
T0IR= 0x00000001; //Clear match 0 interrupt
VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

T0TCR=0X00000001; //TIMER0 COUNTER ENABLE
}

Parents
  • Hello AMOGH PRABHULKAR,

    it is not necessary to change the startup code.
    Be aware that interrupts are disabled during debugging with single steps. It is better to set a breakpoint inside the interrupt function and then perform a GO command.

    Below is your modified code which works on a Keil MCB2130 board and also in uVision Simulation.

    #include <LPC213x.H>              // LPC213x definitions
    
    unsigned int x = 0;
    
    __irq void T0isr (void) {
      x ^= 1;
    
      if (x)
        IOSET1 = 1UL << 16;           // switch LED on
      else
        IOCLR1 = 1UL << 16;           // switch LED off
    
      T0IR        = 0x00000001;       // Clear match 0 interrupt
      VICVectAddr = 0x00000000;       // Dummy write to signal end of interrupt
    }
    
    int main(void) {
      IODIR1  = 0x00FF0000;           // P1.16..23 defined as Outputs (LEDs)
      IOCLR1  = 0x00FF0000;           // Turn LEDs off
    
    
      T0TCR  = 0x00000000;            // TIMER0 COUNTER DISABLE
      T0PR   = 0x00000080;            // PRESCLAR FOR TIMER0
      T0MCR  = 0x00000003;            // MR0 SET TO RESET AND GENERATE INT
      T0MR0  = 0xFFFF;                // MR0 SET 0XFFFF
    
      VICVectAddr4 = (unsigned)T0isr; // Set the timer ISR vector address
      VICVectCntl4 = 0x00000024;      // Set channel
      VICIntEnable = 0x00000010;      // Enable the TIMER-0 interrupt
    
      T0TCR = 0x00000001;             // TIMER0 COUNTER ENABLE
    
      for(;;);
    }
    

    Best Regards,
    Martin Guenther

Reply
  • Hello AMOGH PRABHULKAR,

    it is not necessary to change the startup code.
    Be aware that interrupts are disabled during debugging with single steps. It is better to set a breakpoint inside the interrupt function and then perform a GO command.

    Below is your modified code which works on a Keil MCB2130 board and also in uVision Simulation.

    #include <LPC213x.H>              // LPC213x definitions
    
    unsigned int x = 0;
    
    __irq void T0isr (void) {
      x ^= 1;
    
      if (x)
        IOSET1 = 1UL << 16;           // switch LED on
      else
        IOCLR1 = 1UL << 16;           // switch LED off
    
      T0IR        = 0x00000001;       // Clear match 0 interrupt
      VICVectAddr = 0x00000000;       // Dummy write to signal end of interrupt
    }
    
    int main(void) {
      IODIR1  = 0x00FF0000;           // P1.16..23 defined as Outputs (LEDs)
      IOCLR1  = 0x00FF0000;           // Turn LEDs off
    
    
      T0TCR  = 0x00000000;            // TIMER0 COUNTER DISABLE
      T0PR   = 0x00000080;            // PRESCLAR FOR TIMER0
      T0MCR  = 0x00000003;            // MR0 SET TO RESET AND GENERATE INT
      T0MR0  = 0xFFFF;                // MR0 SET 0XFFFF
    
      VICVectAddr4 = (unsigned)T0isr; // Set the timer ISR vector address
      VICVectCntl4 = 0x00000024;      // Set channel
      VICIntEnable = 0x00000010;      // Enable the TIMER-0 interrupt
    
      T0TCR = 0x00000001;             // TIMER0 COUNTER ENABLE
    
      for(;;);
    }
    

    Best Regards,
    Martin Guenther

Children