AnsweredAssumed Answered

Capture problem with SCT on LPC824

Question asked by Remco Poelstra on Apr 4, 2017
Latest reply on Jan 17, 2019 by Kerry Zhou



I'm trying to use the SCT for decoding the RC-5 (remote control) protocol.

I've configured the SCT to count the low and high bit times, using an input pin and two events. Unfortunately, in my interrupt handling code, the captured times are often (not always) reported to be 0. If they are non-zero they usually have a value that can be expected. Any help would be highly appreciated.


I've added a drawing of a shorted RC-5 pulse train and where I expect the events.

Event 2 is configured to capture on a rising edge, start the counter and limit the counter

Event 3 is configured to capture on a falling edge, limit the counter and request an interrupt

Event 4 is configured to stop and limit the counter after a match condition (to catch a timeout).


My configuration is as follows:

//Enable the SCT Timer for PWM and RC-5 decoder
//Configure the input pin for input 0
Chip_SWM_MovablePinAssign(SWM_SCT_IN0_I, 17);
//Regs 2 and 3 are capture, reg 4 is match (0,1 are in use by the L counter as match regs for PWM)
//Set the capture regs to capture on the events
//Set the match reg for the timeout
//Configure the events
LPC_SCT->EV[2].CTRL=(1<<4) | (0x1 << 10) | (0x2 << 12); //Select H timer, Rising input only
LPC_SCT->EV[3].CTRL=(1<<4) | (0x2 << 10) | (0x2 << 12); //Select H timer, falling input only
LPC_SCT->EV[4].CTRL=(4) | (1<<4) | (0x1 << 12); //Select H timer, match reg 4 only
//Enable the events in state 0 (the only state used)
LPC_SCT->EV[2].STATE=0x1; //Enable in state 0
LPC_SCT->EV[3].STATE=0x1; //Enable in state 0
LPC_SCT->EV[4].STATE=0x1; //Enable in state 0
//Configure the start, stop and limit behaviour
LPC_SCT->LIMIT_H=(1<<2)|(1<<3))|(1<<4); //All events limit
LPC_SCT->START_H=(1<<2); //Start when a rising edge is detected
LPC_SCT->STOP_H =(1<<4); //Stop after the timeout
//Enable the interrupts

LPC_SCT->CTRL_H = (31<<5) | 0x2; //Divide by 32 for microsecond resolution, set counter in stop mode

The interrupt code is as follows:
void SCT_IRQHandler(void) {
    if (LPC_SCT->EVFLAG&SCT_EVT_4) {
       //Timeout, check received bits
       Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_4);
    } else {
        Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_3);
        int lowTime=LPC_SCT->CAP[2].H;
        int highTime=LPC_SCT->CAP[3].H;

      //Do actual decoding of bit(s). But lowTime and highTime are often 0....



In the debugger the capture registers are never 0, but between the time the breakpoint is hit and the IDE is updated, a lot of additional events occur I assume...

I've no idea on how to proceed from here...




Remco Poelstra