AnsweredAssumed Answered

example of LPC1837 capture timer?

Question asked by lpcware Employee on Jun 15, 2016
Latest reply on May 31, 2017 by Yuanbin Zhou
Content originally posted in LPCWare by smalouin on Mon Oct 27 06:37:05 MST 2014
Hello all,

I am trying to use the LPC1837 capture timer on port 5.0 (timer1 capture 0)... not having much luck (ie, I never get the IRQhandler for timer 1 called.

Anybody has an example that works?

Here is what I have, but it's all from scratch, I'm pretty sure an example would set me on the right track.


void rc5InterruptInit(void){
  /* Enable timer 1 clock and reset it */
   #define IR_TIMER              LPC_TIMER1
   #define IR_TIMER_IRQHANDLER   TIMER1_IRQHandler
   #define IR_TIMER_IRQn         TIMER1_IRQn

Chip_TIMER_Init(IR_TIMER);
Chip_RGU_TriggerReset(RGU_TIMER1_RST);
while (Chip_RGU_InReset(RGU_TIMER1_RST)) {}

/* Get timer 1 peripheral clock rate */
gRc5.timerFreq = Chip_Clock_GetRate(CLK_MX_TIMER1);

     
      /* Timer setup for match and interrupt at TICKRATE_HZ */
      Chip_TIMER_Reset(IR_TIMER);

      //Chip_SCU_PinMuxSet(5, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_FUNC5));/* P5.0 pin as T1_CAP0 */
      Chip_SCU_PinMuxSet(5, 0, (SCU_MODE_FUNC5));/* P5.0 pin as T1_CAP0 */
      LPC_GIMA->CAP0_IN[1][0]=00000021;
      Chip_TIMER_TIMER_SetCountClockSrc(IR_TIMER,TIMER_CAPSRC_RISING_PCLK ,0);
      Chip_TIMER_ClearCapture(IR_TIMER,0);
      //Chip_TIMER_PrescaleSet(IR_TIMER,(gRc5.timerFreq /(RC5_FREQ)));
      Chip_TIMER_PrescaleSet(IR_TIMER,0);
      Chip_TIMER_CaptureEnableInt(IR_TIMER,0);/* start the capture timer */
      Chip_TIMER_CaptureFallingEdgeEnable(IR_TIMER,0);
      Chip_TIMER_CaptureRisingEdgeEnable(IR_TIMER,0);


Chip_TIMER_Enable(IR_TIMER);
     
/* Enable timer interrupt */
NVIC_EnableIRQ(IR_TIMER_IRQn);
NVIC_ClearPendingIRQ(IR_TIMER_IRQn);
}

void TIMER1_IRQHandler (void){
  
   /* using the capture compare */
   if (Chip_TIMER_CapturePending(IR_TIMER, 0)){
      rc5TimerCaptureIrq();
   }
}

Outcomes