MCUXpresso SDK API Reference Manual  Rev 2.15.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TPM: Timer PWM Module

Overview

The MCUXpresso SDK provides a driver for the Timer PWM Module (TPM) of MCUXpresso SDK devices.

The TPM driver supports the generation of PWM signals, input capture, and output compare modes. On some SoCs, the driver supports the generation of combined PWM signals, dual-edge capture, and quadrature decoder modes. The driver also supports configuring each of the TPM fault inputs. The fault input is available only on some SoCs.

Introduction of TPM

Initialization and deinitialization

The function TPM_Init() initializes the TPM with a specified configurations. The function TPM_GetDefaultConfig() gets the default configurations. On some SoCs, the initialization function issues a software reset to reset the TPM internal logic. The initialization function configures the TPM's behavior when it receives a trigger input and its operation in doze and debug modes.

The function TPM_Deinit() disables the TPM counter and turns off the module clock.

PWM Operations

The function TPM_SetupPwm() sets up TPM channels for the PWM output. The function can set up the PWM signal properties for multiple channels. Each channel has its own tpm_chnl_pwm_signal_param_t structure that is used to specify the output signals duty cycle and level-mode. However, the same PWM period and PWM mode is applied to all channels requesting a PWM output. The signal duty cycle is provided as a percentage of the PWM period. Its value should be between 0 and 100 where 0=inactive signal (0% duty cycle) and 100=always active signal (100% duty cycle). When generating a combined PWM signal, the channel number passed refers to a channel pair number, for example 0 refers to channel 0 and 1, 1 refers to channels 2 and 3.

The function TPM_UpdatePwmDutycycle() updates the PWM signal duty cycle of a particular TPM channel.

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

Input capture operations

The function TPM_SetupInputCapture() sets up a TPM channel for input capture. The user can specify the capture edge.

The function TPM_SetupDualEdgeCapture() can be used to measure the pulse width of a signal. This is available only for certain SoCs. A channel pair is used during the capture with the input signal coming through a channel that can be configured. The user can specify the capture edge for each channel and any filter value to be used when processing the input signal.

Output compare operations

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

Quad decode

The function TPM_SetupQuadDecode() sets up TPM channels 0 and 1 for quad decode, which is available only for certain SoCs. The user can specify the quad decode mode, polarity, and filter properties for each input signal.

Fault operation

The function TPM_SetupFault() sets up the properties for each fault, which is available only for certain SoCs. 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.

Status

Provides functions to get and clear the TPM status.

Interrupt

Provides functions to enable/disable TPM interrupts and get current enabled interrupts.

Typical use case

PWM output

Output the PWM signal on 2 TPM channels with different duty cycles. Periodically update the PWM signal duty cycle. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/tpm

Data Structures

struct  _tpm_chnl_pwm_signal_param
 Options to configure a TPM channel's PWM signal. More...
 
struct  _tpm_dual_edge_capture_param
 TPM dual edge capture parameters. More...
 
struct  _tpm_phase_param
 TPM quadrature decode phase parameters. More...
 
struct  _tpm_config
 TPM config structure. More...
 

Macros

#define TPM_MAX_COUNTER_VALUE(x)   ((1U != (uint8_t)FSL_FEATURE_TPM_HAS_32BIT_COUNTERn(x)) ? 0xFFFFU : 0xFFFFFFFFU)
 Help macro to get the max counter value.
 

Typedefs

typedef enum _tpm_chnl tpm_chnl_t
 List of TPM channels. More...
 
typedef enum _tpm_pwm_mode tpm_pwm_mode_t
 TPM PWM operation modes.
 
typedef enum _tpm_pwm_level_select tpm_pwm_level_select_t
 TPM PWM output pulse mode: high-true, low-true or no output. More...
 
typedef enum
_tpm_pwm_pause_level_select 
tpm_pwm_pause_level_select_t
 TPM PWM output when first enabled or paused: set or clear.
 
typedef enum
_tpm_chnl_control_bit_mask 
tpm_chnl_control_bit_mask_t
 List of TPM channel modes and level control bit mask.
 
typedef struct
_tpm_chnl_pwm_signal_param 
tpm_chnl_pwm_signal_param_t
 Options to configure a TPM channel's PWM signal.
 
typedef enum _tpm_trigger_select tpm_trigger_select_t
 Trigger sources available. More...
 
typedef enum _tpm_trigger_source tpm_trigger_source_t
 Trigger source options available. More...
 
