lpcware

problem using two input capture

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by eplant_lab on Mon Jan 18 04:34:50 MST 2016
Hello, we have an application in which we have to monitor two signals ( square wave ), using a LPC1765
If the signal is present we have to detect the frequency. 
we use input capture pin CAP1.0 and CAP1.1. We use TIMER1 for CAP1.0 and TIMER2 for CAP1.1.

these are the TIMER init functions


void TIMER1_Init(void) {

NVIC_DisableIRQ(TIMER1_IRQn);
NVIC_ClearPendingIRQ(TIMER1_IRQn);

Chip_TIMER_Init(LPC_TIMER1);
Chip_TIMER_Reset(LPC_TIMER1);

Chip_TIMER_PrescaleSet(LPC_TIMER1, (uint32_t) TIMER1_PRESCALE);

Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER1, CAP_0);
Input1CaptureEdge = RISING_EDGE;

Chip_TIMER_CaptureEnableInt(LPC_TIMER1, CAP_0);

Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);
Chip_TIMER_SetMatch(LPC_TIMER1, 1, DETECT_TIME);
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);

Chip_TIMER_Enable(LPC_TIMER1);
NVIC_SetPriority(TIMER1_IRQn, 5);
NVIC_EnableIRQ(TIMER1_IRQn);

}


void TIMER2_Init(void) {

NVIC_DisableIRQ(TIMER2_IRQn);
NVIC_ClearPendingIRQ(TIMER2_IRQn);

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_TIMER2);

Chip_TIMER_Init(LPC_TIMER2);
Chip_TIMER_Reset(LPC_TIMER2);

Chip_TIMER_PrescaleSet(LPC_TIMER2, (uint32_t) TIMER2_PRESCALE);

Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER2, CAP_1);
Chip_TIMER_ClearCapture(LPC_TIMER2, CAP_1);

Chip_TIMER_CaptureEnableInt(LPC_TIMER2, CAP_1);

Chip_TIMER_MatchEnableInt(LPC_TIMER2, 2);
Chip_TIMER_SetMatch(LPC_TIMER2, 2, DETECT_TIME);
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER2, 2);

Chip_TIMER_Enable(LPC_TIMER2);
NVIC_SetPriority(TIMER2_IRQn, 5);
NVIC_EnableIRQ(TIMER2_IRQn);
}





and these the interrupt routines

void TIMER1_IRQHandler(void) {

if (Chip_TIMER_CapturePending(LPC_TIMER1, CAP_0))   // if a rising edge on CAP1.0 is detected
{
//do something
Chip_TIMER_ClearCapture(LPC_TIMER1, CAP_0);
}

else if (Chip_TIMER_MatchPending(LPC_TIMER1, 1)) {  // if no rising edge is detected for DETECT_TIME
//do something
Chip_TIMER_ClearMatch(LPC_TIMER1, 1);
}
}

void TIMER2_IRQHandler(void)
{
if (Chip_TIMER_CapturePending(LPC_TIMER1, CAP_1))   // if a rising edge on CAP1.1 is detected
{
//do something
Chip_TIMER_ClearCapture(LPC_TIMER1, CAP_1;
}

else if (Chip_TIMER_MatchPending(LPC_TIMER2, 2)) {  // if no rising edge is detected for DETECT_TIME
//do something
Chip_TIMER_ClearMatch(LPC_TIMER2, 2);
}
}


For TIMER1 interrupt we have no problems, in TIMER2 it seems that the input capture doesn't work as the handler is entered only when the macth condition occurs.
We tried to switch the cap pin, but the problem is still present on the TIMER2 Interrupt handler, so we think the problem is in the init, but we can't find where is the error.
Any suggestions?

Outcomes