AnsweredAssumed Answered

LPC1549 input capture missing edges.

Question asked by Edriano Araujo on Jun 25, 2018
Latest reply on Jun 26, 2018 by jeremyzhou

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 ;
}

Outcomes