MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FTM: FlexTimer Driver

Overview

The MCUXpresso SDK provides a driver for the FlexTimer Module (FTM) of MCUXpresso SDK devices.

Function groups

The FTM driver supports the generation of PWM signals, input capture, dual edge capture, output compare, and quadrature decoder modes. The driver also supports configuring each of the FTM fault inputs.

Initialization and deinitialization

The function FTM_Init() initializes the FTM with specified configurations. The function FTM_GetDefaultConfig() gets the default configurations. The initialization function configures the FTM for the requested register update mode for registers with buffers. It also sets up the FTM's fault operation mode and FTM behavior in the BDM mode.

The function FTM_Deinit() disables the FTM counter and turns off the module clock.

PWM Operations

The function FTM_SetupPwm() sets up FTM channels for the PWM output. The function sets up the PWM signal properties for multiple channels. Each channel has its own duty cycle and level-mode specified. However, the same PWM period and PWM mode is applied to all channels requesting the PWM output. The signal duty cycle is provided as a percentage of the PWM period. Its value should be between 0 and 100 0=inactive signal (0% duty cycle) and 100=always active signal (100% duty cycle).

The function FTM_UpdatePwmDutycycle() updates the PWM signal duty cycle of a particular FTM channel.

The function FTM_UpdateChnlEdgeLevelSelect() updates the level select bits of a particular FTM channel. This can be used to disable the PWM output when making changes to the PWM signal.

Input capture operations

The function FTM_SetupInputCapture() sets up an FTM channel for the input capture. The user can specify the capture edge and a filter value to be used when processing the input signal.

The function FTM_SetupDualEdgeCapture() can be used to measure the pulse width of a signal. A channel pair is used during capture with the input signal coming through a channel n. The user can specify whether to use one-shot or continuous capture, the capture edge for each channel, and any filter value to be used when processing the input signal.

Output compare operations

The function FTM_SetupOutputCompare() sets up an FTM channel for the output comparison. The user can specify the channel output on a successful comparison and a comparison value.

Quad decode

The function FTM_SetupQuadDecode() sets up FTM channels 0 and 1 for quad decoding. The user can specify the quad decoding mode, polarity, and filter properties for each input signal.

Fault operation

The function FTM_SetupFault() sets up the properties for each fault. The user can specify the fault polarity and whether to use a filter on a fault input. The overall fault filter value and fault control mode are set up during initialization.

Register Update

Some of the FTM registers have buffers. The driver supports various methods to update these registers with the content of the register buffer. The registers can be updated using the PWM synchronized loading or an intermediate point loading. The update mechanism for register with buffers can be specified through the following fields available in the configuration structure.

uint32_t pwmSyncMode;
uint32_t reloadPoints;

Multiple PWM synchronization update modes can be used by providing an OR'ed list of options available in the enumeration ftm_pwm_sync_method_t to the pwmSyncMode field.

When using an intermediate reload points, the PWM synchnronization is not required. Multiple reload points can be used by providing an OR'ed list of options available in the enumeration ftm_reload_point_t to the reloadPoints field.

The driver initialization function sets up the appropriate bits in the FTM module based on the register update options selected.

If software PWM synchronization is used, the below function can be used to initiate a software trigger.

Typical use case

PWM output

Output a PWM signal on two FTM channels with different duty cycles. Periodically update the PWM signal duty cycle.

int main(void)
{
bool brightnessUp = true; /* Indicates whether LEDs are brighter or dimmer. */
ftm_config_t ftmInfo;
uint8_t updatedDutycycle = 0U;
/* Configures the FTM parameters with frequency 24 kHZ */
ftmParam[0].chnlNumber = (ftm_chnl_t)BOARD_FIRST_FTM_CHANNEL;
ftmParam[0].level = kFTM_LowTrue;
ftmParam[0].dutyCyclePercent = 0U;
ftmParam[0].firstEdgeDelayPercent = 0U;
ftmParam[1].chnlNumber = (ftm_chnl_t)BOARD_SECOND_FTM_CHANNEL;
ftmParam[1].level = kFTM_LowTrue;
ftmParam[1].dutyCyclePercent = 0U;
ftmParam[1].firstEdgeDelayPercent = 0U;
/* Initializes the FTM module. */
FTM_Init(BOARD_FTM_BASEADDR, &ftmInfo);
FTM_SetupPwm(BOARD_FTM_BASEADDR, ftmParam, 2U, kFTM_EdgeAlignedPwm, 24000U, FTM_SOURCE_CLOCK);
FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);
while (1)
{
/* Delays to check whether the LED brightness has changed. */
delay();
if (brightnessUp)
{
/* Increases the duty cycle until it reaches a limited value. */
if (++updatedDutycycle == 100U)
{
brightnessUp = false;
}
}
else
{
/* Decreases the duty cycle until it reaches a limited value. */
if (--updatedDutycycle == 0U)
{
brightnessUp = true;
}
}
/* Starts the PWM mode with an updated duty cycle. */
FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, (ftm_chnl_t)BOARD_FIRST_FTM_CHANNEL, kFTM_EdgeAlignedPwm,
updatedDutycycle);
FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, (ftm_chnl_t)BOARD_SECOND_FTM_CHANNEL, kFTM_EdgeAlignedPwm,
updatedDutycycle);
/* Software trigger to update registers. */
FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);
}
}

