Timer capture interrupt issue on LPC1549

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by cbd8992 on Wed May 27 03:31:19 MST 2015

I am using the timer capture function on the LPC1549 for reading out the data of a digital KMA215 angle sensor. For calculating the value I have to detect falling edges of the output signal and with the time difference between each edge I am able to reconstruct the message.

The code for calculating the message works perfectly fine on the LPC4330 but on the LPC1549 the SCT0 just doesn't detect some falling edges. Because of this, nearly 45% of reading attempts fail. The minimum time between two falling edges is 3us and I am running the SCT with 12MHz.

I attached a picture of an oscilloscope capture where you can see the problem. The blue line is the output signal from the sensor and the red line shows the status of the pin, that I let toggle in the SCT interrupt handler for test purposes.

This is the code I used to initialize the SCT:

void SENT_init(void) {
/* reset flags */
timeout_flag = false;

Chip_GPIO_SetPinDIRInput(LPC_GPIO, 1, 6);

Chip_SCT_Config(LPC_SCT0, (SCT_CONFIG_32BIT_COUNTER)); //use a unified counter
LPC_SCT0->COUNT_U = 0;//set counter to 0

LPC_SCT0->EVEN = 0x01;//enable event 0

LPC_SCT0->REGMODE |= (1 << 0);//register 0 is a capture register
LPC_SCT0->CAPCTRL[0].U |= (1 << 0);//event 0 causes capture 0

LPC_SCT0->EVENT[0].STATE = 0xFFFFFFFF;//happens in every state

LPC_SCT0->EVENT[0].CTRL = (0 << 0) |        //use capture register 0
(0x2 << 10) |//detect falling edges
(0x2 << 12) |//use I/O condition only
(1 << 14) |//STATEV is loaded
(0 << 15);//new state: 0

Chip_INMUX_SelectSCT0Src(0, SCT0_INMUX_PIO1_6);

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


timerFreq = Chip_Clock_GetSysTickClockRate();


Chip_SCT_ClearControl(LPC_SCT0, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);//start counter

And this is the interrupt handler:


if (LPC_SCT0->EVFLAG & 0x01) {
LPC_SCT0->EVFLAG = 0x01;//Clear interrupt flag

/* read timer counter */
newCapValue = LPC_SCT0->CAP[0].U;
sentDelay = newCapValue - oldCapValue;
oldCapValue = newCapValue;

For the CAN controller initialization I have following line, if I delete it the failure rate increases to about 98%

/* Use main oscilator for rates above 100Kh */

Does anyone have any idea why the SCT misses some falling edges?