lpcware

LPCXpresso (LPC1114 ) Input capture mode for measuring pulse width

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by asokfair on Tue Dec 02 03:44:04 MST 2014
Hi Everyone,

I was trying measure the pulse width using lpc1114 in capture mode but it doesn't works.

I am using 16bit Timer0 :

//init 16bit timer0
     LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);//enable clock CT16B0
    //init io CT16B0_CAP0
     LPC_IOCON->PIO0_2 = (1<<1)|(2<<3);     //CT16B0_CAP0 & pullupCAP0FE
     LPC_TMR16B0->CTCR = 0;                //use timer mode
     LPC_TMR16B0->CCR  = 5;                //rising
     LPC_TMR16B0->PR  = 47;                //prescaler 48
     NVIC_EnableIRQ(TIMER_16_0_IRQn);         //enable interrupt
     LPC_TMR16B0->TCR  = 1;                  //and run timer

Interrupt routine :

void TIMER16_0_IRQHandler(void)
{

if(LPC_TMR16B0->IR & (1<<4))            //capture interrupt?
{
  LPC_TMR16B0->TC = 0;                    //reset timer
  period_time = LPC_TMR16B0->CR0;        //read time
  LPC_TMR16B0->IR |= (1<<4);            //reset capture interrupt
}

return;
//end capture interrupt
}


I am varying the pulse with (1-100us) in P0_2 pin but the period time not changing. but i need only the pulse width value
please help me to make it work

Note:-(reading pulse from ultra sonic sensor module)

Thanks,
Ashok r

Outcomes