typedef enum
_tpm_ext_trigger_polarity 
tpm_ext_trigger_polarity_t
 External trigger source polarity. More...
 
typedef enum
_tpm_output_compare_mode 
tpm_output_compare_mode_t
 TPM output compare modes.
 
typedef enum
_tpm_input_capture_edge 
tpm_input_capture_edge_t
 TPM input capture edge.
 
typedef struct
_tpm_dual_edge_capture_param 
tpm_dual_edge_capture_param_t
 TPM dual edge capture parameters. More...
 
typedef enum _tpm_quad_decode_mode tpm_quad_decode_mode_t
 TPM quadrature decode modes. More...
 
typedef enum _tpm_phase_polarity tpm_phase_polarity_t
 TPM quadrature phase polarities.
 
typedef struct _tpm_phase_param tpm_phase_params_t
 TPM quadrature decode phase parameters.
 
typedef enum _tpm_clock_source tpm_clock_source_t
 TPM clock source selection.
 
typedef enum _tpm_clock_prescale tpm_clock_prescale_t
 TPM prescale value selection for the clock source.
 
typedef struct _tpm_config tpm_config_t
 TPM config structure. More...
 
typedef enum _tpm_interrupt_enable tpm_interrupt_enable_t
 List of TPM interrupts.
 
typedef enum _tpm_status_flags tpm_status_flags_t
 List of TPM flags.
 

Enumerations

enum  _tpm_chnl {
  kTPM_Chnl_0 = 0U,
  kTPM_Chnl_1,
  kTPM_Chnl_2,
  kTPM_Chnl_3,
  kTPM_Chnl_4,
  kTPM_Chnl_5,
  kTPM_Chnl_6,
  kTPM_Chnl_7
}
 List of TPM channels. More...
 
enum  _tpm_pwm_mode {
  kTPM_EdgeAlignedPwm = 0U,
  kTPM_CenterAlignedPwm,
  kTPM_CombinedPwm
}
 TPM PWM operation modes. More...
 
enum  _tpm_pwm_level_select {
  kTPM_HighTrue = 0U,
  kTPM_LowTrue
}
 TPM PWM output pulse mode: high-true, low-true or no output. More...
 
enum  _tpm_pwm_pause_level_select {
  kTPM_ClearOnPause = 0U,
  kTPM_SetOnPause
}
 TPM PWM output when first enabled or paused: set or clear. More...
 
enum  _tpm_chnl_control_bit_mask {
  kTPM_ChnlELSnAMask = TPM_CnSC_ELSA_MASK,
  kTPM_ChnlELSnBMask = TPM_CnSC_ELSB_MASK,
  kTPM_ChnlMSAMask = TPM_CnSC_MSA_MASK,
  kTPM_ChnlMSBMask = TPM_CnSC_MSB_MASK
}
 List of TPM channel modes and level control bit mask. More...
 
enum  _tpm_trigger_select
 Trigger sources available. More...
 
enum  _tpm_trigger_source {
  kTPM_TriggerSource_External = 0U,
  kTPM_TriggerSource_Internal
}
 Trigger source options available. More...
 
enum  _tpm_ext_trigger_polarity {
  kTPM_ExtTrigger_Active_High = 0U,
  kTPM_ExtTrigger_Active_Low
}
 External trigger source polarity. More...
 
enum  _tpm_output_compare_mode {
  kTPM_NoOutputSignal = (1U << TPM_CnSC_MSA_SHIFT),
  kTPM_ToggleOnMatch = ((1U << TPM_CnSC_MSA_SHIFT) | (1U << TPM_CnSC_ELSA_SHIFT)),
  kTPM_ClearOnMatch = ((1U << TPM_CnSC_MSA_SHIFT) | (2U << TPM_CnSC_ELSA_SHIFT)),
  kTPM_SetOnMatch = ((1U << TPM_CnSC_MSA_SHIFT) | (3U << TPM_CnSC_ELSA_SHIFT)),
  kTPM_HighPulseOutput = ((3U << TPM_CnSC_MSA_SHIFT) | (1U << TPM_CnSC_ELSA_SHIFT)),
  kTPM_LowPulseOutput = ((3U << TPM_CnSC_MSA_SHIFT) | (2U << TPM_CnSC_ELSA_SHIFT))
}
 TPM output compare modes. More...
 
enum  _tpm_input_capture_edge {
  kTPM_RisingEdge = (1U << TPM_CnSC_ELSA_SHIFT),
  kTPM_FallingEdge = (2U << TPM_CnSC_ELSA_SHIFT),
  kTPM_RiseAndFallEdge = (3U << TPM_CnSC_ELSA_SHIFT)
}
 TPM input capture edge. More...
 
