FlexTimer Quadrature Decoder Driver (FTM_QD)

Detailed Description

FlexTimer Quadrature Decoder 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.

Quadrature decoder mode

For this mode the user needs to configure parameters like: maximum counter value, initial counter value, mode (Count and Direction Encoding mode), and for both input phases polarity and filtering. All this information is included in ftm_quad_decode_config_t. In this mode, the counter is clocked by the phase A and phase B. The current state of the decoder can be obtained using FTM_DRV_QuadGetState.

Hardware limitation:

In count and direction mode if initial value of the PHASE_A is HIGH the counter will be incremented.

Example:

/* The state structure of instance in the quadrature mode */
ftm_state_t stateQuad;
#define FTM_QUADRATURE_INSTANCE 1UL
ftm_quad_decode_config_t quadrature_decoder_configuration =
{
FTM_QUAD_COUNT_AND_DIR, /* Quadrature decoder mode */
0U, /* Initial counter value */
32500U, /* Maximum counter value */
{
false, /* Filter state */
0U, /* Filter value */
FTM_QUAD_PHASE_NORMAL /* Phase polarity */
},
{
false, /* Filter state */
0U, /* Filter value */
FTM_QUAD_PHASE_NORMAL /* Phase polarity */
}
};
/* Timer mode configuration for Quadrature */
/* Global configuration of Quadrature */
ftm_user_config_t Quadrature_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_QUADRATURE_DECODER, /* Mode of operation for FTM */
FTM_CLOCK_DIVID_BY_2, /* FTM clock pre-scaler */
FTM_CLOCK_SOURCE_SYSTEMCLK, /* FTM clock source */
FTM_BDM_MODE_11, /* FTM debug mode */
false, /* Interrupt state */
false /* Initialization trigger */
};
FTM_DRV_Init(FTM_QUADRATURE_INSTANCE, &Quadrature_InitConfig, &stateQuad);
FTM_DRV_QuadDecodeStart(FTM_QUADRATURE_INSTANCE, &quadrature_decoder_configuration);
quadra_state = FTM_DRV_QuadGetState(FTM_QUADRATURE_INSTANCE);

Data Structures

struct  ftm_phase_params_t
 FlexTimer quadrature decoder channel parameters. More...
 
struct  ftm_quad_decode_config_t
 FTM quadrature configure structure. More...
 
struct  ftm_quad_decoder_state_t
 FTM quadrature state(counter value and flags) More...
 

Functions

status_t FTM_DRV_QuadDecodeStart (uint32_t instance, const ftm_quad_decode_config_t *config)
 Configures the quadrature mode and starts measurement. More...
 
status_t FTM_DRV_QuadDecodeStop (uint32_t instance)
 De-activates the quadrature decode mode. More...
 
ftm_quad_decoder_state_t FTM_DRV_QuadGetState (uint32_t instance)
 Return the current quadrature decoder state (counter value, overflow flag and overflow direction) More...
 

Function Documentation

status_t FTM_DRV_QuadDecodeStart ( uint32_t  instance,
const ftm_quad_decode_config_t config 
)

Configures the quadrature mode and starts measurement.

Parameters
[in]instanceInstance number of the FTM module.
[in]configConfiguration structure(quadrature decode mode, polarity for both phases, initial and maximum value for the counter, filter configuration).
Returns
success
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 50 of file ftm_qd_driver.c.

status_t FTM_DRV_QuadDecodeStop ( uint32_t  instance)

De-activates the quadrature decode mode.

Parameters
[in]instanceInstance number of the FTM module.
Returns
success
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 109 of file ftm_qd_driver.c.

ftm_quad_decoder_state_t FTM_DRV_QuadGetState ( uint32_t  instance)

Return the current quadrature decoder state (counter value, overflow flag and overflow direction)

Parameters
[in]instanceInstance number of the FTM module.
Returns
The current state of quadrature decoder

Definition at line 130 of file ftm_qd_driver.c.