Data Structures

struct  ftm_chnl_pwm_signal_param_t
 Options to configure a FTM channel's PWM signal. More...
 
struct  ftm_dual_edge_capture_param_t
 FlexTimer dual edge capture parameters. More...
 
struct  ftm_phase_params_t
 FlexTimer quadrature decode phase parameters. More...
 
struct  ftm_fault_param_t
 Structure is used to hold the parameters to configure a FTM fault. More...
 
struct  ftm_config_t
 FTM configuration structure. More...
 

Enumerations

enum  ftm_chnl_t {
  kFTM_Chnl_0 = 0U,
  kFTM_Chnl_1,
  kFTM_Chnl_2,
  kFTM_Chnl_3,
  kFTM_Chnl_4,
  kFTM_Chnl_5,
  kFTM_Chnl_6,
  kFTM_Chnl_7
}
 List of FTM channels. More...
 
enum  ftm_fault_input_t {
  kFTM_Fault_0 = 0U,
  kFTM_Fault_1,
  kFTM_Fault_2,
  kFTM_Fault_3
}
 List of FTM faults. More...
 
enum  ftm_pwm_mode_t {
  kFTM_EdgeAlignedPwm = 0U,
  kFTM_CenterAlignedPwm,
  kFTM_CombinedPwm
}
 FTM PWM operation modes. More...
 
enum  ftm_pwm_level_select_t {
  kFTM_NoPwmSignal = 0U,
  kFTM_LowTrue,
  kFTM_HighTrue
}
 FTM PWM output pulse mode: high-true, low-true or no output. More...
 
enum  ftm_output_compare_mode_t {
  kFTM_NoOutputSignal = (1U << FTM_CnSC_MSA_SHIFT),
  kFTM_ToggleOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (1U << FTM_CnSC_ELSA_SHIFT)),
  kFTM_ClearOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (2U << FTM_CnSC_ELSA_SHIFT)),
  kFTM_SetOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (3U << FTM_CnSC_ELSA_SHIFT))
}
 FlexTimer output compare mode. More...
 
enum  ftm_input_capture_edge_t {
  kFTM_RisingEdge = (1U << FTM_CnSC_ELSA_SHIFT),
  kFTM_FallingEdge = (2U << FTM_CnSC_ELSA_SHIFT),
  kFTM_RiseAndFallEdge = (3U << FTM_CnSC_ELSA_SHIFT)
}
 FlexTimer input capture edge. More...
 
enum  ftm_dual_edge_capture_mode_t {
  kFTM_OneShot = 0U,
  kFTM_Continuous = (1U << FTM_CnSC_MSA_SHIFT)
}
 FlexTimer dual edge capture modes. More...
 
enum  ftm_quad_decode_mode_t {
  kFTM_QuadPhaseEncode = 0U,
  kFTM_QuadCountAndDir
}
 FlexTimer quadrature decode modes. More...
 
enum  ftm_phase_polarity_t {
  kFTM_QuadPhaseNormal = 0U,
  kFTM_QuadPhaseInvert
}
 FlexTimer quadrature phase polarities. More...
 
enum  ftm_deadtime_prescale_t {
  kFTM_Deadtime_Prescale_1 = 1U,
  kFTM_Deadtime_Prescale_4,
  kFTM_Deadtime_Prescale_16
}
 FlexTimer pre-scaler factor for the dead time insertion. More...
 
enum  ftm_clock_source_t {
  kFTM_SystemClock = 1U,
  kFTM_FixedClock,
  kFTM_ExternalClock
}
 FlexTimer clock source selection. More...
 
enum  ftm_clock_prescale_t {
  kFTM_Prescale_Divide_1 = 0U,
  kFTM_Prescale_Divide_2,
  kFTM_Prescale_Divide_4,
  kFTM_Prescale_Divide_8,
  kFTM_Prescale_Divide_16,
  kFTM_Prescale_Divide_32,
  kFTM_Prescale_Divide_64,
  kFTM_Prescale_Divide_128
}
 FlexTimer pre-scaler factor selection for the clock source. More...
 
enum  ftm_bdm_mode_t {
  kFTM_BdmMode_0 = 0U,
  kFTM_BdmMode_1,
  kFTM_BdmMode_2,
  kFTM_BdmMode_3
}
 Options for the FlexTimer behaviour in BDM Mode. More...
 
enum  ftm_fault_mode_t {
  kFTM_Fault_Disable = 0U,
  kFTM_Fault_EvenChnls,
  kFTM_Fault_AllChnlsMan,
  kFTM_Fault_AllChnlsAuto
}
 Options for the FTM fault control mode. More...
 
enum  ftm_external_trigger_t {
  kFTM_Chnl0Trigger = (1U << 4),
  kFTM_Chnl1Trigger = (1U << 5),
  kFTM_Chnl2Trigger = (1U << 0),
  kFTM_Chnl3Trigger = (1U << 1),
  kFTM_Chnl4Trigger = (1U << 2),
  kFTM_Chnl5Trigger = (1U << 3),
  kFTM_Chnl6Trigger,
  kFTM_Chnl7Trigger,
  kFTM_InitTrigger = (1U << 6),
  kFTM_ReloadInitTrigger = (1U << 7)
}
 FTM external trigger options. More...
 