enum  _tpm_quad_decode_mode {
  kTPM_QuadPhaseEncode = 0U,
  kTPM_QuadCountAndDir
}
 TPM quadrature decode modes. More...
 
enum  _tpm_phase_polarity {
  kTPM_QuadPhaseNormal = 0U,
  kTPM_QuadPhaseInvert
}
 TPM quadrature phase polarities. More...
 
enum  _tpm_clock_source {
  kTPM_SystemClock = 1U,
  kTPM_ExternalClock,
  kTPM_ExternalInputTriggerClock
}
 TPM clock source selection. More...
 
enum  _tpm_clock_prescale {
  kTPM_Prescale_Divide_1 = 0U,
  kTPM_Prescale_Divide_2,
  kTPM_Prescale_Divide_4,
  kTPM_Prescale_Divide_8,
  kTPM_Prescale_Divide_16,
  kTPM_Prescale_Divide_32,
  kTPM_Prescale_Divide_64,
  kTPM_Prescale_Divide_128
}
 TPM prescale value selection for the clock source. More...
 
enum  _tpm_interrupt_enable {
  kTPM_Chnl0InterruptEnable = (1U << 0),
  kTPM_Chnl1InterruptEnable = (1U << 1),
  kTPM_Chnl2InterruptEnable = (1U << 2),
  kTPM_Chnl3InterruptEnable = (1U << 3),
  kTPM_Chnl4InterruptEnable = (1U << 4),
  kTPM_Chnl5InterruptEnable = (1U << 5),
  kTPM_Chnl6InterruptEnable = (1U << 6),
  kTPM_Chnl7InterruptEnable = (1U << 7),
  kTPM_TimeOverflowInterruptEnable = (1U << 8)
}
 List of TPM interrupts. More...
 
enum  _tpm_status_flags {
  kTPM_Chnl0Flag = (1U << 0),
  kTPM_Chnl1Flag = (1U << 1),
  kTPM_Chnl2Flag = (1U << 2),
  kTPM_Chnl3Flag = (1U << 3),
  kTPM_Chnl4Flag = (1U << 4),
  kTPM_Chnl5Flag = (1U << 5),
  kTPM_Chnl6Flag = (1U << 6),
  kTPM_Chnl7Flag = (1U << 7),
  kTPM_TimeOverflowFlag = (1U << 8)
}
 List of TPM flags. More...
 

Functions

static void TPM_Reset (TPM_Type *base)
 Performs a software reset on the TPM module. More...
 

Driver version

#define FSL_TPM_DRIVER_VERSION   (MAKE_VERSION(2, 2, 3))
 TPM driver version 2.2.3. More...
 

Initialization and deinitialization

void TPM_Init (TPM_Type *base, const tpm_config_t *config)
 Ungates the TPM clock and configures the peripheral for basic operation. More...
 
void TPM_Deinit (TPM_Type *base)
 Stops the counter and gates the TPM clock. More...
 
void TPM_GetDefaultConfig (tpm_config_t *config)
 Fill in the TPM config struct with the default settings. More...
 
tpm_clock_prescale_t TPM_CalculateCounterClkDiv (TPM_Type *base, uint32_t counterPeriod_Hz, uint32_t srcClock_Hz)
 Calculates the counter clock prescaler. More...
 

Channel mode operations

status_t TPM_SetupPwm (TPM_Type *base, const tpm_chnl_pwm_signal_param_t *chnlParams, uint8_t numOfChnls, tpm_pwm_mode_t mode, uint32_t pwmFreq_Hz, uint32_t srcClock_Hz)
 Configures the PWM signal parameters. More...
 
status_t TPM_UpdatePwmDutycycle (TPM_Type *base, tpm_chnl_t chnlNumber, tpm_pwm_mode_t currentPwmMode, uint8_t dutyCyclePercent)
 Update the duty cycle of an active PWM signal. More...
 
void TPM_UpdateChnlEdgeLevelSelect (TPM_Type *base, tpm_chnl_t chnlNumber, uint8_t level)
 Update the edge level selection for a channel. More...
 
static uint8_t TPM_GetChannelContorlBits (TPM_Type *base, tpm_chnl_t chnlNumber)
 Get the channel control bits value (mode, edge and level bit fileds). More...
 
static void TPM_DisableChannel (TPM_Type *base, tpm_chnl_t chnlNumber)
 Dsiable the channel. More...
 
