KV58 Encoder Edge Time Capture

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KV58 Encoder Edge Time Capture

Jump to solution
1,361 Views
nelson18
Contributor II

I am trying to setup the KV58 timer capture for encoder phase A.
I do not see any values in the CnV register.
I am following this post https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-How-to-connect-the-encoder-inputs-to-a-ge...

I connected the XBARA11_IN to XBARA42_OUT I setup the timer with this code.

const ftm_config_t FTM1_config = {   .prescale = kFTM_Prescale_Divide_8,   .faultMode = kFTM_Fault_Disable,   .faultFilterValue = 0,  .deadTimePrescale = kFTM_Deadtime_Prescale_1,   .deadTimeValue = 0,   .pwmSyncMode = kFTM_SoftwareTrigger,   .reloadPoints = 0,   .extTriggers = 0,   .chnlInitState = 0,   .chnlPolarity = 0,   .bdmMode = kFTM_BdmMode_3,   .useGlobalTimeBase = false };

static void FTM1_init(void) {   FTM_Init(FTM1_PERIPHERAL, &FTM1_config);   FTM_SetTimerPeriod(FTM1_PERIPHERAL, FTM1_TIMER_MODULO_VALUE);   FTM_SetupInputCapture(FTM1_PERIPHERAL, kFTM_Chnl_1, kFTM_RiseAndFallEdge, 0);   FTM_StartTimer(FTM1_PERIPHERAL, kFTM_SystemClock); }

0 Kudos
Reply
1 Solution
1,306 Views
nelson18
Contributor II

Hi I still have not resolved this


From reading your suggestions I feel I have adequately connected the XBARA_IN11 to the FTM1 Ch1 edge capture.

Is it possible I have a conflict with some other device, I am using PIT Timers.


Is this the correct XBARA Output? 

nelson18_0-1680647050378.png


Is this not being setup through the fsl hal layer stuff?

nelson18_0-1680650440244.png

 

View solution in original post

Tags (1)
0 Kudos
Reply
3 Replies
1,349 Views
giraffe508
Contributor IV

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:

  1. Enable the XBARA clock: Add the following line of code to enable the XBARA clock:

CLOCK_EnableClock(kCLOCK_XbarA);

  1. Configure the XBARA: Initialize the XBARA module with an appropriate function:

XBARA_Init(XBARA);

  1. 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);

  1. 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);

  1. 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);

}

0 Kudos
Reply
1,307 Views
nelson18
Contributor II

Hi I still have not resolved this


From reading your suggestions I feel I have adequately connected the XBARA_IN11 to the FTM1 Ch1 edge capture.

Is it possible I have a conflict with some other device, I am using PIT Timers.


Is this the correct XBARA Output? 

nelson18_0-1680647050378.png


Is this not being setup through the fsl hal layer stuff?

nelson18_0-1680650440244.png

 

Tags (1)
0 Kudos
Reply
1,345 Views
nelson18
Contributor II

Sorry, I failed to post what I had for XBARA

This is what I had(lots setup by MCUespresso)

The encoder is on Pin 71 which can be routed to XB_IN11

CLOCK_EnableClock(kCLOCK_XbarA);


XBARA_Init(XBARA);

XBARA_SetSignalsConnection(XBARA, kXBARA_InputXbarIn11, kXBARA_OutputEncPhA);
XBARA_SetSignalsConnection(XBARA, kXBARA_InputXbarIn11, kXBARA_OutputHsadc1ATrig);  <--- this is connected to FTM1 Ch1 signal XOR

Am I missing a connection somewhere? can the XBARA fanout to multiple outputs?
Tags (1)
0 Kudos
Reply