Dear Team,
I am working LPC4367 MCU SCT timer to read the IR Remote data.I have created init function as per AN11538 RC5 example and changed input pin to CTIN_6.
void PwmInit(void)
{
Chip_SCU_PinMuxSet(0x2, 2, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC5));
Chip_SCTPWM_Init(SCT_PWM);
SCT_PWM->CTRL_L |= (SystemCoreClock/1000000-1) << 5; // set prescaler, SCTimer/PWM clock = 1 MHz
SCT_PWM->REGMODE_L = (1 << 1) | (1 << 2); // register pair 1 and 2 are capture
SCT_PWM->MATCH[0].L = 12000; // match 0 @ 12000/1MHz = 12 msec (timeout)
SCT_PWM->MATCHREL[0].L = 12000;
SCT_PWM->EVENT[0].STATE = 0x00000001; // event 0 only happens in state 0
SCT_PWM->EVENT[0].CTRL = (0 << 0) | // MATCHSEL[3:0] = related to match 0
(1 << 12) | // COMBMODE[13:12] = uses match condition only
(1 << 14) | // STATELD [14] = STATEV is loaded into state
(0 << 15); // STATEV [15] = new state is 0
SCT_PWM->EVENT[1].STATE = 0x00000001; // event 1 only happens in state 0
SCT_PWM->EVENT[1].CTRL = (0 << 5) |
(6 << 6) | // IOSEL [9:6] = SCT_IN6
(2 << 10) | // IOCOND [11:10] = falling edge
(2 << 12) | // COMBMODE[13:12] = uses IO condition only
(1 << 14) | // STATELD [14] = STATEV is loaded into state
(0 << 15); // STATEV[ 15] = new state is 0
SCT_PWM->EVENT[2].STATE = 0x00000001; // event 2 only happens in state 0
SCT_PWM->EVENT[2].CTRL = (0 << 5) |
(6 << 6) | // IOSEL [9:6] = SCT_IN6
(1 << 10) | // IOCOND [11:10] = rising edge
(2 << 12) | // COMBMODE[13:12] = uses IO condition only
(1 << 14) | // STATELD [14] = STATEV is loaded into state
(0 << 15); // STATEV [15] = new state is 0
SCT_PWM->CAPCTRL[1].L = (1 << 1); // event 1 causes capture 1 to be loaded
SCT_PWM->CAPCTRL[2].L = (1 << 2); // event 2 causes capture 2 to be loaded
SCT_PWM->LIMIT_L = 0x0007; // events 0, 1 and 2 are used as counter limit
SCT_PWM->EVEN = 0x00000005; // events 0 and 2 generate interrupts
NVIC_EnableIRQ(SCT_IRQn); // enable SCTimer/PWM interrupt
Chip_SCTPWM_Start(SCT_PWM);
}
void SCT_IRQHandler(void) {
if(SCT_PWM->EVFLAG & SCT_EVT_0) {
timeout = 1;
SCT_PWM->EVFLAG = SCT_EVT_0;
}
if(SCT_PWM->EVFLAG & SCT_EVT_2) {
// If we have a wraparound on the counter between the rising and falling edge detection, correct the value
if (SCT_PWM->CAP[2].U < SCT_PWM->CAP[1].U)
capture[CaptureIndex++]=0xFFFFFFFF + SCT_PWM->CAP[2].U - SCT_PWM->CAP[1].U;
else
capture[CaptureIndex++] = SCT_PWM->CAP[2].U- SCT_PWM->CAP[1].U;
// Set timeout for change detected
if(CaptureIndex == 31){
CaptureIndex = 0;
RemoteFlag = 1;
}
SCT_PWM->EVFLAG = SCT_EVT_2;
}
}
I am getting only event0 interrupt every 20ms. but there there is no interrupt generating from event2.
Capturing the pulse width in the event 2 and loading into array.
Please help us resloving this issue.
Regards,
Chethan Kumar