Setting up the SCT for a simple match timer.

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up the SCT for a simple match timer.

Jump to solution
581 Views
chrispflieger
Contributor IV

I've used up all the "good" timers on my LPC11e68, so I need to set up the SCT to do a simple match for microseconds into the future and trigger an IRQ - no repeating, PWM, output, input, etc. just a match.

The driver code seems to be missing some interfaces, because I can set the match register, and clear the counter, but I never get my interrupt.

 

static void setup_timer(void)
{
Chip_SCT_Init(LPC_SCT1);
Chip_SCT_Config(LPC_SCT1, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK);

Chip_SCT_SetPrescale(LPC_SCT1, TIMER_MICROSECONDS - 1);
NVIC_SetPriority(SCT0_1_IRQn, 2);
NVIC_ClearPendingIRQ(SCT0_1_IRQn);
NVIC_EnableIRQ(SCT0_1_IRQn);
}

static void start_timer(uint32_t match_value)
{
Chip_SCT_SetControl(LPC_SCT1, SCT_CTRL_HALT_L);
Chip_SCT_SetCount(LPC_SCT1, 0); // You can only write the count when the counter is halted.
Chip_SCT_SetMatchCount(LPC_SCT1, 0, match_value);
Chip_SCT_EnableEventInt(LPC_SCT1, SCT_EVT_0);
Chip_SCT_ClearControl(LPC_SCT1, SCT_CTRL_HALT_L);
Chip_SCT_SetControl(LPC_SCT1, SCT_CTRL_CLRCTR_L);
}

 

Labels (1)
0 Kudos
1 Solution
566 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to the an11538.pdf, which discusses the SCT module.

This is the code to generate interrupt, if you want to just generate one interrupt, you have to disable interrupt in the ISR.

void SCT_Init(void)
{
LPC_SCT->CONFIG = (1 << 0) | (1 << 17); // unified 32-bit timer, auto limit
LPC_SCT->MATCHREL[0].U = SystemCoreClock/100; // match 0 @ 100 Hz = 10 msec
LPC_SCT->EVENT[0].STATE = 0xFFFFFFFF; // event 0 happens in all states
LPC_SCT->EVENT[0].CTRL = (1 << 12); // match 0 condition only
LPC_SCT->EVEN = (1 << 0); // event 0 generates an interrupt
NVIC_EnableIRQ(SCT_IRQn); // enable SCTimer/PWM interrupt
LPC_SCT->CTRL_U &= ~(1 << 2); // unhalt by clearing bit 2 of the CTRL
}
Fig 2. Code for SCT_repetitive_irq

Hope it can help you

BR

Xiangjun Rong

View solution in original post

3 Replies
577 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Chris,

From your code, you enable the SCT_EVT_0  to generate interrupt.

Chip_SCT_EnableEventInt(LPC_SCT1, SCT_EVT_0);

But I do not see the code to generate the SCT_EVT_0 event, maybe it is missing. Pls check.

BTW, I do not see the code to define the modulo value for the counter, do you use the match0 as modulo? if it is the case, you have to use code to the set it as automatic in CONFIG reg or define another event and specify the event in LIMIT register.

Hope it can help you

BR

XiangJun Rong

0 Kudos
572 Views
chrispflieger
Contributor IV

Yes, my code (and the lpcOpen code) is missing something - that's my question, "What am I missing?"

 

I'm not sure I need a reload or modulo - I really only want this IRQ to fire once, then I'll shut it off till I need it again much later.

0 Kudos
567 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to the an11538.pdf, which discusses the SCT module.

This is the code to generate interrupt, if you want to just generate one interrupt, you have to disable interrupt in the ISR.

void SCT_Init(void)
{
LPC_SCT->CONFIG = (1 << 0) | (1 << 17); // unified 32-bit timer, auto limit
LPC_SCT->MATCHREL[0].U = SystemCoreClock/100; // match 0 @ 100 Hz = 10 msec
LPC_SCT->EVENT[0].STATE = 0xFFFFFFFF; // event 0 happens in all states
LPC_SCT->EVENT[0].CTRL = (1 << 12); // match 0 condition only
LPC_SCT->EVEN = (1 << 0); // event 0 generates an interrupt
NVIC_EnableIRQ(SCT_IRQn); // enable SCTimer/PWM interrupt
LPC_SCT->CTRL_U &= ~(1 << 2); // unhalt by clearing bit 2 of the CTRL
}
Fig 2. Code for SCT_repetitive_irq

Hope it can help you

BR

Xiangjun Rong