enum  ftm_pwm_sync_method_t {
  kFTM_SoftwareTrigger = FTM_SYNC_SWSYNC_MASK,
  kFTM_HardwareTrigger_0 = FTM_SYNC_TRIG0_MASK,
  kFTM_HardwareTrigger_1 = FTM_SYNC_TRIG1_MASK,
  kFTM_HardwareTrigger_2 = FTM_SYNC_TRIG2_MASK
}
 FlexTimer PWM sync options to update registers with buffer. More...
 
enum  ftm_reload_point_t {
  kFTM_Chnl0Match = (1U << 0),
  kFTM_Chnl1Match = (1U << 1),
  kFTM_Chnl2Match = (1U << 2),
  kFTM_Chnl3Match = (1U << 3),
  kFTM_Chnl4Match = (1U << 4),
  kFTM_Chnl5Match = (1U << 5),
  kFTM_Chnl6Match = (1U << 6),
  kFTM_Chnl7Match = (1U << 7),
  kFTM_CntMax = (1U << 8),
  kFTM_CntMin = (1U << 9),
  kFTM_HalfCycMatch = (1U << 10)
}
 FTM options available as loading point for register reload. More...
 
enum  ftm_interrupt_enable_t {
  kFTM_Chnl0InterruptEnable = (1U << 0),
  kFTM_Chnl1InterruptEnable = (1U << 1),
  kFTM_Chnl2InterruptEnable = (1U << 2),
  kFTM_Chnl3InterruptEnable = (1U << 3),
  kFTM_Chnl4InterruptEnable = (1U << 4),
  kFTM_Chnl5InterruptEnable = (1U << 5),
  kFTM_Chnl6InterruptEnable = (1U << 6),
  kFTM_Chnl7InterruptEnable = (1U << 7),
  kFTM_FaultInterruptEnable = (1U << 8),
  kFTM_TimeOverflowInterruptEnable = (1U << 9),
  kFTM_ReloadInterruptEnable = (1U << 10)
}
 List of FTM interrupts. More...
 
enum  ftm_status_flags_t {
  kFTM_Chnl0Flag = (1U << 0),
  kFTM_Chnl1Flag = (1U << 1),
  kFTM_Chnl2Flag = (1U << 2),
  kFTM_Chnl3Flag = (1U << 3),
  kFTM_Chnl4Flag = (1U << 4),
  kFTM_Chnl5Flag = (1U << 5),
  kFTM_Chnl6Flag = (1U << 6),
  kFTM_Chnl7Flag = (1U << 7),
  kFTM_FaultFlag = (1U << 8),
  kFTM_TimeOverflowFlag = (1U << 9),
  kFTM_ChnlTriggerFlag = (1U << 10),
  kFTM_ReloadFlag = (1U << 11)
}
 List of FTM flags. More...
 
enum  _ftm_quad_decoder_flags {
  kFTM_QuadDecoderCountingIncreaseFlag = FTM_QDCTRL_QUADIR_MASK,
  kFTM_QuadDecoderCountingOverflowOnTopFlag = FTM_QDCTRL_TOFDIR_MASK
}
 List of FTM Quad Decoder flags. More...
 

Functions

void FTM_SetupFault (FTM_Type *base, ftm_fault_input_t faultNumber, const ftm_fault_param_t *faultParams)
 Sets up the working of the FTM fault protection. More...
 
static void FTM_SetGlobalTimeBaseOutputEnable (FTM_Type *base, bool enable)
 Enables or disables the FTM global time base signal generation to other FTMs. More...
 
static void FTM_SetOutputMask (FTM_Type *base, ftm_chnl_t chnlNumber, bool mask)
 Sets the FTM peripheral timer channel output mask. More...
 
static void FTM_SetSoftwareTrigger (FTM_Type *base, bool enable)
 Enables or disables the FTM software trigger for PWM synchronization. More...
 
static void FTM_SetWriteProtection (FTM_Type *base, bool enable)
 Enables or disables the FTM write protection. More...
 

Driver version

#define FSL_FTM_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
 Version 2.0.2.
 

Initialization and deinitialization

status_t FTM_Init (FTM_Type *base, const ftm_config_t *config)
 Ungates the FTM clock and configures the peripheral for basic operation. More...
 
void FTM_Deinit (FTM_Type *base)
 Gates the FTM clock. More...
 
void FTM_GetDefaultConfig (ftm_config_t *config)
 Fills in the FTM configuration structure with the default settings. More...
 

Channel mode operations

status_t FTM_SetupPwm (FTM_Type *base, const ftm_chnl_pwm_signal_param_t *chnlParams, uint8_t numOfChnls, ftm_pwm_mode_t mode, uint32_t pwmFreq_Hz, uint32_t srcClock_Hz)
 Configures the PWM signal parameters. More...
 
void FTM_UpdatePwmDutycycle (FTM_Type *base, ftm_chnl_t chnlNumber, ftm_pwm_mode_t currentPwmMode, uint8_t dutyCyclePercent)
 Updates the duty cycle of an active PWM signal. More...
 
void FTM_UpdateChnlEdgeLevelSelect (FTM_Type *base, ftm_chnl_t chnlNumber, uint8_t level)
 Updates the edge level selection for a channel. More...
 
void FTM_SetupInputCapture (FTM_Type *base, ftm_chnl_t chnlNumber, ftm_input_capture_edge_t captureMode, uint32_t filterValue)
 Enables capturing an input signal on the channel using the function parameters. More...
 
