FlexTimer Input Capture Driver (FTM_IC)

Detailed Description

FlexTimer Input Capture Peripheral Driver.

Hardware background

The FTM of the S32K1xx is based on a 16 bits counter and supports: input capture, output compare, PWM and some instances include quadrature decoder.

How to use FTM driver in your application

For all operation modes (without Quadrature Decoder mode) the user need to configure ftm_user_config_t. This structure will be used for initialization (FTM_DRV_Init). The next functions used are specific for each operation mode.

Single edge input capture mode

For this mode the user needs to configure parameters such: maximum counter value, number of channels, input capture operation mode (for single edge input are used edge detect mode) and edge alignment. All this information is included in the ftm_input_param_t structure.

Example:

/* The state structure of instance in the input capture mode */
ftm_state_t stateInputCapture;
#define FTM_IC_INSTANCE 0UL
/* Channels configuration structure for inputCapture input capture */
ftm_input_ch_param_t inputCapture_InputCaptureChannelConfig[1] =
{
{
0U, /* Channel Id */
FTM_EDGE_DETECT, /* Input capture operation Mode */
FTM_RISING_EDGE, /* Edge alignment Mode */
FTM_NO_MEASUREMENT, /* Signal measurement operation type */
0U, /* Filter value */
false, /* Filter disabled */
true /* Continuous mode measurement */
NULL, /* Vector of callbacks parameters for channels events */
NULL /* Vector of callbacks for channels events */
}
};
/* Input capture configuration for inputCapture */
ftm_input_param_t inputCapture_InputCaptureConfig =
{
1U, /* Number of channels */
65535U, /* Maximum count value */
inputCapture_InputCaptureChannelConfig /* Channels configuration */
};
/* Timer mode configuration for inputCapture */
/* Global configuration of inputCapture */
ftm_user_config_t inputCapture_InitConfig =
{
{
false, /* Software trigger state */
false, /* Hardware trigger 1 state */
false, /* Hardware trigger 2 state */
false, /* Hardware trigger 3 state */
false, /* Maximum loading point state */
false, /* Min loading point state */
FTM_SYSTEM_CLOCK, /* Update mode for INVCTRL register */
FTM_SYSTEM_CLOCK, /* Update mode for SWOCTRL register */
FTM_SYSTEM_CLOCK, /* Update mode for OUTMASK register */
FTM_SYSTEM_CLOCK, /* Update mode for CNTIN register */
false, /* Auto clear trigger state for hardware trigger */
FTM_UPDATE_NOW, /* Select synchronization method */
},
FTM_MODE_INPUT_CAPTURE, /* Mode of operation for FTM */
FTM_CLOCK_DIVID_BY_4, /* FTM clock pre-scaler */
FTM_CLOCK_SOURCE_SYSTEMCLK, /* FTM clock source */
FTM_BDM_MODE_00, /* FTM debug mode */
false, /* Interrupt state */
false /* Initialization trigger */
};
FTM_DRV_Init(FTM_IC_INSTANCE, &inputCapture_InitConfig, &stateInputCapture);
FTM_DRV_InitInputCapture(FTM_IC_INSTANCE, &inputCapture_InputCaptureConfig);
counter = FTM_DRV_GetInputCaptureMeasurement(FTM_IC_INSTANCE, 0UL);

FTM_DRV_GetInputCaptureMeasurement is now used in interrupt mode and this function is used to save time stamps in internal buffers.

Data Structures

struct  ftm_input_ch_param_t
 FlexTimer driver Input capture parameters for each channel. More...
 
struct  ftm_input_param_t
 FlexTimer driver input capture parameters. More...
 

Enumerations

enum  ftm_input_op_mode_t { FTM_EDGE_DETECT = 0U, FTM_SIGNAL_MEASUREMENT = 1U, FTM_NO_OPERATION = 2U }
 FTM status. More...
 
