Hello,
I am having an issue clearing a channel flag for an FTM input capture interrupt. This is on the LPC865M201. The application is glitch filtering out subsequent pulses so that after the initial interrupt, the channel interrupt is disabled for several ms. The problem appears to be that the flag does not clear. So, the interrupt is called accidentally when another ch interrupts. Below is the sample code of what's going on inside the interrupt.
if (1 == ((FTM0->CONTROLS[0].CnSC & FTM_CnSC_CHF_MASK) >> FTM_CnSC_CHF_SHIFT))
{
(void)FTM0->CONTROLS[0].CnSC; /* Read to clear flag */
FTM0->CONTROLS[0].CnSC ^= FTM_CnSC_CHF_MASK; /* Clear flag */
FTM0->CONTROLS[0].CnSC turnoff FTM_CnSC_CHIE_MASK; //Disable Interrupt
kl_Intervals[kl_intPointer] = FTM0->CONTROLS[0].CnV + 0xFFFFUL *
kl_OverFlowCounter - kl_lastTick;
kl_Timers[kl_intPointer] = FTM0->CONTROLS[0].CnV;
kl_intPointer = (kl_intPointer + 1) % 50;
kl_lastTick = FTM0->CONTROLS[0].CnV;
}

Based on the RM, there are two lines to clear a channel flag:
(void)FTM0->CONTROLS[0].CnSC; /* Read to clear flag */
FTM0->CONTROLS[0].CnSC ^= FTM_CnSC_CHF_MASK; /* Clear flag */
However, stepping through this in debug mode shows that CHF stays at 1. I've tried clearing the flag using the STATUS register to no avail.
What's interesting is that this works fine without glitch filter (i.e. no disabling interrupt). Although, the CHF is still not cleared when debug stepping. Only when the CHIE is disabled do we see false interrupts (CHF not cleared, CHIE = disabled).
Any ideas on what might be going wrong here?