void FTM_SetupOutputCompare (FTM_Type *base, ftm_chnl_t chnlNumber, ftm_output_compare_mode_t compareMode, uint32_t compareValue)
 Configures the FTM to generate timed pulses. More...
 
void FTM_SetupDualEdgeCapture (FTM_Type *base, ftm_chnl_t chnlPairNumber, const ftm_dual_edge_capture_param_t *edgeParam, uint32_t filterValue)
 Configures the dual edge capture mode of the FTM. More...
 

Interrupt Interface

void FTM_EnableInterrupts (FTM_Type *base, uint32_t mask)
 Enables the selected FTM interrupts. More...
 
void FTM_DisableInterrupts (FTM_Type *base, uint32_t mask)
 Disables the selected FTM interrupts. More...
 
uint32_t FTM_GetEnabledInterrupts (FTM_Type *base)
 Gets the enabled FTM interrupts. More...
 

Status Interface

uint32_t FTM_GetStatusFlags (FTM_Type *base)
 Gets the FTM status flags. More...
 
void FTM_ClearStatusFlags (FTM_Type *base, uint32_t mask)
 Clears the FTM status flags. More...
 

Read and write the timer period

static void FTM_SetTimerPeriod (FTM_Type *base, uint32_t ticks)
 Sets the timer period in units of ticks. More...
 
static uint32_t FTM_GetCurrentTimerCount (FTM_Type *base)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void FTM_StartTimer (FTM_Type *base, ftm_clock_source_t clockSource)
 Starts the FTM counter. More...
 
static void FTM_StopTimer (FTM_Type *base)
 Stops the FTM counter. More...
 

Software output control

static void FTM_SetSoftwareCtrlEnable (FTM_Type *base, ftm_chnl_t chnlNumber, bool value)
 Enables or disables the channel software output control. More...
 
static void FTM_SetSoftwareCtrlVal (FTM_Type *base, ftm_chnl_t chnlNumber, bool value)
 Sets the channel software output control value. More...
 

Channel pair operations

