Configure lpc4337 timer0 as input capture

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Configure lpc4337 timer0 as input capture

1,304件の閲覧回数
matiasalvarez
Contributor I

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
タグ(3)
0 件の賞賛
返信
2 返答(返信)

825件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Matias Alvarez,

About your demo, using the following the code to replace the "  Chip_SCU_PinMuxSet(IC_SCU_PORT, IC_SCU_PIN,  SCU_MODE_FUNC4);"

Chip_SCU_PinMux(IC_SCU_PORT,IC_SCU_PIN, MD_PLN_FAST, SCU_MODE_FUNC4);

I've also create a demo for LPCXpresso4337 board which toggles the P1.5 in the Timer1 interrupt and set the P1.12 work as the T0_CAP1 to receive the PWM wave.

When testing the demo, use a wire connect the P1.5 and P1.12, and after enter into the Timer0 interrupt, it will toggle the blue led (Fig 1).

673834818286369845.jpg

Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

825件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi,

Just recommend, I'm working now and I will inform ASAP if I figure the root cause of the issue.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信