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

LPC2378_timer1

hi all

this is how i initialize the timer1

void init_timer1(void)
{ T1MR1 = 15999999;//15990;
T1MCR = 3; T1TCR = 1;
T1CTCR = 0x00;
VICVectAddr5 = (unsigned long)T1_IRQHandler; VICVectCntl5 = 14;
VICIntEnable = (1 << 5);
}

__irq void T1_IRQHandler (void)
{ volatile unsigned int pin_status; pin_status = FIO4PIN;

if((pin_status & 0x20000000) == 0x20000000)
{ FIO4CLR |= 0x20000000;
} else
{ FIO4SET |= 0x20000000;
} }

this timer1 is not working in timer0 and timer1 i have initialized as similar
which toggles the pin every one sec.here timer0 generates the interrupt and i get the pin toggled but i have the problem with timer1 the pin doesnt toggle so i doubt tht timer1 is not initialized or its not able to generate interrupt so can any one help me to rectify the doubt i have given the code how i initialize the time and the interrupt code ...the default PCONP is set .

Regards
suresh

Parents Reply Children
  • If you expect answers, please keep your discussion in the correct thread!

    Starting a new thread wastes other peoples time, since they don't know what have already been discuessed! If that is important to you, please show that!

  • Hello Suresh Kumar,

    You must acknowledge the interrupt in your interrupt service routine.

    The following code runs on a Keil evaluation board MCB2300 and toggles the LEDs P2.0, P2.1 with 1Hz.

    /* Timer0 IRQ: Executed periodically                                          */
    __irq void T0_IRQHandler (void) {
      volatile unsigned int pin_status = FIO2PIN;
    
      if (pin_status & (1 << 0))
        FIO2CLR = (1 << 0);                 /* LED off                            */
      else
        FIO2SET = (1 << 0);                 /* LED on                             */
    
      T0IR        = 1;                      /* Clear interrupt flag               */
      VICVectAddr = 0;                      /* Acknowledge Interrupt              */
    }
    
    /* Timer1 IRQ: Executed periodically                                          */
    __irq void T1_IRQHandler (void) {
      volatile unsigned int pin_status = FIO2PIN;
    
      if (pin_status & (1 << 1))
        FIO2CLR = (1 << 1);                 /* LED off                            */
      else
        FIO2SET = (1 << 1);                 /* LED on                             */
    
      T1IR        = 1;                      /* Clear interrupt flag               */
      VICVectAddr = 0;                      /* Acknowledge Interrupt              */
    }
    
    int main (void) {
    
      PINSEL10 = 0;                         /* Disable ETM interface, enable LEDs */
      FIO2DIR  = 0x000000FF;                /* P2.0..7 defined as Outputs         */
      FIO2MASK = 0x00000000;
    
      /* Enable and setup timer interrupt, start timer                            */
      T0MR0         = 11999999;                    /* 1sec = 12000000-1 @ 12.0 MHz*/
      T0MCR         = 3;                           /* Interrupt and Reset on MR0  */
      T0TCR         = 1;                           /* Timer0 Enable               */
      VICVectAddr4  = (unsigned long)T0_IRQHandler;/* Set Interrupt Vector        */
      VICVectCntl4  = 15;                          /* use it for Timer0 Interrupt */
      VICIntEnable  = (1  << 4);                   /* Enable Timer0 Interrupt     */
    
      /* Enable and setup timer interrupt, start timer                            */
      T1MR0         = 11999999;                    /* 1sec = 12000000-1 @ 12.0 MHz*/
      T1MCR         = 3;                           /* Interrupt and Reset on MR1  */
      T1TCR         = 1;                           /* Timer0 Enable               */
      VICVectAddr5  = (unsigned long)T1_IRQHandler;/* Set Interrupt Vector        */
      VICVectCntl5  = 15;                          /* use it for Timer0 Interrupt */
      VICIntEnable  = (1  << 5);                   /* Enable Timer0 Interrupt     */
    
      while (1);                                   /* Loop forever                */
    }
    

    Best Regards,
    Martin Guenther

  • sorry i had the acknoledge statement it some how got missed it the above published code ...
    its working now the mistake was i loaded the value in TXMR1 instead of TxMR0. so when TXMR0 is loaded with the value the timer is working but y not when TxMR1,TxMR2,TxMR3 any reason to make it workable ....