look 4 sample code to measure signal timing

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

look 4 sample code to measure signal timing

725 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattes on Tue Feb 25 15:49:01 MST 2014
I need to measure the pulse length of a signal with a timer. According to the LPC11U1x product data sheet,
it is possible to do this with 'clearing' the timer on leading edge and capture the timer value on trailing edge.

Is there a code sample that describe how to do that?
I looked at all the sample code to no avail

any hints
Labels (1)
0 Kudos
Reply
3 Replies

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattes on Thu Mar 06 12:31:42 MST 2014
Here some sample code that works with lpcopen2.x, tested with lpc11u14 cpu:


void TIMER16_0_IRQHandler(void)
{
   if (Chip_TIMER_CapturePending( LPC_TIMER16_0, 0 )) {          //capture interrupt?      
      LPC_TIMER16_0->TC = 0;                                                        //reset timer  
      period = Chip_TIMER_ReadCapture( LPC_TIMER16_0, 0 );    //save counter CR0
      Chip_TIMER_ClearCapture( LPC_TIMER16_0, 0 );                  //reset capture interrupt
   }
}

   //
   // setup timer16_0  with counting milliseconds
   //   generate interrupt on falling edge at PIO0_2
   //
   Chip_TIMER_Init(LPC_TIMER16_0);                                // enable clock timer16_0
   Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 2,                    // CT16B0_CAP0 & pullup (pio2_2)
                (IOCON_FUNC2 | IOCON_MODE_PULLUP) ); 
   Chip_TIMER_TIMER_SetCountClockSrc( LPC_TIMER16_0,    // use timer mode
               TIMER_CAPSRC_RISING_PCLK, 0 );
   Chip_TIMER_CaptureFallingEdgeEnable( LPC_TIMER16_0, 0 );   // set falling edge
   Chip_TIMER_CaptureEnableInt( LPC_TIMER16_0, 0 );   // set interrupt for pio0_2
   Chip_TIMER_PrescaleSet( LPC_TIMER16_0, 47999 );   // prescaler 48000, milliseconds
   Chip_TIMER_Enable(LPC_TIMER16_0);                         // enable timer start counting

   NVIC_ClearPendingIRQ(TIMER_16_0_IRQn);
   NVIC_EnableIRQ(TIMER_16_0_IRQn);                            //enable interrupt



0 Kudos
Reply

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mattes on Tue Feb 25 17:27:54 MST 2014

Quote: LabRat

Quote: mattes
any hints



Forum search?

http://www.lpcware.com/content/forum/lpc1114-my-isr-using-timer16-on-lpcxpresso



Thank you very much let me look into that
0 Kudos
Reply

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Feb 25 15:59:41 MST 2014

Quote: mattes
any hints



Forum search?

http://www.lpcware.com/content/forum/lpc1114-my-isr-using-timer16-on-lpcxpresso
0 Kudos
Reply