static void FTM_SetFaultControlEnable (FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
 This function enables/disables the fault control in a channel pair. More...
 
static void FTM_SetDeadTimeEnable (FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
 This function enables/disables the dead time insertion in a channel pair. More...
 
static void FTM_SetComplementaryEnable (FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
 This function enables/disables complementary mode in a channel pair. More...
 
static void FTM_SetInvertEnable (FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
 This function enables/disables inverting control in a channel pair. More...
 

Quad Decoder

void FTM_SetupQuadDecode (FTM_Type *base, const ftm_phase_params_t *phaseAParams, const ftm_phase_params_t *phaseBParams, ftm_quad_decode_mode_t quadMode)
 Configures the parameters and activates the quadrature decoder mode. More...
 
static uint32_t FTM_GetQuadDecoderFlags (FTM_Type *base)
 Gets the FTM Quad Decoder flags. More...
 
static void FTM_SetQuadDecoderModuloValue (FTM_Type *base, uint32_t startValue, uint32_t overValue)
 Sets the modulo values for Quad Decoder. More...
 
static uint32_t FTM_GetQuadDecoderCounterValue (FTM_Type *base)
 Gets the current Quad Decoder counter value. More...
 
static void FTM_ClearQuadDecoderCounterValue (FTM_Type *base)
 Clears the current Quad Decoder counter value. More...
 

Data Structure Documentation

struct ftm_chnl_pwm_signal_param_t

Data Fields

ftm_chnl_t chnlNumber
 The channel/channel pair number. More...
 
ftm_pwm_level_select_t level
 PWM output active level select. More...
 
uint8_t dutyCyclePercent
 PWM pulse width, value should be between 0 to 100 0 = inactive signal(0% duty cycle)... More...
 
uint8_t firstEdgeDelayPercent
 Used only in combined PWM mode to generate an asymmetrical PWM. More...
 

Field Documentation

ftm_chnl_t ftm_chnl_pwm_signal_param_t::chnlNumber

In combined mode, this represents the channel pair number.

ftm_pwm_level_select_t ftm_chnl_pwm_signal_param_t::level
uint8_t ftm_chnl_pwm_signal_param_t::dutyCyclePercent

100 = always active signal (100% duty cycle).

uint8_t ftm_chnl_pwm_signal_param_t::firstEdgeDelayPercent

Specifies the delay to the first edge in a PWM period. If unsure leave as 0; Should be specified as a percentage of the PWM period

struct ftm_dual_edge_capture_param_t

Data Fields

ftm_dual_edge_capture_mode_t mode
 Dual Edge Capture mode.
 
ftm_input_capture_edge_t currChanEdgeMode
 Input capture edge select for channel n.
 
ftm_input_capture_edge_t nextChanEdgeMode
 Input capture edge select for channel n+1.
 
struct ftm_phase_params_t

Data Fields

bool enablePhaseFilter
 True: enable phase filter; false: disable filter.
 
uint32_t phaseFilterVal
 Filter value, used only if phase filter is enabled.
 
ftm_phase_polarity_t phasePolarity
 Phase polarity.
 
struct ftm_fault_param_t

Data Fields

bool enableFaultInput
 True: Fault input is enabled; false: Fault input is disabled.
 
bool faultLevel
 True: Fault polarity is active low; in other words, '0' indicates a fault; False: Fault polarity is active high.
 
bool useFaultFilter
 True: Use the filtered fault signal; False: Use the direct path from fault input.
 
struct ftm_config_t

This structure holds the configuration settings for the FTM peripheral. To initialize this structure to reasonable defaults, call the FTM_GetDefaultConfig() function and pass a pointer to the configuration structure instance.

The configuration structure can be made constant so as to reside in flash.

Data Fields

ftm_clock_prescale_t prescale
 FTM clock prescale value.
 
ftm_bdm_mode_t bdmMode
 FTM behavior in BDM mode.
 
uint32_t pwmSyncMode
 Synchronization methods to use to update buffered registers; Multiple update modes can be used by providing an OR'ed list of options available in enumeration ftm_pwm_sync_method_t. More...
 
uint32_t reloadPoints
 FTM reload points; When using this, the PWM synchronization is not required. More...
 
ftm_fault_mode_t faultMode
 FTM fault control mode.
 
uint8_t faultFilterValue
 Fault input filter value.
 
ftm_deadtime_prescale_t deadTimePrescale
 The dead time prescalar value.
 
uint32_t deadTimeValue
 The dead time value deadTimeValue's available range is 0-1023 when register has DTVALEX, otherwise its available range is 0-63. More...
 
uint32_t extTriggers
 External triggers to enable. More...
 
uint8_t chnlInitState
 Defines the initialization value of the channels in OUTINT register.
 
uint8_t chnlPolarity
 Defines the output polarity of the channels in POL register.
 
bool useGlobalTimeBase
 True: Use of an external global time base is enabled; False: disabled.
 

Field Documentation

uint32_t ftm_config_t::pwmSyncMode
uint32_t ftm_config_t::reloadPoints

Multiple reload points can be used by providing an OR'ed list of options available in enumeration ftm_reload_point_t.

uint32_t ftm_config_t::deadTimeValue
uint32_t ftm_config_t::extTriggers

Multiple trigger sources can be enabled by providing an OR'ed list of options available in enumeration ftm_external_trigger_t.

Enumeration Type Documentation

enum ftm_chnl_t
Note
Actual number of available channels is SoC dependent
Enumerator
kFTM_Chnl_0 

FTM channel number 0.

kFTM_Chnl_1 

FTM channel number 1.

kFTM_Chnl_2 

FTM channel number 2.

kFTM_Chnl_3 

FTM channel number 3.

kFTM_Chnl_4 

FTM channel number 4.

kFTM_Chnl_5 

FTM channel number 5.

kFTM_Chnl_6 

FTM channel number 6.

kFTM_Chnl_7 

FTM channel number 7.

Enumerator
kFTM_Fault_0 

FTM fault 0 input pin.

kFTM_Fault_1 

FTM fault 1 input pin.

kFTM_Fault_2 

FTM fault 2 input pin.

kFTM_Fault_3 

FTM fault 3 input pin.

Enumerator
kFTM_EdgeAlignedPwm 

Edge-aligned PWM.

kFTM_CenterAlignedPwm 

Center-aligned PWM.

kFTM_CombinedPwm 

Combined PWM.

Enumerator
kFTM_NoPwmSignal 

No PWM output on pin.

kFTM_LowTrue 

Low true pulses.

kFTM_HighTrue 

High true pulses.

Enumerator
kFTM_NoOutputSignal 

No channel output when counter reaches CnV.

kFTM_ToggleOnMatch 

Toggle output.

kFTM_ClearOnMatch 

Clear output.

kFTM_SetOnMatch 

Set output.

Enumerator
kFTM_RisingEdge 

Capture on rising edge only.

kFTM_FallingEdge 

Capture on falling edge only.

kFTM_RiseAndFallEdge 

Capture on rising or falling edge.

Enumerator
kFTM_OneShot 

One-shot capture mode.

kFTM_Continuous 

Continuous capture mode.

Enumerator
kFTM_QuadPhaseEncode 

Phase A and Phase B encoding mode.

kFTM_QuadCountAndDir 

Count and direction encoding mode.

Enumerator
kFTM_QuadPhaseNormal 

Phase input signal is not inverted.

kFTM_QuadPhaseInvert 

Phase input signal is inverted.

Enumerator
kFTM_Deadtime_Prescale_1 

Divide by 1.

kFTM_Deadtime_Prescale_4 

Divide by 4.

kFTM_Deadtime_Prescale_16 

Divide by 16.

Enumerator
kFTM_SystemClock 

System clock selected.

kFTM_FixedClock 

Fixed frequency clock.

kFTM_ExternalClock 

External clock.

Enumerator
kFTM_Prescale_Divide_1 

Divide by 1.

kFTM_Prescale_Divide_2 

Divide by 2.

kFTM_Prescale_Divide_4 

Divide by 4.

kFTM_Prescale_Divide_8 

Divide by 8.

kFTM_Prescale_Divide_16 

Divide by 16.

kFTM_Prescale_Divide_32 

Divide by 32.

kFTM_Prescale_Divide_64 

Divide by 64.

kFTM_Prescale_Divide_128 

Divide by 128.

Enumerator
kFTM_BdmMode_0 

FTM counter stopped, CH(n)F bit can be set, FTM channels in functional mode, writes to MOD,CNTIN and C(n)V registers bypass the register buffers.

kFTM_BdmMode_1 

FTM counter stopped, CH(n)F bit is not set, FTM channels outputs are forced to their safe value , writes to MOD,CNTIN and C(n)V registers bypass the register buffers.

kFTM_BdmMode_2 

FTM counter stopped, CH(n)F bit is not set, FTM channels outputs are frozen when chip enters in BDM mode, writes to MOD,CNTIN and C(n)V registers bypass the register buffers.

kFTM_BdmMode_3 

FTM counter in functional mode, CH(n)F bit can be set, FTM channels in functional mode, writes to MOD,CNTIN and C(n)V registers is in fully functional mode.

Enumerator
kFTM_Fault_Disable 

Fault control is disabled for all channels.

kFTM_Fault_EvenChnls 

Enabled for even channels only(0,2,4,6) with manual fault clearing.

kFTM_Fault_AllChnlsMan 

Enabled for all channels with manual fault clearing.

kFTM_Fault_AllChnlsAuto 

Enabled for all channels with automatic fault clearing.

Note
Actual available external trigger sources are SoC-specific
Enumerator
kFTM_Chnl0Trigger 

Generate trigger when counter equals chnl 0 CnV reg.

kFTM_Chnl1Trigger 

Generate trigger when counter equals chnl 1 CnV reg.

kFTM_Chnl2Trigger 

Generate trigger when counter equals chnl 2 CnV reg.

kFTM_Chnl3Trigger 

Generate trigger when counter equals chnl 3 CnV reg.

kFTM_Chnl4Trigger 

Generate trigger when counter equals chnl 4 CnV reg.

kFTM_Chnl5Trigger 

Generate trigger when counter equals chnl 5 CnV reg.

kFTM_Chnl6Trigger 

Available on certain SoC's, generate trigger when counter equals chnl 6 CnV reg.

kFTM_Chnl7Trigger 

Available on certain SoC's, generate trigger when counter equals chnl 7 CnV reg.

kFTM_InitTrigger 

Generate Trigger when counter is updated with CNTIN.

kFTM_ReloadInitTrigger 

Available on certain SoC's, trigger on reload point.

Enumerator
kFTM_SoftwareTrigger 

Software triggers PWM sync.

kFTM_HardwareTrigger_0 

Hardware trigger 0 causes PWM sync.

kFTM_HardwareTrigger_1 

Hardware trigger 1 causes PWM sync.

kFTM_HardwareTrigger_2 

Hardware trigger 2 causes PWM sync.

Note
Actual available reload points are SoC-specific
Enumerator
kFTM_Chnl0Match 

Channel 0 match included as a reload point.

kFTM_Chnl1Match 

Channel 1 match included as a reload point.

kFTM_Chnl2Match 

Channel 2 match included as a reload point.

kFTM_Chnl3Match 

Channel 3 match included as a reload point.

kFTM_Chnl4Match 

Channel 4 match included as a reload point.

kFTM_Chnl5Match 

Channel 5 match included as a reload point.

kFTM_Chnl6Match 

Channel 6 match included as a reload point.

kFTM_Chnl7Match 

Channel 7 match included as a reload point.

kFTM_CntMax 

Use in up-down count mode only, reload when counter reaches the maximum value.

kFTM_CntMin 

Use in up-down count mode only, reload when counter reaches the minimum value.

kFTM_HalfCycMatch 

Available on certain SoC's, half cycle match reload point.

Note
Actual available interrupts are SoC-specific
Enumerator
kFTM_Chnl0InterruptEnable 

Channel 0 interrupt.

kFTM_Chnl1InterruptEnable 

Channel 1 interrupt.

kFTM_Chnl2InterruptEnable 

Channel 2 interrupt.

kFTM_Chnl3InterruptEnable 

Channel 3 interrupt.

kFTM_Chnl4InterruptEnable 

Channel 4 interrupt.

kFTM_Chnl5InterruptEnable 

Channel 5 interrupt.

kFTM_Chnl6InterruptEnable 

Channel 6 interrupt.

kFTM_Chnl7InterruptEnable 

Channel 7 interrupt.

kFTM_FaultInterruptEnable 

Fault interrupt.

kFTM_TimeOverflowInterruptEnable 

Time overflow interrupt.

kFTM_ReloadInterruptEnable 

Reload interrupt; Available only on certain SoC's.

Note
Actual available flags are SoC-specific
Enumerator
kFTM_Chnl0Flag 

Channel 0 Flag.

kFTM_Chnl1Flag 

Channel 1 Flag.

kFTM_Chnl2Flag 

Channel 2 Flag.

kFTM_Chnl3Flag 

Channel 3 Flag.

kFTM_Chnl4Flag 

Channel 4 Flag.

kFTM_Chnl5Flag 

Channel 5 Flag.

kFTM_Chnl6Flag 

Channel 6 Flag.

kFTM_Chnl7Flag 

Channel 7 Flag.

kFTM_FaultFlag 

Fault Flag.

kFTM_TimeOverflowFlag 

Time overflow Flag.

kFTM_ChnlTriggerFlag 

Channel trigger Flag.

kFTM_ReloadFlag 

Reload Flag; Available only on certain SoC's.

Enumerator
kFTM_QuadDecoderCountingIncreaseFlag 

Counting direction is increasing (FTM counter increment), or the direction is decreasing.

kFTM_QuadDecoderCountingOverflowOnTopFlag 

Indicates if the TOF bit was set on the top or the bottom of counting.

Function Documentation

status_t FTM_Init ( FTM_Type *  base,
const ftm_config_t config 
)
Note
This API should be called at the beginning of the application which is using the FTM driver.
Parameters
baseFTM peripheral base address
configPointer to the user configuration structure.
Returns
kStatus_Success indicates success; Else indicates failure.
void FTM_Deinit ( FTM_Type *  base)
Parameters
baseFTM peripheral base address
void FTM_GetDefaultConfig ( ftm_config_t config)

The default values are:

* config->prescale = kFTM_Prescale_Divide_1;
* config->bdmMode = kFTM_BdmMode_0;
* config->pwmSyncMode = kFTM_SoftwareTrigger;
* config->reloadPoints = 0;
* config->faultMode = kFTM_Fault_Disable;
* config->faultFilterValue = 0;
* config->deadTimePrescale = kFTM_Deadtime_Prescale_1;
* config->deadTimeValue = 0;
* config->extTriggers = 0;
* config->chnlInitState = 0;
* config->chnlPolarity = 0;
* config->useGlobalTimeBase = false;
*
Parameters
configPointer to the user configuration structure.
status_t FTM_SetupPwm ( FTM_Type *  base,
const ftm_chnl_pwm_signal_param_t chnlParams,
uint8_t  numOfChnls,
ftm_pwm_mode_t  mode,
uint32_t  pwmFreq_Hz,
uint32_t  srcClock_Hz 
)

Call this function to configure the PWM signal period, mode, duty cycle, and edge. Use this function to configure all FTM channels that are used to output a PWM signal.

Parameters
baseFTM peripheral base address
chnlParamsArray of PWM channel parameters to configure the channel(s)
numOfChnlsNumber of channels to configure; This should be the size of the array passed in
modePWM operation mode, options available in enumeration ftm_pwm_mode_t
pwmFreq_HzPWM signal frequency in Hz
srcClock_HzFTM counter clock in Hz
Returns
kStatus_Success if the PWM setup was successful kStatus_Error on failure
void FTM_UpdatePwmDutycycle ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
ftm_pwm_mode_t  currentPwmMode,
uint8_t  dutyCyclePercent 
)
Parameters
baseFTM peripheral base address
chnlNumberThe channel/channel pair number. In combined mode, this represents the channel pair number
currentPwmModeThe current PWM mode set during PWM setup
dutyCyclePercentNew PWM pulse width; The value should be between 0 to 100 0=inactive signal(0% duty cycle)... 100=active signal (100% duty cycle)
void FTM_UpdateChnlEdgeLevelSelect ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
uint8_t  level 
)
Parameters
baseFTM peripheral base address
chnlNumberThe channel number
levelThe level to be set to the ELSnB:ELSnA field; Valid values are 00, 01, 10, 11. See the Kinetis SoC reference manual for details about this field.
void FTM_SetupInputCapture ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
ftm_input_capture_edge_t  captureMode,
uint32_t  filterValue 
)

When the edge specified in the captureMode argument occurs on the channel, the FTM counter is captured into the CnV register. The user has 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 for channels 0, 1, 2, 3.

Parameters
baseFTM peripheral base address
chnlNumberThe channel number
captureModeSpecifies which edge to capture
filterValueFilter value, specify 0 to disable filter. Available only for channels 0-3.
void FTM_SetupOutputCompare ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
ftm_output_compare_mode_t  compareMode,
uint32_t  compareValue 
)

