Setting up the SCT for a simple match timer.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Setting up the SCT for a simple match timer.

ソリューションへジャンプ
1,491件の閲覧回数
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);
}

 

ラベル(1)
0 件の賞賛
1 解決策
1,476件の閲覧回数
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

元の投稿で解決策を見る

3 返答(返信)
1,487件の閲覧回数
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 件の賞賛
1,482件の閲覧回数
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 件の賞賛
1,477件の閲覧回数
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