LPC1549 SCT - two capture event interrupts do not work

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

LPC1549 SCT - two capture event interrupts do not work

1,103 Views
doini
Contributor III

Hello,

I am using the SCT1 to capture a signal on rising edge and on falling edge also. I set up 2 events with interrupts for this, and I want when it interrupts on rising edge to reset the counter. At each interrupt either on rising edge or on falling edge I want to read the counter, to have the duration between 2 rising edges and the duration between 1 rising edge and 1 falling edge (like a full period and a half period of the incoming signal).

But only the falling edge interrupt works, the other does not.

Here it is my code that does not work:

//The Setup Routine:

void SCT1_Setup(void)

{
/* Initialize */
Chip_SCT_Init (LPC_SCT1);
Chip_SCTPWM_Stop (LPC_SCT1);
Chip_SCT_Config(LPC_SCT1, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK | (1 << 10));
/* SET EVENT0 FOR CAP0 (RISING EDGE), RESET TIMER ON INTERRUPT */
LPC_SCT1->REGMODE = 0x01; //bit 0 = '1'
LPC_SCT1->EVENT[0].CTRL = (0 << 5) | (1 << 6) | (0x1 << 10) | (0x2 << 12);//(0x1 << 10) | (0 << 0)
LPC_SCT1->EVENT[0].STATE = 0x00000001;
LPC_SCT1->LIMIT = 0x00000001;
LPC_INMUX->SCT1_INMUX[1] = 0x10;
LPC_SCT1->CAPCTRL[0].U = 0x1;
Chip_SCT_EnableEventInt(LPC_SCT1, SCT_EVT_0);
/* SET EVENT1 FOR CAP1 (FALLING EDGE, SAME INPUT) */
LPC_SCT1->REGMODE = 0x02;
LPC_SCT1->EVENT[1].CTRL = (0 << 5) | (1 << 6) | (0x2 << 10) | (0x2 << 12);
LPC_SCT1->EVENT[1].STATE = 0x00000001;
LPC_SCT1->CAPCTRL[1].U = 0x2;
Chip_SCT_EnableEventInt(LPC_SCT1, SCT_EVT_1);
/* Enable the interrupt for the SCT */
NVIC_EnableIRQ (SCT1_IRQn);
Chip_SCT_ClearControl(LPC_SCT1, SCT_CTRL_HALT_L);
}
//Some global variables:
uint32_t varCounterFull = 0;
uint32_t varCounterHalf = 0;
//The ISR Routine:
void SCT1_IRQHandler(void)
{
if (LPC_SCT1->EVFLAG & SCT_EVT_0)
    {
    //if interrupt on rising edge
    Chip_SCT_ClearEventFlag(LPC_SCT1, SCT_EVT_0);
    varCounterFull = (LPC_SCT1->CAP[0].U);
    }
else if (LPC_SCT1->EVFLAG & SCT_EVT_1)
    {
    //if interrupt on falling edge
    Chip_SCT_ClearEventFlag(LPC_SCT1, SCT_EVT_1);
    varCounterHalf = (LPC_SCT1->CAP[1].U);
    }
}
/////////////////////////////////////////////////////////////////////////////
If I change my code like to take out the line
LPC_SCT1->LIMIT = 0x00000001;
from SCT1_Setup(), and re-write the ISR like that:
//The ISR Routine:
void SCT1_IRQHandler(void)
{
if (LPC_SCT1->EVFLAG & SCT_EVT_0)
    {
    //if interrupt on rising edge
    Chip_SCT_ClearEventFlag(LPC_SCT1, SCT_EVT_0);
    varCounterFull = (LPC_SCT1->COUNT_U);
    Chip_SCTPWM_Stop (LPC_SCT1);
    Chip_SCT_ClearControl(LPC_SCT1, SCT_CTRL_HALT_L);
    }
else if (LPC_SCT1->EVFLAG & SCT_EVT_1)
    {
    //if interrupt on falling edge
    Chip_SCT_ClearEventFlag(LPC_SCT1, SCT_EVT_1);
    varCounterHalf = (LPC_SCT1->CAP[1].U);
    }
}
it works.
But I think it should work with re-setting the counter automatically at EVENT0, and I do not understand why it does not work. If I stop and restart the counter inside the ISR it is not a solution, and it takes time.
I would really appreciate any help!
Thank you,
Doini
0 Kudos
Reply
0 Replies