I figured it out. The issue was with my initialization of TPM1 as capture input and ISR:
void TPM1_CH0_Timer_Capture_Init(void)
{
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; /* Enable clock to PORTA */
PORTA_PCR12 &= ~(PORT_PCR_PS_MASK);
PORTA_PCR12 |= PORT_PCR_PE_MASK;
PORTA_PCR12 = PORT_PCR_MUX(3); /* Set Port A for TPM1CH0 input */
SIM_SCGC6 |= SIM_SCGC6_TPM1_MASK; /* Enable clock to TPM1 */
SIM_SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK; /* Set for MCGPLLCLK with fixed divide by two */
SIM_SOPT2 &= ~(SIM_SOPT2_TPMSRC_MASK); /* Clear TPMSRC bit filed to 2'b00 */
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); /* Set for MCGPLLCLK/2 */
TPM1_SC = 0; /* Blow away the control registers to ensure that the counter is not running */
TPM1_CONF = 0; /* Blow away the control registers to ensure that the counter is not running */
TPM1_C0SC = 0; /* Blow away the control registers to ensure that the counter is not running */
TPM1_SC = TPM_SC_PS(TPM1_CLK_PRESCALE); /* Setup prescaler to DIV by 64 */
TPM1_MOD = 0xFFFF; /* Set max modulo */
/* Input Capture mode rising and falling edge interrupt */
TPM1_C0SC |= TPM_CnSC_CHIE_MASK | TPM_CnSC_ELSA_MASK | TPM_CnSC_ELSB_MASK; /* Set all these bits */
TPM1_C0SC &= ~(TPM_CnSC_MSA_MASK | TPM_CnSC_MSB_MASK); /* Clear these bits */
}
void FTM1_IRQHandler(void)
{
if(TPM1_C0SC & TPM_CnSC_CHF_MASK) { /* Check to see if channel capture interrupt flag is set */
TPM1_C0SC |= TPM_CnSC_CHF_MASK; /* If set then clear interrupt flag */
if(GPIOA_PDIR & GPIO_PTA12_LOC) { /* Check logic level of PTA12 */
TPM1_CNT = 0; /* If rising edge has hapened, reset the count to 0 */
}
if(!(GPIOA_PDIR & GPIO_PTA12_LOC)) { /*check level of PTA12 */
BLUE_LED_ON;
val = TPM1_C0V; /* if LOW store the current count */
}
}
return;
}