When the FTM counter matches the value of compareVal argument (this is written into CnV reg), the channel output is changed based on what is specified in the compareMode argument.

Parameters
baseFTM peripheral base address
chnlNumberThe channel number
compareModeAction to take on the channel output when the compare condition is met
compareValueValue to be programmed in the CnV register.
void FTM_SetupDualEdgeCapture ( FTM_Type *  base,
ftm_chnl_t  chnlPairNumber,
const ftm_dual_edge_capture_param_t edgeParam,
uint32_t  filterValue 
)

This function sets up the dual edge capture mode on a channel pair. The capture edge for the channel pair and the capture mode (one-shot or continuous) is specified in the parameter argument. The filter function is disabled if the filterVal argument passed is zero. The filter function is available only on channels 0 and 2. The user has to read the channel CnV registers separately to get the capture values.

Parameters
baseFTM peripheral base address
chnlPairNumberThe FTM channel pair number; options are 0, 1, 2, 3
edgeParamSets up the dual edge capture function
filterValueFilter value, specify 0 to disable filter. Available only for channel pair 0 and 1.
void FTM_SetupFault ( FTM_Type *  base,
ftm_fault_input_t  faultNumber,
const ftm_fault_param_t faultParams 
)

FTM can have up to 4 fault inputs. This function sets up fault parameters, fault level, and a filter.

