FlexTimer Module Counter Driver (FTM_MC)

Detailed Description

FlexTimer Module Counter 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.

Counter mode

For this mode the user needs to configure parameters like: counter mode (up-counting or up-down counting), maximum counter value, initial counter value. All this information is included in the ftm_timer_param_t structure.

Example:

/* The state structure of instance in the input capture mode */
ftm_state_t stateTimer;
#define FTM_TIMER_INSTANCE 1UL
/* Timer mode configuration for Timer */
ftm_timer_param_t Timer_TimerConfig =
{
FTM_MODE_UP_TIMER, /* Counter mode */
0U, /* Initial counter value */
0x8000U /* Final counter value */
};
/* Global configuration of Timer*/
ftm_user_config_t Timer_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_UP_TIMER, /* 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_TIMER_INSTANCE,&Timer_InitConfig, &stateTimer);
FTM_DRV_InitCounter(FTM_TIMER_INSTANCE, &Timer_TimerConfig);
FTM_DRV_CounterStart(FTM_TIMER_INSTANCE);

Data Structures

struct  ftm_timer_param_t
 FlexTimer driver timer mode configuration structure. More...
 

Functions

status_t FTM_DRV_InitCounter (uint32_t instance, const ftm_timer_param_t *timer)
 Initialize the FTM counter. More...
 
status_t FTM_DRV_CounterStart (uint32_t instance)
 Starts the FTM counter. More...
 
status_t FTM_DRV_CounterStop (uint32_t instance)
 Stops the FTM counter. More...
 
uint32_t FTM_DRV_CounterRead (uint32_t instance)
 Reads back the current value of the FTM counter. More...
 

Function Documentation

uint32_t FTM_DRV_CounterRead ( uint32_t  instance)

Reads back the current value of the FTM counter.

Parameters
[in]instanceThe FTM peripheral instance number.
Returns
The current counter value

Definition at line 153 of file ftm_mc_driver.c.

status_t FTM_DRV_CounterStart ( uint32_t  instance)

Starts the FTM counter.

Parameters
[in]instanceThe FTM peripheral instance number.
Returns
operation status
  • STATUS_SUCCESS : Completed successfully.
  • STATUS_ERROR : Error occurred.

Definition at line 112 of file ftm_mc_driver.c.

status_t FTM_DRV_CounterStop ( uint32_t  instance)

Stops the FTM counter.

Parameters
[in]instanceThe FTM peripheral instance number.
Returns
operation status
  • STATUS_SUCCESS : Completed successfully.

Definition at line 133 of file ftm_mc_driver.c.

status_t FTM_DRV_InitCounter ( uint32_t  instance,
const ftm_timer_param_t timer 
)

Initialize the FTM counter.

Starts the FTM counter. This function provides access to the FTM counter settings. The counter can be run in Up counting and Up-down counting modes. To run the counter in Free running mode, choose Up counting option and provide 0x0 for the countStartVal and 0xFFFF for countFinalVal. Please call this function only when FTM is used as timer/counter.

Parameters
[in]instanceThe FTM peripheral instance number.
[in]timerTimer configuration structure.
Returns
operation status
  • STATUS_SUCCESS : Initialized successfully.

Definition at line 53 of file ftm_mc_driver.c.