static void TPM_EnableChannel (TPM_Type *base, tpm_chnl_t chnlNumber, uint8_t control)
 Enable the channel according to mode and level configs. More...
 
void TPM_SetupInputCapture (TPM_Type *base, tpm_chnl_t chnlNumber, tpm_input_capture_edge_t captureMode)
 Enables capturing an input signal on the channel using the function parameters. More...
 
void TPM_SetupOutputCompare (TPM_Type *base, tpm_chnl_t chnlNumber, tpm_output_compare_mode_t compareMode, uint32_t compareValue)
 Configures the TPM to generate timed pulses. More...
 
void TPM_SetupDualEdgeCapture (TPM_Type *base, tpm_chnl_t chnlPairNumber, const tpm_dual_edge_capture_param_t *edgeParam, uint32_t filterValue)
 Configures the dual edge capture mode of the TPM. More...
 
void TPM_SetupQuadDecode (TPM_Type *base, const tpm_phase_params_t *phaseAParams, const tpm_phase_params_t *phaseBParams, tpm_quad_decode_mode_t quadMode)
 Configures the parameters and activates the quadrature decode mode. More...
 
static void TPM_SetChannelPolarity (TPM_Type *base, tpm_chnl_t chnlNumber, bool enable)
 Set the input and output polarity of each of the channels. More...
 
static void TPM_EnableChannelExtTrigger (TPM_Type *base, tpm_chnl_t chnlNumber, bool enable)
 Enable external trigger input to be used by channel. More...
 

Interrupt Interface

void TPM_EnableInterrupts (TPM_Type *base, uint32_t mask)
 Enables the selected TPM interrupts. More...
 
void TPM_DisableInterrupts (TPM_Type *base, uint32_t mask)
 Disables the selected TPM interrupts. More...
 
uint32_t TPM_GetEnabledInterrupts (TPM_Type *base)
 Gets the enabled TPM interrupts. More...
 

Status Interface

static uint32_t TPM_GetChannelValue (TPM_Type *base, tpm_chnl_t chnlNumber)
 Gets the TPM channel value. More...
 
static uint32_t TPM_GetStatusFlags (TPM_Type *base)
 Gets the TPM status flags. More...
 
static void TPM_ClearStatusFlags (TPM_Type *base, uint32_t mask)
 Clears the TPM status flags. More...
 

Read and write the timer period

static void TPM_SetTimerPeriod (TPM_Type *base, uint32_t ticks)
 Sets the timer period in units of ticks. More...
 
static uint32_t TPM_GetCurrentTimerCount (TPM_Type *base)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void TPM_StartTimer (TPM_Type *base, tpm_clock_source_t clockSource)
 Starts the TPM counter. More...
 
static void TPM_StopTimer (TPM_Type *base)
 Stops the TPM counter. More...
 

Data Structure Documentation

struct _tpm_chnl_pwm_signal_param

Data Fields

tpm_chnl_t chnlNumber
 TPM channel to configure. More...
 
tpm_pwm_pause_level_select_t pauseLevel
 PWM output level when counter first enabled or paused.
 
tpm_pwm_level_select_t level
 PWM output active level select.
 
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 asymmetrical PWM. More...
 
bool enableComplementary
 Used only in combined PWM mode. More...
 
tpm_pwm_pause_level_select_t secPauseLevel
 Used only in combined PWM mode. More...
 
uint8_t deadTimeValue [2]
 The dead time value for channel n and n+1 in combined complementary PWM mode. More...
 

Field Documentation

tpm_chnl_t _tpm_chnl_pwm_signal_param::chnlNumber