enum  ftm_signal_measurement_mode_t {
  FTM_NO_MEASUREMENT = 0x00U, FTM_RISING_EDGE_PERIOD_MEASUREMENT = 0x01U, FTM_FALLING_EDGE_PERIOD_MEASUREMENT = 0x02U, FTM_PERIOD_ON_MEASUREMENT = 0x03U,
  FTM_PERIOD_OFF_MEASUREMENT = 0x04U
}
 FlexTimer input capture measurement type for dual edge input capture. More...
 
enum  ftm_edge_alignment_mode_t { FTM_NO_PIN_CONTROL = 0x00U, FTM_RISING_EDGE = 0x01U, FTM_FALLING_EDGE = 0x02U, FTM_BOTH_EDGES = 0x03U }
 FlexTimer input capture edge mode, rising edge, or falling edge. More...
 
enum  ftm_ic_op_mode_t {
  FTM_DISABLE_OPERATION = 0x00U, FTM_TIMESTAMP_RISING_EDGE = 0x01U, FTM_TIMESTAMP_FALLING_EDGE = 0x02U, FTM_TIMESTAMP_BOTH_EDGES = 0x03U,
  FTM_MEASURE_RISING_EDGE_PERIOD = 0x04U, FTM_MEASURE_FALLING_EDGE_PERIOD = 0x05U, FTM_MEASURE_PULSE_HIGH = 0x06U, FTM_MEASURE_PULSE_LOW = 0x07U
}
 The measurement type for input capture mode Implements : ftm_ic_op_mode_t_Class. More...
 

Functions

status_t FTM_DRV_InitInputCapture (uint32_t instance, const ftm_input_param_t *param)
 Configures Channel Input Capture for either getting time-stamps on edge detection or on signal measurement . When the edge specified in the captureMode argument occurs on the channel the FTM counter is captured into the CnV register. The user will have to read the CnV register separately to get this value. The filter function is disabled if the filterVal argument passed in is 0. The filter function is available only on channels 0,1,2,3. More...
 
status_t FTM_DRV_DeinitInputCapture (uint32_t instance, const ftm_input_param_t *param)
 Disables input capture mode and clears FTM timer configuration. More...
 
uint16_t FTM_DRV_GetInputCaptureMeasurement (uint32_t instance, uint8_t channel)
 This function is used to calculate the measurement and/or time stamps values which are read from the C(n, n+1)V registers and stored to the static buffers. More...
 
status_t FTM_DRV_StartNewSignalMeasurement (uint32_t instance, uint8_t channel)
 Starts new single-shot signal measurement of the given channel. More...
 
status_t FTM_IC_DRV_SetChannelMode (uint32_t instance, uint8_t channel, ftm_ic_op_mode_t inputMode, bool enableContinuousCapture)
 Set mode operation for channel in the input captue mode. More...
 

Enumeration Type Documentation

FlexTimer input capture edge mode, rising edge, or falling edge.

Implements : ftm_edge_alignment_mode_t_Class

Enumerator
FTM_NO_PIN_CONTROL 

No trigger

FTM_RISING_EDGE 

Rising edge trigger

FTM_FALLING_EDGE 

Falling edge trigger

FTM_BOTH_EDGES 

Rising and falling edge trigger

Definition at line 70 of file ftm_ic_driver.h.

The measurement type for input capture mode Implements : ftm_ic_op_mode_t_Class.

Enumerator
FTM_DISABLE_OPERATION 

Have no operation

FTM_TIMESTAMP_RISING_EDGE 

Rising edge trigger

FTM_TIMESTAMP_FALLING_EDGE 

Falling edge trigger

FTM_TIMESTAMP_BOTH_EDGES 

Rising and falling edge trigger

FTM_MEASURE_RISING_EDGE_PERIOD 

Period measurement between two consecutive rising edges

FTM_MEASURE_FALLING_EDGE_PERIOD 

Period measurement between two consecutive falling edges

FTM_MEASURE_PULSE_HIGH 

