Timer capture examples for LPC4337

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Timer capture examples for LPC4337

1,620 Views
yuanbinzhou
Contributor II

Anyone can provide examples on how to use timer capture function on LPCXpresso 4337 platform? I cannot find any examples on lpc open library.

Labels (1)
0 Kudos
Reply
2 Replies

1,066 Views
yuanbinzhou
Contributor II

Hi Kerry Zhou,

Thanks for your reply. I have carefully read the link you have send me and I am currently using the code similar to what you have send.

#include "board.h"
#include <stdio.h>

/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/

#define TIMER_NUMBER 0
#define CAP_NUMB 0

#define LPC_TIMER LPC_TIMER0
#define RGU_TIMER_RST RGU_TIMER0_RST
#define LPC_TIMER_IRQ TIMER0_IRQn
#define LPC_TIMER_IRQH TIMER0_IRQHandler

/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/

/*****************************************************************************
* Private functions
****************************************************************************/

/*****************************************************************************
* Public functions
****************************************************************************/

/**
* @brief Handle interrupt from 32-bit timer
* @return Nothing
*/

void LPC_TIMER_IRQH (void)
{
static uint32_t times = 0;
volatile static uint32_t captureValue = 0;
/* Count how many times the interrupt has being trigger */
times++;
if(Chip_TIMER_CapturePending(LPC_TIMER,CAP_NUMB))
{
/* Get capture value on CAP0 */
captureValue = Chip_TIMER_ReadCapture(LPC_TIMER, CAP_NUMB);
if(times % 0x64 == 0){
DEBUGOUT(" times:%d\r\n", times);
DEBUGOUT(" captureValue:%d\r\n", captureValue);
}
Chip_TIMER_ClearCapture(LPC_TIMER, CAP_NUMB);
}

}

/**
* @brief main routine for blinky example
* @return Function should not exit.
*/
int main(void)
{

SystemCoreClockUpdate();
Board_Init();
DEBUGOUT("Hello World\n");

/* P1_13 as T0_CAP0, disable internal filter and enable input buffer */
//Chip_SCU_PinMuxSet(1, 13, (SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC4));
Chip_SCU_PinMux(1,13, MD_PLN_FAST, SCU_MODE_FUNC4);
/* Timer 0 CAP0 EDGE enabled and SELECT as 0x2 */
LPC_GIMA->CAP0_IN[TIMER_NUMBER][CAP_NUMB] = (1 << 2) | (2 << 4) | (1 << 1);

/* Timer0 init */
Chip_TIMER_Init(LPC_TIMER);
/* Reset timer0 */
Chip_RGU_TriggerReset(RGU_TIMER_RST);
while (Chip_RGU_InReset(RGU_TIMER_RST));

Chip_TIMER_Reset(LPC_TIMER);
/* Select PCLK as timer source */
//Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER, TIMER_CAPSRC_RISING_PCLK, CAP_NUMB);
Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER, TIMER_CAPSRC_RISING_CAPN, CAP_NUMB);
/* Select prescaler value */
Chip_TIMER_PrescaleSet(LPC_TIMER, 10);

/* Clear capture value on T0.CAP0 */
Chip_TIMER_ClearCapture(LPC_TIMER, CAP_NUMB);
/* Enable rising trigger on T0.CAP0 */
Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER, CAP_NUMB);

/* Enable interrupt */
Chip_TIMER_CaptureEnableInt(LPC_TIMER, CAP_NUMB);

/* Enable timer interrupt */
NVIC_ClearPendingIRQ(LPC_TIMER_IRQ);
NVIC_EnableIRQ(LPC_TIMER_IRQ);

/* Enable timer */
Chip_TIMER_Enable(LPC_TIMER);
while (1) {

}
return 0;
}

In the function "LPC_TIMER_IRQH", I can succeed in printing the "times" value, which is the count of my input signal. However, when using "Chip_TIMER_ReadCapture", the return values always equals to 0. How can I solve it. I think what I have setting in the code is confronted with the data sheet.

0 Kudos
Reply

1,066 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Yuanbin,

    Please refer to this post:

Configure lpc4337 timer0 as input capture 

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos
Reply