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 decoderChip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT);Chip_SCT_Init(LPC_SCT);//Configure the input pin for input 0Chip_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 eventsLPC_SCT->CAPCTRL[2].H=(1<<2);LPC_SCT->CAPCTRL[3].H=(1<<3);//Set the match reg for the timeoutLPC_SCT->MATCH[4].H=2*MAX_FULL_BIT;LPC_SCT->MATCHREL[4].H=2*MAX_FULL_BIT;//Configure the eventsLPC_SCT->EV[2].CTRL=(1<<4) | (0x1 << 10) | (0x2 << 12); //Select H timer, Rising input onlyLPC_SCT->EV[3].CTRL=(1<<4) | (0x2 << 10) | (0x2 << 12); //Select H timer, falling input onlyLPC_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 0LPC_SCT->EV[3].STATE=0x1; //Enable in state 0LPC_SCT->EV[4].STATE=0x1; //Enable in state 0//Configure the start, stop and limit behaviourLPC_SCT->LIMIT_H=(1<<2)|(1<<3))|(1<<4); //All events limit
LPC_SCT->START_H=(1<<2); //Start when a rising edge is detectedLPC_SCT->STOP_H =(1<<4); //Stop after the timeout//Enable the interruptsLPC_SCT->EVEN=(1<<3)|(1<<4);LPC_SCT->CTRL_H = (31<<5) | 0x2; //Divide by 32 for microsecond resolution, set counter in stop mode
voidSCT_IRQHandler(void) {if(LPC_SCT->EVFLAG&SCT_EVT_4) {//Timeout, check received bitsChip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_4);}else{Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_3);intlowTime=LPC_SCT->CAP[2].H;inthighTime=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
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!
-----------------------------------------------------------------------------------------------------------------------
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!
-----------------------------------------------------------------------------------------------------------------------
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:
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------