In combined mode (available in some SoC's), this represents the channel pair number

uint8_t _tpm_chnl_pwm_signal_param::dutyCyclePercent

100=always active signal (100% duty cycle)

uint8_t _tpm_chnl_pwm_signal_param::firstEdgeDelayPercent

Specifies the delay to the first edge in a PWM period. If unsure, leave as 0. Should be specified as percentage of the PWM period, (dutyCyclePercent + firstEdgeDelayPercent) value should be not greate than 100.

bool _tpm_chnl_pwm_signal_param::enableComplementary

true: The combined channels output complementary signals; false: The combined channels output same signals;

tpm_pwm_pause_level_select_t _tpm_chnl_pwm_signal_param::secPauseLevel

Define the second channel output level when counter first enabled or paused

uint8_t _tpm_chnl_pwm_signal_param::deadTimeValue[2]

Deadtime insertion is disabled when this value is zero, otherwise deadtime insertion for channel n/n+1 is configured as (deadTimeValue * 4) clock cycles. deadTimeValue's available range is 0 ~ 15.

struct _tpm_dual_edge_capture_param
Note
This mode is available only on some SoC's.

Data Fields

bool enableSwap
 true: Use channel n+1 input, channel n input is ignored; false: Use channel n input, channel n+1 input is ignored
 
tpm_input_capture_edge_t currChanEdgeMode
 Input capture edge select for channel n.
 
tpm_input_capture_edge_t nextChanEdgeMode
 Input capture edge select for channel n+1.
 
struct _tpm_phase_param

Data Fields

uint32_t phaseFilterVal
 Filter value, filter is disabled when the value is zero.
 
tpm_phase_polarity_t phasePolarity
 Phase polarity.
 
struct _tpm_config

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

The config struct can be made const so it resides in flash

Data Fields

tpm_clock_prescale_t prescale
 Select TPM clock prescale value.
 
bool useGlobalTimeBase
 true: The TPM channels use an external global time base (the local counter still use for generate overflow interrupt and DMA request); false: All TPM channels use the local counter as their timebase
 
bool syncGlobalTimeBase
 true: The TPM counter is synchronized to the global time base; false: disabled
 
tpm_trigger_select_t triggerSelect
 Input trigger to use for controlling the counter operation.
 
tpm_trigger_source_t triggerSource
 Decides if we use external or internal trigger. More...
 
tpm_ext_trigger_polarity_t extTriggerPolarity
 when using external trigger source, need selects the polarity of it. More...
 
bool enableDoze
 true: TPM counter is paused in doze mode; false: TPM counter continues in doze mode
 
bool enableDebugMode
 true: TPM counter continues in debug mode; false: TPM counter is paused in debug mode
 
bool enableReloadOnTrigger
 true: TPM counter is reloaded on trigger; false: TPM counter not reloaded
 
bool enableStopOnOverflow
 true: TPM counter stops after overflow; false: TPM counter continues running after overflow
 
bool enableStartOnTrigger
 true: TPM counter only starts when a trigger is detected; false: TPM counter starts immediately
 
bool enablePauseOnTrigger
 true: TPM counter will pause while trigger remains asserted; false: TPM counter continues running
 
uint8_t chnlPolarity
 Defines the input/output polarity of the channels in POL register.
 

Field Documentation

tpm_trigger_source_t _tpm_config::triggerSource
tpm_ext_trigger_polarity_t _tpm_config::extTriggerPolarity

Macro Definition Documentation

#define FSL_TPM_DRIVER_VERSION   (MAKE_VERSION(2, 2, 3))

Typedef Documentation

typedef enum _tpm_chnl tpm_chnl_t
Note
Actual number of available channels is SoC dependent
Note
When the TPM has PWM pause level select feature, the PWM output cannot be turned off by selecting the output level. In this case, the channel must be closed to close the PWM output.

This is used for both internal & external trigger sources (external trigger sources available in certain SoC's)

Note
The actual trigger sources available is SoC-specific.
Note
This selection is available only on some SoC's. For SoC's without this selection, the only trigger source available is internal triger.
Note
Selects the polarity of the external trigger source.
Note
This mode is available only on some SoC's.
Note
This mode is available only on some SoC's.
typedef struct _tpm_config tpm_config_t

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

The config struct can be made const so it resides in flash

Enumeration Type Documentation

enum _tpm_chnl
Note
Actual number of available channels is SoC dependent
Enumerator
kTPM_Chnl_0 

TPM channel number 0.

kTPM_Chnl_1 

TPM channel number 1.

kTPM_Chnl_2 

TPM channel number 2.

kTPM_Chnl_3 

TPM channel number 3.

kTPM_Chnl_4 

TPM channel number 4.

kTPM_Chnl_5 

TPM channel number 5.

kTPM_Chnl_6 

TPM channel number 6.

kTPM_Chnl_7 

TPM channel number 7.

Enumerator
kTPM_EdgeAlignedPwm 

Edge aligned PWM.

kTPM_CenterAlignedPwm 

Center aligned PWM.

kTPM_CombinedPwm 

Combined PWM (Edge-aligned, center-aligned, or asymmetrical PWMs can be obtained in combined mode using different software configurations)

Note
When the TPM has PWM pause level select feature, the PWM output cannot be turned off by selecting the output level. In this case, the channel must be closed to close the PWM output.
Enumerator
kTPM_HighTrue 

High true pulses.

kTPM_LowTrue 

Low true pulses.

Enumerator
kTPM_ClearOnPause 

Clear Output when counter first enabled or paused.

kTPM_SetOnPause 

Set Output when counter first enabled or paused.

Enumerator
kTPM_ChnlELSnAMask 

Channel ELSA bit mask.

kTPM_ChnlELSnBMask 

Channel ELSB bit mask.

kTPM_ChnlMSAMask 

Channel MSA bit mask.

kTPM_ChnlMSBMask 

Channel MSB bit mask.

This is used for both internal & external trigger sources (external trigger sources available in certain SoC's)

Note
The actual trigger sources available is SoC-specific.
Note
This selection is available only on some SoC's. For SoC's without this selection, the only trigger source available is internal triger.
Enumerator
kTPM_TriggerSource_External 

Use external trigger input.

kTPM_TriggerSource_Internal 

Use internal trigger (channel pin input capture)

Note
Selects the polarity of the external trigger source.
Enumerator
kTPM_ExtTrigger_Active_High 

External trigger input is active high.

kTPM_ExtTrigger_Active_Low 

External trigger input is active low.

Enumerator
kTPM_NoOutputSignal 

No channel output when counter reaches CnV.

kTPM_ToggleOnMatch 

Toggle output.

kTPM_ClearOnMatch 

Clear output.

kTPM_SetOnMatch 

Set output.

kTPM_HighPulseOutput 

Pulse output high.

kTPM_LowPulseOutput 

Pulse output low.

Enumerator
kTPM_RisingEdge 

Capture on rising edge only.

kTPM_FallingEdge 

Capture on falling edge only.

kTPM_RiseAndFallEdge 

Capture on rising or falling edge.

Note
This mode is available only on some SoC's.
Enumerator
kTPM_QuadPhaseEncode 

Phase A and Phase B encoding mode.

kTPM_QuadCountAndDir 

Count and direction encoding mode.

Enumerator
kTPM_QuadPhaseNormal 

Phase input signal is not inverted.

kTPM_QuadPhaseInvert 

Phase input signal is inverted.

Enumerator
kTPM_SystemClock 

System clock.

kTPM_ExternalClock 

External TPM_EXTCLK pin clock.

kTPM_ExternalInputTriggerClock 

Selected external input trigger clock.

Enumerator
kTPM_Prescale_Divide_1 

Divide by 1.

kTPM_Prescale_Divide_2 

Divide by 2.

kTPM_Prescale_Divide_4 

Divide by 4.

kTPM_Prescale_Divide_8 

Divide by 8.

kTPM_Prescale_Divide_16 

Divide by 16.

kTPM_Prescale_Divide_32 

Divide by 32.

kTPM_Prescale_Divide_64 

Divide by 64.

kTPM_Prescale_Divide_128 

Divide by 128.

Enumerator
kTPM_Chnl0InterruptEnable 

Channel 0 interrupt.

kTPM_Chnl1InterruptEnable 

Channel 1 interrupt.

kTPM_Chnl2InterruptEnable 

Channel 2 interrupt.

kTPM_Chnl3InterruptEnable 

Channel 3 interrupt.

kTPM_Chnl4InterruptEnable 

Channel 4 interrupt.

kTPM_Chnl5InterruptEnable 

Channel 5 interrupt.

kTPM_Chnl6InterruptEnable 

Channel 6 interrupt.

kTPM_Chnl7InterruptEnable 

Channel 7 interrupt.

kTPM_TimeOverflowInterruptEnable 

Time overflow interrupt.

Enumerator
kTPM_Chnl0Flag 

Channel 0 flag.

kTPM_Chnl1Flag 

Channel 1 flag.

kTPM_Chnl2Flag 

Channel 2 flag.

kTPM_Chnl3Flag 

Channel 3 flag.

kTPM_Chnl4Flag 

Channel 4 flag.

kTPM_Chnl5Flag 

Channel 5 flag.

kTPM_Chnl6Flag 

Channel 6 flag.

kTPM_Chnl7Flag 

Channel 7 flag.

kTPM_TimeOverflowFlag 

Time overflow flag.

Function Documentation

void TPM_Init ( TPM_Type *  base,
const tpm_config_t config 
)
Note
This API should be called at the beginning of the application using the TPM driver.
Parameters
baseTPM peripheral base address
configPointer to user's TPM config structure.
void TPM_Deinit ( TPM_Type *  base)
Parameters
baseTPM peripheral base address
void TPM_GetDefaultConfig ( tpm_config_t config)

The default values are:

* config->prescale = kTPM_Prescale_Divide_1;
* config->useGlobalTimeBase = false;
* config->syncGlobalTimeBase = false;
* config->dozeEnable = false;
* config->dbgMode = false;
* config->enableReloadOnTrigger = false;
* config->enableStopOnOverflow = false;
* config->enableStartOnTrigger = false;
*#if FSL_FEATURE_TPM_HAS_PAUSE_COUNTER_ON_TRIGGER
* config->enablePauseOnTrigger = false;
*#endif
* config->triggerSelect = kTPM_Trigger_Select_0;
*#if FSL_FEATURE_TPM_HAS_EXTERNAL_TRIGGER_SELECTION
* config->triggerSource = kTPM_TriggerSource_External;
* config->extTriggerPolarity = kTPM_ExtTrigger_Active_High;
*#endif
*#if defined(FSL_FEATURE_TPM_HAS_POL) && FSL_FEATURE_TPM_HAS_POL
* config->chnlPolarity = 0U;
*#endif
*
Parameters
configPointer to user's TPM config structure.
tpm_clock_prescale_t TPM_CalculateCounterClkDiv ( TPM_Type *  base,
uint32_t  counterPeriod_Hz,
uint32_t  srcClock_Hz 
)

This function calculates the values for SC[PS].

Parameters
baseTPM peripheral base address
counterPeriod_HzThe desired frequency in Hz which corresponding to the time when the counter reaches the mod value
srcClock_HzTPM counter clock in Hz

return Calculated clock prescaler value.

status_t TPM_SetupPwm ( TPM_Type *  base,
const tpm_chnl_pwm_signal_param_t chnlParams,
uint8_t  numOfChnls,
tpm_pwm_mode_t  mode,
uint32_t  pwmFreq_Hz,
uint32_t  srcClock_Hz 
)

User calls this function to configure the PWM signals period, mode, dutycycle and edge. Use this function to configure all the TPM channels that will be used to output a PWM signal

Parameters
baseTPM 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 tpm_pwm_mode_t
pwmFreq_HzPWM signal frequency in Hz
srcClock_HzTPM counter clock in Hz
Returns
kStatus_Success if the PWM setup was successful, kStatus_Error on failure
status_t TPM_UpdatePwmDutycycle ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
tpm_pwm_mode_t  currentPwmMode,
uint8_t  dutyCyclePercent 
)
Parameters
baseTPM peripheral base address
chnlNumberThe channel number. In combined mode, this represents the channel pair number
currentPwmModeThe current PWM mode set during PWM setup
dutyCyclePercentNew PWM pulse width, value should be between 0 to 100 0=inactive signal(0% duty cycle)... 100=active signal (100% duty cycle)
Returns
kStatus_Success if the PWM setup was successful, kStatus_Error on failure
void TPM_UpdateChnlEdgeLevelSelect ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
uint8_t  level 
)
Note
When the TPM has PWM pause level select feature (FSL_FEATURE_TPM_HAS_PAUSE_LEVEL_SELECT = 1), the PWM output cannot be turned off by selecting the output level. In this case, must use TPM_DisableChannel API to close the PWM output.
Parameters
baseTPM 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 appropriate SoC reference manual for details about this field.
static uint8_t TPM_GetChannelContorlBits ( TPM_Type *  base,
tpm_chnl_t  chnlNumber 
)
inlinestatic

This function disable the channel by clear all mode and level control bits.

Parameters
baseTPM peripheral base address
chnlNumberThe channel number
Returns
The contorl bits value. This is the logical OR of members of the enumeration tpm_chnl_control_bit_mask_t.
static void TPM_DisableChannel ( TPM_Type *  base,
tpm_chnl_t  chnlNumber 
)
inlinestatic

This function disable the channel by clear all mode and level control bits.

Parameters
baseTPM peripheral base address
chnlNumberThe channel number
static void TPM_EnableChannel ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
uint8_t  control 
)
inlinestatic

