LPC1549 input capture missing edges.

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

LPC1549 input capture missing edges.

885 Views
Edrianocarlos
Contributor IV

Hello.

I am new to this LPC world.

And i am trying to configure the input capture timer, right now i am injecting a 1HZ and at fist glance the code was working. as i could see the led toggling every time i got int to the interrupt.

but when measuring the time i could see that sometimes i was getting double of it was supposed to be. and seing the led it indeed is missing some pulses.

Could you take a look and see am i doing anything wrong?

void SCT0_IRQHandler(void)
{

if (SCT_CAP->EVFLAG & SCT_EVT_0)
{
frequencia2 = SCT_CAP->CAP[0].U;
Chip_SCT_SetClrControl(SCT_CAP, SCT_CTRL_HALT_L,ENABLE);
SCT_CAP->COUNT_U = 0;
Chip_SCT_SetClrControl(SCT_CAP, SCT_CTRL_HALT_L, DISABLE);
frequencia2s[contador] = frequencia2;
frequencia2 = 0;
++contador;
if (contador > 19)
{
// Board_LED_Toggle(1);
contador = 0;
}


Board_LED_Toggle(2);

Chip_SCT_ClearEventFlag(SCT_CAP, SCT_EVT_0);

}else
{
Board_LED_Toggle(1);
}


}

void init_timer(void)
{

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_MODE_PULLDOWN));

Chip_SCT_Init(SCT_CAP);
Chip_SCT_Config(LPC_SCT0,SCT_CONFIG_32BIT_COUNTER+SCT_CONFIG_CLKMODE_BUSCLK+SCT_CONFIG_NORELOADL_U );

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
/* Use PIO0_15 as CTIN_0 */
// Chip_SWM_MovablePinAssign(SWM_CTIN_0_I, GPIO_CAPTURE);

/* Configure the SCT as a 32bit counter using the bus clock */
Chip_SCT_Config(SCT_CAP, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK);

/* The match/capture REGMODE defaults to capture mode */
SCT_CAP->REGMODE_L = 1;
SCT_CAP->REGMODE_H = 1;

LPC_INMUX->SCT0_INMUX[0] = 2;//SCT0_IN0 = P0IO_17

/* Enable an Interrupt on the Capture Event */
Chip_SCT_EnableEventInt(SCT_CAP, SCT_EVT_0);

/* event 0 is causing capture 0 */
SCT_CAP->CAPCTRL[0].U = SCT_EVT_0;


/* setup channel 0 capture event */
/* use CTIN_0, Rise, I/O condition only */
SCT_CAP->EVENT[0].CTRL = 0x00006400;
/* event happens in all states */
SCT_CAP->EVENT[0].STATE = 0xFFFFFFFF;

//SCT_CAP->LIMIT = 0X7FFFFFFF;

/* Enable the IRQ for the SCT */
NVIC_EnableIRQ(SCT_IRQn);
SCT_CAP->COUNT_U = 0;
frequencia2= 0;
frequencia = 0;

/* Unhalt the counter to start */
Chip_SCT_SetClrControl(SCT_CAP, SCT_CTRL_HALT_L, DISABLE);


}

int main(void)
{

sys_init();
Ini_Mux();
contador = 0;
init_timer();

while(1)
{
}
return 0 ;
}

Labels (1)
0 Kudos
2 Replies

699 Views
Edrianocarlos
Contributor IV

Ok.

I have found the problem.

Chip_SCT_Config(SCT_CAP,(SCT_CONFIG_32BIT_COUNTER |SCT_CONFIG_CLKMODE_BUSCLK | SCT_CONFIG_NORELOADL_U |  (1<<9)));

INSYNC needs to be set, i had tried it before and didn`t work, when i saw in my code that i was configuring CONFIG  register twice and INSYNC configured before were being lost.

0 Kudos

699 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Edriano Araujo,
Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.
I'm glad to hear you found the problem, If you have any further questions about it, please feel free to contact me.
Have a great day,
TIC

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

0 Kudos