Parameters
baseFTM peripheral base address
faultNumberFTM fault to configure.
faultParamsParameters passed in to set up the fault
void FTM_EnableInterrupts ( FTM_Type *  base,
uint32_t  mask 
)
Parameters
baseFTM peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration ftm_interrupt_enable_t
void FTM_DisableInterrupts ( FTM_Type *  base,
uint32_t  mask 
)
Parameters
baseFTM peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration ftm_interrupt_enable_t
uint32_t FTM_GetEnabledInterrupts ( FTM_Type *  base)
Parameters
baseFTM peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration ftm_interrupt_enable_t
uint32_t FTM_GetStatusFlags ( FTM_Type *  base)
Parameters
baseFTM peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration ftm_status_flags_t
void FTM_ClearStatusFlags ( FTM_Type *  base,
uint32_t  mask 
)
Parameters
baseFTM peripheral base address
maskThe status flags to clear. This is a logical OR of members of the enumeration ftm_status_flags_t
static void FTM_SetTimerPeriod ( FTM_Type *  base,
uint32_t  ticks 
)
inlinestatic

Timers counts from 0 until it equals the count value set here. The count value is written to the MOD register.

Note
  1. This API allows the user to use the FTM module as a timer. Do not mix usage of this API with FTM's PWM setup API's.
  2. Call the utility macros provided in the fsl_common.h to convert usec or msec to ticks.
