LPC4367 SCT input Event Interrupt issue

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC4367 SCT input Event Interrupt issue

149 Views
Contributor I

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

 

 

0 Kudos
5 Replies

135 Views
NXP TechSupport
NXP TechSupport

Hi, Chethan,

I think your SCT code is correct, but I do not see you initialize the SCT CTIN_6 capture input multiplexer, if you set the EDGE bit in the SCT CTIN_6 capture input multiplexer, what is the result?

Pls refer to the section 18.4.23 SCT CTIN_6 capture input multiplexer (CTIN_6_IN) in the UM10503.pdf.

Hope it can help you

BR

XiangJun Rong

 

0 Kudos

122 Views
Contributor I

Hi XiangJun Rong,

Thank you for your response.

I have added GIMA CTIN in the intialization but in the document it is showing for CTIN_6 GIMA output is 22, i don't know where i need to initialize this value.

Still i am not getting the interrupt.

Can you please help us?

Do you have any example code for the same?

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
LPC_GIMA->CTIN_IN[6] = (0 << 0) | // GIMA input mux CTIN6 selected as non inverted
(1 << 1) | // GIMA input mux CTIN6 selected as rising edge
(1 << 2) | // Synchronization is enabled
(0 << 3) | // Disable pulse generation.
(0 << 4); // Selected CTIN_6 as input

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);

 

Best Regards,

Chethan Kumar

0 Kudos

96 Views
NXP TechSupport
NXP TechSupport

Hi, Kumar,

I am sorry for the delay.

 because you do not use the state mechanism, how about setting all the state register you have used as 0xFFFF and have a try?

SCT_PWM->EVENT[2].STATE = oxFFFF; // event 2 only happens in state 0

BTW,pls refer to the ticket:

https://community.nxp.com/t5/LPC-Microcontrollers/Capture-problem-with-SCT-on-LPC824/m-p/646482#M255...

 

 

BR

XiangJun Rong

 

0 Kudos

89 Views
Contributor I

Hi XiangJun Rong,

I have changed state also, there is no changes.

Please see attached file for your reference.

 

Can you please try once ?

 

Regards,

Chethan Kumar

0 Kudos

61 Views
NXP TechSupport
NXP TechSupport

Hi,

Because I have not LPC4367 board, I develop code based on your original code, it works fine on my LPC55S69 board.

I copy the code, pls modify your code.

BR

XiangJun Rong

void PwmInit(void)
{

//set PIO0_5 as SCT trigger signal
//set PIO0_5 as P0_5/FC4_RXD_SDA_MOSI/CT3MAT0/SCT_GPI5(Func 4)
//enable IOCON bit
SYSCON->AHBCLKCTRLX[0]|=1<<13;
IOCON->PIO[0][5]=0x104;

//enable gated clock for MUX
//P0_5(SCT_GPI5) is routed to SCT0_INPUT3 signal
SYSCON->AHBCLKCTRLX[0]|=1<<11;
INPUTMUX->SCT0_INMUX[3]=5;


//enable SCT0 gated clock
SYSCON->AHBCLKCTRLX[1]|=1<<2;

SCT0->CTRL |= (SystemCoreClock/1000000-1) << 5; // set prescaler, SCTimer/PWM clock = 1 MHz
SCT0->CONFIG|=1<<0|1<<17;
SCT0->REGMODE = (1 <<2); // register pair 1 and 2 are capture
SCT0->MATCH[0]= 12000; // match 0 @ 12000/1MHz = 12 msec (timeout)
SCT0->MATCHREL[0] = 12000;
SCT0->EV[0].STATE = 0xFFFF; // event 0 only happens in state 0
SCT0->EV[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
SCT0->EV[1].STATE = 0xFFFF; // event 1 only happens in state 0
SCT0->EV[1].CTRL = (0 << 5) |
(3 << 6) | // IOSEL [9:6] = SCT_IN3
(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
#if 0
SCT0->EV[2].STATE = 0xFFFF; // event 2 only happens in state 0
SCT0->EV[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
#endif
SCT0->CAPCTRL[2] = (1 << 1); // event 1 causes capture 0 to be loaded
//SCT0->CAPCTRL[2] = (1 << 2); // event 2 causes capture 2 to be loaded
SCT0->LIMIT=0x00;
//SCT0->LIMIT = 0x0007; // events 0, 1 and 2 are used as counter limit
SCT0->EVEN = 0x02; // events 0 and 2 generate interrupts
//NVIC_EnableIRQ(SCT_IRQn); // enable SCTimer/PWM interrupt
//Chip_SCTPWM_Start(SCT_PWM);
//SCT0 interrupt vector is 12

NVIC->ISER[0]|=1<<12;
NVIC->ICPR[0]|=1<<12;
NVIC->IPR[12]=0x00;
//start SCT0
SCT0->CTRL&=~(1<<2);

}
uint32_t capture_Value;
void SCT0_DriverIRQHandler(void)
{
if(SCT0->EVFLAG&0x02)
{
SCT0->EVFLAG|=0x02;
//toggle LED0
capture_Value=SCT0->CAP[2];
//GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u << BOARD_LED_PIN);
GPIO->NOT[1]=1<<4;
__asm("nop");
}
}

0 Kudos