Capture problem with SCT on LPC824

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

Capture problem with SCT on LPC824

1,790 Views
remco2
Contributor I

Hi,

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:

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
 
//Enable the SCT Timer for PWM and RC-5 decoder
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT);
Chip_SCT_Init(LPC_SCT);
//Configure the input pin for input 0
Chip_SWM_MovablePinAssign(SWM_SCT_IN0_I, 17);
Chip_INMUX_SetSCTInMux(LPC_INMUX,SCT_INMUX_0,SCT_INP_IN0);
//Regs 2 and 3 are capture, reg 4 is match (0,1 are in use by the L counter as match regs for PWM)
LPC_SCT->REGMODE_H=(1<<2)|(1<<3);
//Set the capture regs to capture on the events
LPC_SCT->CAPCTRL[2].H=(1<<2);
LPC_SCT->CAPCTRL[3].H=(1<<3);
//Set the match reg for the timeout
LPC_SCT->MATCH[4].H=2*MAX_FULL_BIT;
LPC_SCT->MATCHREL[4].H=2*MAX_FULL_BIT;
//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->EVEN=(1<<3)|(1<<4);

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...

Regards,

Remco Poelstra

Labels (2)
Tags (3)
0 Kudos
Reply
5 Replies

1,338 Views
remco2
Contributor I

Hi,

Thanks! I'll check it out!

Regards,

Remco Poelstra

0 Kudos
Reply

1,338 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Remco Poelstra,

    You are welcome.

   Please check it at first, any question, just let me know!


Have a great day,
Kerry

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

0 Kudos
Reply

1,338 Views
athmesh_n
Contributor IV

Hi kerryzhou‌,

How can we count the frequency using capture, my capture is working. What is the basic of Timer Capture

0 Kudos
Reply

1,338 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi ATHMESH NANDAKUMAR,

    Capture will get the counter, then use the counter can calculate the frequency, as you know, each counter time is you own defined.

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos
Reply

1,338 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Remco Poelstra,

    I share a LPC824 SCT capture code with you.

    You can find it from the attachment.

   This code has been test on my side, the captured data is changing.

   Please check my attached project, this is the test result on my side:

pastedImage_1.png

Wish it helps you!


Have a great day,
Kerry

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