lpcware

lpc1343 Capture Concern :(

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by ub3r on Sun Jul 08 03:06:28 MST 2012
Greetings,

Ive set up the capture on the 1343 like so:


LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);//enable clock CT16B0
//init io CT16B0_CAP0
LPC_IOCON->PIO0_2 = (1<<1)|(2<<3);     //CT16B0_CAP0 & pullup

LPC_TMR16B0->CTCR = 0;                //use timer mode
LPC_TMR16B0->CCR  = (1<<2)|(1<<0);          //rising, interrupt
RISING = 1;

LPC_TMR16B0->PR  = 71;                //prescaler 71
NVIC_EnableIRQ(TIMER_16_0_IRQn);         //enable interrupt
LPC_TMR16B0->TCR  = 1;   



Basically i want to read the input pulse width. Ranges from 1000us to 2000us.

My capture interrupt is below:

//read width
void TIMER16_0_IRQHandler(void)
{
if(LPC_TMR16B0->IR & (1<<4))            //capture interrupt?
{
LPC_TMR16B0->IR |= (1<<4);            //reset capture interrupt

if(RISING)//Rising Edge
{
LPC_TMR16B0->TC = 0;                    //reset timer
LED_ON;

LPC_TMR16B0->CCR  = (1<<2)|(1<<1);             //falling
RISING = 0;
}

else//Falling Edge
{
P_WIDTH = LPC_TMR16B0->CR0;        //read time
LED_OFF;

LPC_TMR16B0->CCR  = (1<<2)|(1<<0);             //rising
RISING = 1;
}
}                                         //end capture interrupt
}


Basically, on the rising interrupt im clearing the timer, and on the falling interrupt I'm capturing the timer value in P_WIDTH.

My only concern is if the interrupt is delayed due to some other interrupt, TC wont be cleared exactly on the rising edge, and I will have a slight inaccuracy, which i don't want.

How can i overcome this??

Outcomes