The time measurement taken for the pulse to remain ON or HIGH state

FTM_MEASURE_PULSE_LOW 

The time measurement taken for the pulse to remain OFF or LOW state

Definition at line 82 of file ftm_ic_driver.h.

FTM status.

Implements : ftm_input_op_mode_t_Class

Enumerator
FTM_EDGE_DETECT 

FTM edge detect

FTM_SIGNAL_MEASUREMENT 

FTM signal measurement

FTM_NO_OPERATION 

FTM no operation

Definition at line 44 of file ftm_ic_driver.h.

FlexTimer input capture measurement type for dual edge input capture.

Implements : ftm_signal_measurement_mode_t_Class

Enumerator
FTM_NO_MEASUREMENT 

No measurement

FTM_RISING_EDGE_PERIOD_MEASUREMENT 

Period measurement between two consecutive rising edges

FTM_FALLING_EDGE_PERIOD_MEASUREMENT 

Period measurement between two consecutive falling edges

FTM_PERIOD_ON_MEASUREMENT 

The time measurement taken for the pulse to remain ON or HIGH state

FTM_PERIOD_OFF_MEASUREMENT 

The time measurement taken for the pulse to remain OFF or LOW state

Definition at line 56 of file ftm_ic_driver.h.

Function Documentation

status_t FTM_DRV_DeinitInputCapture ( uint32_t  instance,
const ftm_input_param_t param 
)

Disables input capture mode and clears FTM timer configuration.

Parameters
[in]instanceThe FTM peripheral instance number.
[in]paramConfiguration of the output compare channel.
Returns
success
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 285 of file ftm_ic_driver.c.

uint16_t FTM_DRV_GetInputCaptureMeasurement ( uint32_t  instance,
uint8_t  channel 
)

This function is used to calculate the measurement and/or time stamps values which are read from the C(n, n+1)V registers and stored to the static buffers.

Parameters
[in]instanceThe FTM peripheral instance number.
[in]channelFor getting the time stamp of the last edge (in normal input capture) this parameter represents the channel number. For getting the last measured value (in dual edge input capture) this parameter is the lowest channel number of the pair (EX: 0, 2, 4, 6).
Returns
value The measured value

Definition at line 337 of file ftm_ic_driver.c.

status_t FTM_DRV_InitInputCapture ( uint32_t  instance,
const ftm_input_param_t param 
)

Configures Channel Input Capture for either getting time-stamps on edge detection or on signal measurement . When the edge specified in the captureMode argument occurs on the channel the FTM counter is captured into the CnV register. The user will have to read the CnV register separately to get this value. The filter function is disabled if the filterVal argument passed in is 0. The filter function is available only on channels 0,1,2,3.

Parameters
[in]instanceThe FTM peripheral instance number.
[in]paramConfiguration of the input capture channel.
Returns
success
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 136 of file ftm_ic_driver.c.

status_t FTM_DRV_StartNewSignalMeasurement ( uint32_t  instance,
uint8_t  channel 
)

Starts new single-shot signal measurement of the given channel.

Parameters
[in]instanceThe FTM peripheral instance number.
[in]channelConfiguration of the output compare channel.
Returns
success
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 361 of file ftm_ic_driver.c.

status_t FTM_IC_DRV_SetChannelMode ( uint32_t  instance,
uint8_t  channel,
ftm_ic_op_mode_t  inputMode,
bool  enableContinuousCapture 
)

Set mode operation for channel in the input captue mode.

This function will change the channel mode at run time or when stopping channel. The channel mode is selected in the ftm_ic_op_mode_t enumeration type.

Parameters
[in]instanceThe input capture instance number.
[in]channelThe channel number.
[in]inputModeThe channel operation mode.
[in]enableContinuousCaptureEnable/disable the continuous capture mode.
Returns
success
  • STATUS_SUCCESS : Completed successfully.

Definition at line 399 of file ftm_ic_driver.c.