t appears that you've set up the FTM (FlexTimer Module) correctly, but you haven't mentioned how you're connecting the XBARA (Crossbar Switch) and configuring it.
To route the encoder signal through the XBARA and to the FTM input capture, you need to set up the XBARA as well. Here's an example of how to do that:
- Enable the XBARA clock: Add the following line of code to enable the XBARA clock:
CLOCK_EnableClock(kCLOCK_XbarA);
- Configure the XBARA: Initialize the XBARA module with an appropriate function:
XBARA_Init(XBARA);
- Connect the input signal (Phase A) to an XBARA input: Use a function to connect the input signal (e.g., Phase A) to an XBARA input, such as XBARA_IN11:
XBARA_SetSignalsConnection(XBARA, kXBARA1_InputQdtimer1Trig01, kXBARA1_OutputXbOut11);
- Connect the XBARA output to the FTM1_CH1 input: Connect the XBARA output, such as XBARA_OUT42, to the FTM1_CH1 input:
XBARA_SetSignalsConnection(XBARA, kXBARA1_InputXbIn42, kXBARA1_OutputFtm1Ch1);
- Update the FTM1_init function to include the XBARA configuration:
static void FTM1_init(void) {
// Enable the XBARA clock
CLOCK_EnableClock(kCLOCK_XbarA);
// Initialize the XBARA module
XBARA_Init(XBARA);
// Connect the input signal (Phase A) to XBARA_IN11
XBARA_SetSignalsConnection(XBARA, kXBARA1_InputQdtimer1Trig01, kXBARA1_OutputXbOut11);
// Connect XBARA_OUT42 to FTM1_CH1 input
XBARA_SetSignalsConnection(XBARA, kXBARA1_InputXbIn42, kXBARA1_OutputFtm1Ch1);
// Initialize the FTM1 module with the given configuration
FTM_Init(FTM1_PERIPHERAL, &FTM1_config);
// Set the timer period
FTM_SetTimerPeriod(FTM1_PERIPHERAL, FTM1_TIMER_MODULO_VALUE);
// Setup the input capture
FTM_SetupInputCapture(FTM1_PERIPHERAL, kFTM_Chnl_1, kFTM_RiseAndFallEdge, 0);
// Start the timer
FTM_StartTimer(FTM1_PERIPHERAL, kFTM_SystemClock);
}