Parameters
baseFTM peripheral base address
ticksA timer period in units of ticks, which should be equal or greater than 1.
static uint32_t FTM_GetCurrentTimerCount ( FTM_Type *  base)
inlinestatic

This function returns the real-time timer counting value in a range from 0 to a timer period.

Note
Call the utility macros provided in the fsl_common.h to convert ticks to usec or msec.
Parameters
baseFTM peripheral base address
Returns
The current counter value in ticks
static void FTM_StartTimer ( FTM_Type *  base,
ftm_clock_source_t  clockSource 
)
inlinestatic
Parameters
baseFTM peripheral base address
clockSourceFTM clock source; After the clock source is set, the counter starts running.
static void FTM_StopTimer ( FTM_Type *  base)
inlinestatic
Parameters
baseFTM peripheral base address
static void FTM_SetSoftwareCtrlEnable ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlNumberChannel to be enabled or disabled
valuetrue: channel output is affected by software output control false: channel output is unaffected by software output control
static void FTM_SetSoftwareCtrlVal ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address.
chnlNumberChannel to be configured
valuetrue to set 1, false to set 0
static void FTM_SetGlobalTimeBaseOutputEnable ( FTM_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseFTM peripheral base address
enabletrue to enable, false to disable
static void FTM_SetOutputMask ( FTM_Type *  base,
ftm_chnl_t  chnlNumber,
bool  mask 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlNumberChannel to be configured
masktrue: masked, channel is forced to its inactive state; false: unmasked
static void FTM_SetFaultControlEnable ( FTM_Type *  base,
ftm_chnl_t  chnlPairNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlPairNumberThe FTM channel pair number; options are 0, 1, 2, 3
valuetrue: Enable fault control for this channel pair; false: No fault control
static void FTM_SetDeadTimeEnable ( FTM_Type *  base,
ftm_chnl_t  chnlPairNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlPairNumberThe FTM channel pair number; options are 0, 1, 2, 3
valuetrue: Insert dead time in this channel pair; false: No dead time inserted
static void FTM_SetComplementaryEnable ( FTM_Type *  base,
ftm_chnl_t  chnlPairNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlPairNumberThe FTM channel pair number; options are 0, 1, 2, 3
valuetrue: enable complementary mode; false: disable complementary mode
static void FTM_SetInvertEnable ( FTM_Type *  base,
ftm_chnl_t  chnlPairNumber,
bool  value 
)
inlinestatic
Parameters
baseFTM peripheral base address
chnlPairNumberThe FTM channel pair number; options are 0, 1, 2, 3
valuetrue: enable inverting; false: disable inverting
void FTM_SetupQuadDecode ( FTM_Type *  base,
const ftm_phase_params_t phaseAParams,
const ftm_phase_params_t phaseBParams,
ftm_quad_decode_mode_t  quadMode 
)
Parameters
baseFTM peripheral base address
phaseAParamsPhase A configuration parameters
phaseBParamsPhase B configuration parameters
quadModeSelects encoding mode used in quadrature decoder mode
static uint32_t FTM_GetQuadDecoderFlags ( FTM_Type *  base)
inlinestatic
Parameters
baseFTM peripheral base address.
Returns
Flag mask of FTM Quad Decoder, see _ftm_quad_decoder_flags.
static void FTM_SetQuadDecoderModuloValue ( FTM_Type *  base,
uint32_t  startValue,
uint32_t  overValue 
)
inlinestatic

The modulo values configure the minimum and maximum values that the Quad decoder counter can reach. After the counter goes over, the counter value goes to the other side and decrease/increase again.

Parameters
baseFTM peripheral base address.
startValueThe low limit value for Quad Decoder counter.
overValueThe high limit value for Quad Decoder counter.
static uint32_t FTM_GetQuadDecoderCounterValue ( FTM_Type *  base)
inlinestatic
Parameters
baseFTM peripheral base address.
Returns
Current quad Decoder counter value.
static void FTM_ClearQuadDecoderCounterValue ( FTM_Type *  base)
inlinestatic

The counter is set as the initial value.

Parameters
baseFTM peripheral base address.
static void FTM_SetSoftwareTrigger ( FTM_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseFTM peripheral base address
enabletrue: software trigger is selected, false: software trigger is not selected
static void FTM_SetWriteProtection ( FTM_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseFTM peripheral base address
enabletrue: Write-protection is enabled, false: Write-protection is disabled