Hi,
This hasn't answered the question.
I have a similar problem:
SystemClk = 120MHz; Pre-scaler = divide by 1
Filter:
The signal to be captured by FTM1 Ch0 is Freq_Mon = 1MHz.
The signal when present has been verified by oscilloscope.
The minimum pulse width to be passed by the filter is:
1/2 Freq_Mon = 500ns.
From the manual [Ref: P972 K24 Sub-Family Reference Manual, Rev. 2, January 2014]
it states that:
minimum pulse width = CHnFVAL[3:0] x 4 system clocks
4 system clocks = 1/120MHz x 4
= 8.3ns x 4
= 33.33ns
so
CHnFVAL[3:0] = 500ns / 33.33ns
= 15 // Stops capturing. Tried 14 and get same result
However:
Setting CHnFVAL[3:0] = 7 passes a pulse of 500ns
Setting CHnFVAL[3:0] = 8 stops a pulse of 500ns
This infers the system clock is divided by 2. i.e. 60MHz
e.g.
4 system clocks = 1/60MHz x 4
= 16.67ns x 4
= 66.67ns
so
CHnFVAL[3:0] = 500ns / 66.67ns
= 7.5 (7) works fine, but I don't understand why?
Implementation:
void FTM1_DRV_InputCaptureInit(void)
{
// Enable clock to the FTM1 module
SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
// Configure pin 64 and its alternate function for FTM1 Ch 0. pin PTA12 (64)
PORTA_PCR12 = PORT_PCR_MUX(3);
// Disable write protection for FTM1 registers
FTM1_MODE |= FTM_MODE_WPDIS_MASK;
// Configure FTM1 as input capture
FTM1_SC = 0; // Ensure FTM1 is disabled for setup
FTM1_SC &= ~FTM_SC_TOIE_MASK; // Disable Timer Overflow Interrupt
FTM1_SC &= ~FTM_SC_TOF_MASK; // Clear Timer Overflow Event flag
FTM1_CNTIN = 0; // Count reset to 0
FTM1_MOD = 0xFFFF; // Set the modulo register for maximum count
// The clk source is set to 120MHz by FTM1_DRV_CaptureStart() every 500ms.
FTM1_SC &= ~FTM_SC_CLKS(7); // Select NO clock.
FTM1_SC |= FTM_SC_PS(0); // Select prescaler divide by 1.
// Configure FTM1 Channel 0 for input capture on rising edge only
FTM1_C0SC = FTM_CnSC_ELSA_MASK; // Capture on rising edge
FTM1_FILTER |= FTM_FILTER_CH0FVAL(7); // Half the input period
// (120MHz / 4) x FVAL = 500ns
// FVAL = 500 / 33.33 = 15.
// This value stops the ISR
// (Using 60MHz / 4) x FVAL = 500ns
// FVAL = 500 / 66.67 = 7.5
// Use 7 and runs ok
// Dont know why using the value of
// SYS_CLK doesnt work.
// The frequency set in SC reg is SYS_CLK
#ifdef DEBUG_CPT
// Enable CAPTEST mode for FTM1 (simulate input capture events internally)
FTM1_CONF |= FTM_CONF_CAPTEST_MASK;
#endif
/* Configure NVIC. Register interrupt into Ram Vector table */
os_install_int_handler (g_ftmIrqId[HW_FTM1], FTM1_ISR);
NVIC_SetPriority(FTM1_IRQn, 1); // ISR runs every 500ms for ?ns
NVIC_ClearPendingIRQ(g_ftmIrqId[HW_FTM1]);
/* Enable FTM interrupt in NVIC level.*/
INT_SYS_EnableIRQ(g_ftmIrqId[HW_FTM1]);
// Make sure these are reset at initailization.
count = 0;
freq_mon_fault = false;
}