This function enable the channel output according to input mode/level config parameters.

Parameters
baseTPM peripheral base address
chnlNumberThe channel number
controlThe contorl bits value. This is the logical OR of members of the enumeration tpm_chnl_control_bit_mask_t.
void TPM_SetupInputCapture ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
tpm_input_capture_edge_t  captureMode 
)

When the edge specified in the captureMode argument occurs on the channel, the TPM counter is captured into the CnV register. The user has to read the CnV register separately to get this value.

Parameters
baseTPM peripheral base address
chnlNumberThe channel number
captureModeSpecifies which edge to capture
void TPM_SetupOutputCompare ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
tpm_output_compare_mode_t  compareMode,
uint32_t  compareValue 
)

When the TPM 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
baseTPM 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 TPM_SetupDualEdgeCapture ( TPM_Type *  base,
tpm_chnl_t  chnlPairNumber,
const tpm_dual_edge_capture_param_t edgeParam,
uint32_t  filterValue 
)

This function allows to measure a pulse width of the signal on the input of channel of a channel pair. The filter function is disabled if the filterVal argument passed is zero.

Parameters
baseTPM peripheral base address
chnlPairNumberThe TPM channel pair number; options are 0, 1, 2, 3
edgeParamSets up the dual edge capture function
filterValueFilter value, specify 0 to disable filter.
void TPM_SetupQuadDecode ( TPM_Type *  base,
const tpm_phase_params_t phaseAParams,
const tpm_phase_params_t phaseBParams,
tpm_quad_decode_mode_t  quadMode 
)
Parameters
baseTPM peripheral base address
phaseAParamsPhase A configuration parameters
phaseBParamsPhase B configuration parameters
quadModeSelects encoding mode used in quadrature decoder mode
static void TPM_SetChannelPolarity ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
bool  enable 
)
inlinestatic
Parameters
baseTPM peripheral base address
chnlNumberThe channel number
enabletrue: Set the channel polarity to active high; false: Set the channel polarity to active low;
static void TPM_EnableChannelExtTrigger ( TPM_Type *  base,
tpm_chnl_t  chnlNumber,
bool  enable 
)
inlinestatic

