AnsweredAssumed Answered

Configure lpc4337 timer0 as input capture

Question asked by Matias Alvarez on Oct 7, 2016
Latest reply on Oct 11, 2016 by jeremyzhou

Hello, i'm trryng to configure lpc4337 timer0 as input capture to capture both rising and falling edges. It's still not working. Can you help me?. Here is my code:

 

#define TIMER_NUMBER           0
#define CAP_NUMB                    3
#define TIMER0_PRESCALER   10
#define IC_SCU_PORT               1
#define IC_SCU_PIN                   17            
#define LPC_TIMER                  LPC_TIMER0
#define RGU_TIMER_RST        RGU_TIMER0_RST 
#define LPC_TIMER_IRQ          TIMER0_IRQn
#define INPUT                            0
#define OUTPUT                        1
#define ON                                  1
#define OFF                                0
volatile uint8_t STATUS=0;
__attribute__ ((section(".after_vectors")))
void TIMER0_IRQHandler(void){
   
   if (STATUS == 0)
         STATUS=1;
   else
         STATUS=0;
   
}
int main(void)
{
   
   SystemCoreClockUpdate();
   ledConfig();
   
   Chip_SCU_PinMuxSet(IC_SCU_PORT, IC_SCU_PIN,  SCU_MODE_FUNC4);
   Chip_TIMER_Init(LPC_TIMER);
   LPC_GIMA->CAP0_IN[TIMER_NUMBER][CAP_NUMB] = (1<<4);
   Chip_RGU_TriggerReset(RGU_TIMER_RST);
    
   while (Chip_RGU_InReset(RGU_TIMER_RST)); 
    Chip_TIMER_Reset(LPC_TIMER); 
    Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER, TIMER_CAPSRC_RISING_PCLK, CAP_NUMB); 
 
    Chip_TIMER_PrescaleSet(LPC_TIMER, TIMER0_PRESCALER);
    Chip_TIMER_ClearCapture(LPC_TIMER, CAP_NUMB);
    Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER, CAP_NUMB);
    Chip_TIMER_CaptureFallingEdgeEnable (LPC_TIMER, CAP_NUMB );
    Chip_TIMER_CaptureEnableInt(LPC_TIMER, CAP_NUMB);
    
    NVIC_ClearPendingIRQ(LPC_TIMER_IRQ);
    NVIC_EnableIRQ(LPC_TIMER_IRQ);
    Chip_TIMER_Enable(LPC_TIMER);
     while(1) {
          ledSet(STATUS);
      }
    return 0;
}
Thank you, Matias

Outcomes