Hi jeremyzhou,
how is the counter then any different from a normal Pin Change Interrupt? I wanted to use the peripheral because I have a very fast clock signal that I need to count (it's the clock base for a manchester encoding). If an interrupt is generated every time the clock signal toggles, the CPU is completely blocked as it runs on a quiet high frequency there are also other interrupts to be handled.
Something else I discovered is that the values I get from the counter in the debugger are completely false. For some reason, they are always in the range of 100000, but if I let the program run normally, it works. Very strange.
Anyway, for now I solved the problem by using the MRTimer as a Soft-PWM and the SCTimer as a counter. Here is my minimal-example:
int main(void)
{
SystemCoreClockUpdate();
Chip_SYSCTL_SetBODLevels(3, 3);
Chip_SYSCTL_EnableBODReset();
Chip_GPIO_Init(LPC_GPIO_PORT);
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 14);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 1);
Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 1);
Chip_SWM_MovablePinAssign(SWM_SCT_IN2_I, 9);
Chip_SYSCTL_SetPinInterrupt(2, 9);
Chip_SYSCTL_EnablePINTWakeup(2);
Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH2);
Chip_PININT_EnableIntLow(LPC_PININT, PININTCH2);
Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH2);
Chip_SWM_MovablePinAssign(SWM_SCT_IN1_I, 8);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT);
Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0, SCT_INP_IN1);
Chip_SCT_Init(LPC_SCT);
Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_INCLK);
Chip_SCT_ClearControl(LPC_SCT, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);
NVIC_SetPriority(PININT2_IRQn, NVIC_PRIO_RFID_DATA);
NVIC_EnableIRQ(PININT2_IRQn);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON);
Chip_MRT_Init();
LPC_MRT_CH_T *mrt = Chip_MRT_GetRegPtr(0);
Chip_MRT_SetInterval(mrt, 2550);
Chip_MRT_SetMode(mrt, MRT_MODE_REPEAT);
Chip_MRT_SetEnabled(mrt);
NVIC_SetPriority(MRT_IRQn, 4);
NVIC_EnableIRQ(MRT_IRQn);
while(1)
{
__WFI();
}
}
void MRT_IRQHandler()
{
Chip_MRT_IntClear(Chip_MRT_GetRegPtr(0));
}
void PININT2_IRQHandler()
{
Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH2);
if(LPC_SCT->COUNT_U > 48)
{
Chip_SCT_SetControl(LPC_SCT, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);
Chip_SCT_SetControl(LPC_SCT, SCT_CTRL_CLRCTR_L | SCT_CTRL_CLRCTR_H);
Chip_SCT_ClearControl(LPC_SCT, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);
Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 0, 14);
}
This is not a nice solution, but for now it works.
If anyone knows a more elegant solution for my purposes, possibly using the SCTimer, please let me know!
With kind regards,
Jan