In input capture mode, configures the trigger input that is used by the channel to capture the counter value. In output compare or PWM mode, configures the trigger input used to modulate the channel output. When modulating the output, the output is forced to the channel initial value whenever the trigger is not asserted.

Note
No matter how many external trigger sources there are, only input trigger 0 and 1 are used. The even numbered channels share the input trigger 0 and the odd numbered channels share the second input trigger 1.
Parameters
baseTPM peripheral base address
chnlNumberThe channel number
enabletrue: Configures trigger input 0 or 1 to be used by channel; false: Trigger input has no effect on the channel
void TPM_EnableInterrupts ( TPM_Type *  base,
uint32_t  mask 
)
Parameters
baseTPM peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration tpm_interrupt_enable_t
void TPM_DisableInterrupts ( TPM_Type *  base,
uint32_t  mask 
)
Parameters
baseTPM peripheral base address
maskThe interrupts to disable. This is a logical OR of members of the enumeration tpm_interrupt_enable_t
uint32_t TPM_GetEnabledInterrupts ( TPM_Type *  base)
Parameters
baseTPM peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration tpm_interrupt_enable_t
static uint32_t TPM_GetChannelValue ( TPM_Type *  base,
tpm_chnl_t  chnlNumber 
)
inlinestatic
Note
The TPM channel value contain the captured TPM counter value for the input modes or the match value for the output modes.
Parameters
baseTPM peripheral base address
chnlNumberThe channel number
Returns
The channle CnV regisyer value.
static uint32_t TPM_GetStatusFlags ( TPM_Type *  base)
inlinestatic
Parameters
baseTPM peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration tpm_status_flags_t
static void TPM_ClearStatusFlags ( TPM_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseTPM peripheral base address
maskThe status flags to clear. This is a logical OR of members of the enumeration tpm_status_flags_t
static void TPM_SetTimerPeriod ( TPM_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 TPM module as a timer. Do not mix usage of this API with TPM's PWM setup API's.
  2. Call the utility macros provided in the fsl_common.h to convert usec or msec to ticks.
Parameters
baseTPM peripheral base address
ticksA timer period in units of ticks, which should be equal or greater than 1.
static uint32_t TPM_GetCurrentTimerCount ( TPM_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
baseTPM peripheral base address
Returns
The current counter value in ticks
static void TPM_StartTimer ( TPM_Type *  base,
tpm_clock_source_t  clockSource 
)
inlinestatic
Parameters
baseTPM peripheral base address
clockSourceTPM clock source; once clock source is set the counter will start running
static void TPM_StopTimer ( TPM_Type *  base)
inlinestatic
Parameters
baseTPM peripheral base address
static void TPM_Reset ( TPM_Type *  base)
inlinestatic

Reset all internal logic and registers, except the Global Register. Remains set until cleared by software.

Note
TPM software reset is available on certain SoC's only
Parameters
baseTPM peripheral base address