LPC1768 Capture event

Showing results for 
Search instead for 
Did you mean: 

LPC1768 Capture event

Contributor II

In my project, 

trying to configure a timer that runs with a clock with the 1 µs resolution.
Then set CCR to capture rising and falling edges and generate an event. In the ISR, I need to check the input pin if a falling or rising edge occured. On a falling edge, save contents of the CR (capture register) and send it through UART. Same On a rising edge, save CR send it through UART.
But the issue, am not able to enter in ISR.
I appreciate your suggestions. Please find the attached code.

Original Attachment has been moved to: main.c.zip

Tags (2)
2 Replies

NXP TechSupport
NXP TechSupport

Hi ramana madishetty,

    1. About the capture code,

   You can refer to this code:

#define LED     (1 << 22)

void TIMER0_IRQHandler(void)
 uint32_t reg_val;
 reg_val = LPC_TIM0->IR;
 if(reg_val & (1<<4))            //CR0 interrupt
  if(LPC_GPIO1->FIOPIN & (1<<26))//high?
  LPC_TIM0->IR = (1<<4);        //reset interrupt

int main(void)
 LPC_GPIO0->FIODIR |= LED;        //LED output
 volatile static int i = 0 ;
//setup timer 0 capture
//Setup P1.26 as CAP0.0
 LPC_PINCON->PINSEL3 |= (3<<20);    //set capture 0.0
//Note: reset values of timer registers are 0, so setting them isn't necessary
 LPC_TIM0->CCR =((1<<0)|(1<<1)|(1<<2));        //capture rising & falling with interrupt
 LPC_TIM0->TCR = 1;                //start timer
  i++ ;
 return 0 ;

I have test it on my side(lpcxpress 1769 board), the ISR can be entered, the capture function works OK.

I also attached the .c file which can be used in the lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769 timer project directly.

I think you can let the capture ISR work at first, then add the UART code.

You can debug the code, and add the breakpoint in TIMER0_IRQHandler, when the external signal put in p1.26, rising or falling, whether the ISR breakpoint can be entered?

2. About the UART printf.

   I don't recommend you add UART printf in the ISR directly, as you know, printf will consume a long time, you can define a flag, and when the IRQ happens, set that the flag, then in the main while to check this flag, and printf the UART data.

   In the IRQ function, the code should as short as possible, otherwise, the other capture event will be lost.

Wish it helps you!

Have a great day,

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

Contributor II

Thanks for your reply Kerry. Will try and let you know

0 Kudos