MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
QTMR: Quad Timer Driver

Overview

The MCUXpresso SDK provides a driver for the QTMR module of MCUXpresso SDK devices.

Data Structures

struct  _qtmr_config
 Quad Timer config structure. More...
 

Typedefs

typedef enum
_qtmr_primary_count_source 
qtmr_primary_count_source_t
 Quad Timer primary clock source selection.
 
typedef enum _qtmr_input_source qtmr_input_source_t
 Quad Timer input sources selection.
 
typedef enum _qtmr_counting_mode qtmr_counting_mode_t
 Quad Timer counting mode selection.
 
typedef enum _qtmr_pwm_out_state qtmr_pwm_out_state_t
 Quad Timer PWM output state.
 
typedef enum _qtmr_output_mode qtmr_output_mode_t
 Quad Timer output mode selection.
 
typedef enum
_qtmr_input_capture_edge 
qtmr_input_capture_edge_t
 Quad Timer input capture edge mode, rising edge, or falling edge.
 
typedef enum _qtmr_preload_control qtmr_preload_control_t
 Quad Timer input capture edge mode, rising edge, or falling edge.
 
typedef enum _qtmr_debug_action qtmr_debug_action_t
 List of Quad Timer run options when in Debug mode.
 
typedef enum _qtmr_interrupt_enable qtmr_interrupt_enable_t
 List of Quad Timer interrupts.
 
typedef enum _qtmr_status_flags qtmr_status_flags_t
 List of Quad Timer flags.
 
typedef enum
_qtmr_channel_selection 
qtmr_channel_selection_t
 List of channel selection.
 
typedef enum _qtmr_dma_enable qtmr_dma_enable_t
 List of Quad Timer DMA enable.
 
typedef struct _qtmr_config qtmr_config_t
 Quad Timer config structure. More...
 

Enumerations

enum  _qtmr_primary_count_source {
  kQTMR_ClockCounter0InputPin = 0,
  kQTMR_ClockCounter1InputPin,
  kQTMR_ClockCounter2InputPin,
  kQTMR_ClockCounter3InputPin,
  kQTMR_ClockCounter0Output,
  kQTMR_ClockCounter1Output,
  kQTMR_ClockCounter2Output,
  kQTMR_ClockCounter3Output,
  kQTMR_ClockDivide_1,
  kQTMR_ClockDivide_2,
  kQTMR_ClockDivide_4,
  kQTMR_ClockDivide_8,
  kQTMR_ClockDivide_16,
  kQTMR_ClockDivide_32,
  kQTMR_ClockDivide_64,
  kQTMR_ClockDivide_128
}
 Quad Timer primary clock source selection. More...
 
enum  _qtmr_input_source {
  kQTMR_Counter0InputPin = 0,
  kQTMR_Counter1InputPin,
  kQTMR_Counter2InputPin,
  kQTMR_Counter3InputPin
}
 Quad Timer input sources selection. More...
 
enum  _qtmr_counting_mode {
  kQTMR_NoOperation = 0,
  kQTMR_PriSrcRiseEdge,
  kQTMR_PriSrcRiseAndFallEdge,
  kQTMR_PriSrcRiseEdgeSecInpHigh,
  kQTMR_QuadCountMode,
  kQTMR_PriSrcRiseEdgeSecDir,
  kQTMR_SecSrcTrigPriCnt,
  kQTMR_CascadeCount
}
 Quad Timer counting mode selection. More...
 
enum  _qtmr_pwm_out_state {
  kQTMR_PwmLow = 0,
  kQTMR_PwmHigh
}
 Quad Timer PWM output state. More...
 
enum  _qtmr_output_mode {
  kQTMR_AssertWhenCountActive = 0,
  kQTMR_ClearOnCompare,
  kQTMR_SetOnCompare,
  kQTMR_ToggleOnCompare,
  kQTMR_ToggleOnAltCompareReg,
  kQTMR_SetOnCompareClearOnSecSrcInp,
  kQTMR_SetOnCompareClearOnCountRoll,
  kQTMR_EnableGateClock
}
 Quad Timer output mode selection. More...
 
enum  _qtmr_input_capture_edge {
  kQTMR_NoCapture = 0,
  kQTMR_RisingEdge,
  kQTMR_FallingEdge,
  kQTMR_RisingAndFallingEdge
}
 Quad Timer input capture edge mode, rising edge, or falling edge. More...
 
enum  _qtmr_preload_control {
  kQTMR_NoPreload = 0,
  kQTMR_LoadOnComp1,
  kQTMR_LoadOnComp2
}
 Quad Timer input capture edge mode, rising edge, or falling edge. More...
 
enum  _qtmr_debug_action {
  kQTMR_RunNormalInDebug = 0U,
  kQTMR_HaltCounter,
  kQTMR_ForceOutToZero,
  kQTMR_HaltCountForceOutZero
}
 List of Quad Timer run options when in Debug mode. More...
 
enum  _qtmr_interrupt_enable {
  kQTMR_CompareInterruptEnable = (1U << 0),
  kQTMR_Compare1InterruptEnable = (1U << 1),
  kQTMR_Compare2InterruptEnable = (1U << 2),
  kQTMR_OverflowInterruptEnable = (1U << 3),
  kQTMR_EdgeInterruptEnable = (1U << 4)
}
 List of Quad Timer interrupts. More...
 
enum  _qtmr_status_flags {
  kQTMR_CompareFlag = (1U << 0),
  kQTMR_Compare1Flag = (1U << 1),
  kQTMR_Compare2Flag = (1U << 2),
  kQTMR_OverflowFlag = (1U << 3),
  kQTMR_EdgeFlag = (1U << 4)
}
 List of Quad Timer flags. More...
 
enum  _qtmr_channel_selection {
  kQTMR_Channel_0 = 0U,
  kQTMR_Channel_1,
  kQTMR_Channel_2,
  kQTMR_Channel_3
}
 List of channel selection. More...
 
enum  _qtmr_dma_enable {
  kQTMR_InputEdgeFlagDmaEnable = (1U << 0),
  kQTMR_ComparatorPreload1DmaEnable = (1U << 1),
  kQTMR_ComparatorPreload2DmaEnable = (1U << 2)
}
 List of Quad Timer DMA enable. More...
 

Functions

status_t QTMR_SetupPwm (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t pwmFreqHz, uint8_t dutyCyclePercent, bool outputPolarity, uint32_t srcClock_Hz)
 Sets up Quad timer module for PWM signal output. More...
 
void QTMR_SetupInputCapture (TMR_Type *base, qtmr_channel_selection_t channel, qtmr_input_source_t capturePin, bool inputPolarity, bool reloadOnCapture, qtmr_input_capture_edge_t captureMode)
 Allows the user to count the source clock cycles until a capture event arrives. More...
 

Driver version

#define FSL_QTMR_DRIVER_VERSION   (MAKE_VERSION(2, 2, 2))
 Version.
 

Initialization and deinitialization

void QTMR_Init (TMR_Type *base, qtmr_channel_selection_t channel, const qtmr_config_t *config)
 Ungates the Quad Timer clock and configures the peripheral for basic operation. More...
 
void QTMR_Deinit (TMR_Type *base, qtmr_channel_selection_t channel)
 Stops the counter and gates the Quad Timer clock. More...
 
void QTMR_GetDefaultConfig (qtmr_config_t *config)
 Fill in the Quad Timer config struct with the default settings. More...
 

Interrupt Interface

void QTMR_EnableInterrupts (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
 Enables the selected Quad Timer interrupts. More...
 
void QTMR_DisableInterrupts (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
 Disables the selected Quad Timer interrupts. More...
 
uint32_t QTMR_GetEnabledInterrupts (TMR_Type *base, qtmr_channel_selection_t channel)
 Gets the enabled Quad Timer interrupts. More...
 

Status Interface

uint32_t QTMR_GetStatus (TMR_Type *base, qtmr_channel_selection_t channel)
 Gets the Quad Timer status flags. More...
 
void QTMR_ClearStatusFlags (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
 Clears the Quad Timer status flags. More...
 

Read and Write the timer period

void QTMR_SetTimerPeriod (TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks)
 Sets the timer period in ticks. More...
 
void QTMR_SetCompareValue (TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks)
 Set compare value. More...
 
static void QTMR_SetLoadValue (TMR_Type *base, qtmr_channel_selection_t channel, uint16_t value)
 Set load value. More...
 
static uint16_t QTMR_GetCurrentTimerCount (TMR_Type *base, qtmr_channel_selection_t channel)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void QTMR_StartTimer (TMR_Type *base, qtmr_channel_selection_t channel, qtmr_counting_mode_t clockSource)
 Starts the Quad Timer counter. More...
 
static void QTMR_StopTimer (TMR_Type *base, qtmr_channel_selection_t channel)
 Stops the Quad Timer counter. More...
 

Enable and Disable the Quad Timer DMA

void QTMR_EnableDma (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
 Enable the Quad Timer DMA. More...
 
void QTMR_DisableDma (TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
 Disable the Quad Timer DMA. More...
 
void QTMR_SetPwmOutputToIdle (TMR_Type *base, qtmr_channel_selection_t channel, bool idleStatus)
 Set PWM output in idle status (high or low). More...
 
static qtmr_pwm_out_state_t QTMR_GetPwmOutputStatus (TMR_Type *base, qtmr_channel_selection_t channel)
 Get the channel output status. More...
 
uint8_t QTMR_GetPwmChannelStatus (TMR_Type *base, qtmr_channel_selection_t channel)
 Get the PWM channel dutycycle value. More...
 
void QTMR_SetPwmClockMode (TMR_Type *base, qtmr_channel_selection_t channel, qtmr_primary_count_source_t prescaler)
 This function set the value of the prescaler on QTimer channels. More...
 

Data Structure Documentation

struct _qtmr_config

This structure holds the configuration settings for the Quad Timer peripheral. To initialize this structure to reasonable defaults, call the QTMR_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

qtmr_primary_count_source_t primarySource
 Specify the primary count source.
 
qtmr_input_source_t secondarySource
 Specify the secondary count source.
 
bool enableMasterMode
 true: Broadcast compare function output to other counters; false no broadcast
 
bool enableExternalForce
 true: Compare from another counter force state of OFLAG signal false: OFLAG controlled by local counter
 
uint8_t faultFilterCount
 Fault filter count.
 
uint8_t faultFilterPeriod
 Fault filter period;value of 0 will bypass the filter.
 
qtmr_debug_action_t debugMode
 Operation in Debug mode.
 

Typedef Documentation

typedef struct _qtmr_config qtmr_config_t

This structure holds the configuration settings for the Quad Timer peripheral. To initialize this structure to reasonable defaults, call the QTMR_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

Enumerator
kQTMR_ClockCounter0InputPin 

Use counter 0 input pin.

kQTMR_ClockCounter1InputPin 

Use counter 1 input pin.

kQTMR_ClockCounter2InputPin 

Use counter 2 input pin.

kQTMR_ClockCounter3InputPin 

Use counter 3 input pin.

kQTMR_ClockCounter0Output 

Use counter 0 output.

kQTMR_ClockCounter1Output 

Use counter 1 output.

kQTMR_ClockCounter2Output 

Use counter 2 output.

kQTMR_ClockCounter3Output 

Use counter 3 output.

kQTMR_ClockDivide_1 

IP bus clock divide by 1 prescaler.

kQTMR_ClockDivide_2 

IP bus clock divide by 2 prescaler.

kQTMR_ClockDivide_4 

IP bus clock divide by 4 prescaler.

kQTMR_ClockDivide_8 

IP bus clock divide by 8 prescaler.

kQTMR_ClockDivide_16 

IP bus clock divide by 16 prescaler.

kQTMR_ClockDivide_32 

IP bus clock divide by 32 prescaler.

kQTMR_ClockDivide_64 

IP bus clock divide by 64 prescaler.

kQTMR_ClockDivide_128 

IP bus clock divide by 128 prescaler.

Enumerator
kQTMR_Counter0InputPin 

Use counter 0 input pin.

kQTMR_Counter1InputPin 

Use counter 1 input pin.

kQTMR_Counter2InputPin 

Use counter 2 input pin.

kQTMR_Counter3InputPin 

Use counter 3 input pin.

Enumerator
kQTMR_NoOperation 

No operation.

kQTMR_PriSrcRiseEdge 

Count rising edges of primary source.

kQTMR_PriSrcRiseAndFallEdge 

Count rising and falling edges of primary source.

kQTMR_PriSrcRiseEdgeSecInpHigh 

Count rise edges of pri SRC while sec inp high active.

kQTMR_QuadCountMode 

Quadrature count mode, uses pri and sec sources.

kQTMR_PriSrcRiseEdgeSecDir 

Count rising edges of pri SRC; sec SRC specifies dir.

kQTMR_SecSrcTrigPriCnt 

Edge of sec SRC trigger primary count until compare.

kQTMR_CascadeCount 

Cascaded count mode (up/down)

Enumerator
kQTMR_PwmLow 

The output state of PWM channel is low.

kQTMR_PwmHigh 

The output state of PWM channel is low.

Enumerator
kQTMR_AssertWhenCountActive 

Assert OFLAG while counter is active.

kQTMR_ClearOnCompare 

Clear OFLAG on successful compare.

kQTMR_SetOnCompare 

Set OFLAG on successful compare.

kQTMR_ToggleOnCompare 

Toggle OFLAG on successful compare.

kQTMR_ToggleOnAltCompareReg 

Toggle OFLAG using alternating compare registers.

kQTMR_SetOnCompareClearOnSecSrcInp 

Set OFLAG on compare, clear on sec SRC input edge.

kQTMR_SetOnCompareClearOnCountRoll 

Set OFLAG on compare, clear on counter rollover.

kQTMR_EnableGateClock 

Enable gated clock output while count is active.

Enumerator
kQTMR_NoCapture 

Capture is disabled.

kQTMR_RisingEdge 

Capture on rising edge (IPS=0) or falling edge (IPS=1)

kQTMR_FallingEdge 

Capture on falling edge (IPS=0) or rising edge (IPS=1)

kQTMR_RisingAndFallingEdge 

Capture on both edges.

Enumerator
kQTMR_NoPreload 

Never preload.

kQTMR_LoadOnComp1 

Load upon successful compare with value in COMP1.

kQTMR_LoadOnComp2 

Load upon successful compare with value in COMP2.

Enumerator
kQTMR_RunNormalInDebug 

Continue with normal operation.

kQTMR_HaltCounter 

Halt counter.

kQTMR_ForceOutToZero 

Force output to logic 0.

kQTMR_HaltCountForceOutZero 

Halt counter and force output to logic 0.

Enumerator
kQTMR_CompareInterruptEnable 

Compare interrupt.

kQTMR_Compare1InterruptEnable 

Compare 1 interrupt.

kQTMR_Compare2InterruptEnable 

Compare 2 interrupt.

kQTMR_OverflowInterruptEnable 

Timer overflow interrupt.

kQTMR_EdgeInterruptEnable 

Input edge interrupt.

Enumerator
kQTMR_CompareFlag 

Compare flag.

kQTMR_Compare1Flag 

Compare 1 flag.

kQTMR_Compare2Flag 

Compare 2 flag.

kQTMR_OverflowFlag 

Timer overflow flag.

kQTMR_EdgeFlag 

Input edge flag.

Enumerator
kQTMR_Channel_0 

TMR Channel 0.

kQTMR_Channel_1 

TMR Channel 1.

kQTMR_Channel_2 

TMR Channel 2.

kQTMR_Channel_3 

TMR Channel 3.

Enumerator
kQTMR_InputEdgeFlagDmaEnable 

Input Edge Flag DMA Enable.

kQTMR_ComparatorPreload1DmaEnable 

Comparator Preload Register 1 DMA Enable.

kQTMR_ComparatorPreload2DmaEnable 

Comparator Preload Register 2 DMA Enable.

Function Documentation

void QTMR_Init ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
const qtmr_config_t config 
)
Note
This API should be called at the beginning of the application using the Quad Timer driver.
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
configPointer to user's Quad Timer config structure
void QTMR_Deinit ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
void QTMR_GetDefaultConfig ( qtmr_config_t config)

The default values are:

* config->debugMode = kQTMR_RunNormalInDebug;
* config->enableExternalForce = false;
* config->enableMasterMode = false;
* config->faultFilterCount = 0;
* config->faultFilterPeriod = 0;
* config->primarySource = kQTMR_ClockDivide_2;
* config->secondarySource = kQTMR_Counter0InputPin;
*
Parameters
configPointer to user's Quad Timer config structure.
status_t QTMR_SetupPwm ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  pwmFreqHz,
uint8_t  dutyCyclePercent,
bool  outputPolarity,
uint32_t  srcClock_Hz 
)

The function initializes the timer module according to the parameters passed in by the user. The function also sets up the value compare registers to match the PWM signal requirements.

Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
pwmFreqHzPWM signal frequency in Hz
dutyCyclePercentPWM pulse width, value should be between 0 to 100 0=inactive signal(0% duty cycle)... 100=active signal (100% duty cycle)
outputPolaritytrue: invert polarity of the output signal, false: no inversion
srcClock_HzMain counter clock in Hz.
Returns
Returns an error if there was error setting up the signal.
void QTMR_SetupInputCapture ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
qtmr_input_source_t  capturePin,
bool  inputPolarity,
bool  reloadOnCapture,
qtmr_input_capture_edge_t  captureMode 
)

The count is stored in the capture register.

Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
capturePinPin through which we receive the input signal to trigger the capture
inputPolaritytrue: invert polarity of the input signal, false: no inversion
reloadOnCapturetrue: reload the counter when an input capture occurs, false: no reload
captureModeSpecifies which edge of the input signal triggers a capture
void QTMR_EnableInterrupts ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
maskThe interrupts to enable. This is a logical OR of members of the enumeration qtmr_interrupt_enable_t
void QTMR_DisableInterrupts ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base addres
channelQuad Timer channel number
maskThe interrupts to enable. This is a logical OR of members of the enumeration qtmr_interrupt_enable_t
uint32_t QTMR_GetEnabledInterrupts ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
Returns
The enabled interrupts. This is the logical OR of members of the enumeration qtmr_interrupt_enable_t
uint32_t QTMR_GetStatus ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
Returns
The status flags. This is the logical OR of members of the enumeration qtmr_status_flags_t
void QTMR_ClearStatusFlags ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
maskThe status flags to clear. This is a logical OR of members of the enumeration qtmr_status_flags_t
void QTMR_SetTimerPeriod ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint16_t  ticks 
)

Timers counts from initial value till it equals the count value set here. The counter will then reinitialize to the value specified in the Load register.

Note
  1. This function will write the time period in ticks to COMP1 or COMP2 register depending on the count direction
  2. User can call the utility macros provided in fsl_common.h to convert to ticks
  3. This function supports cases, providing only primary source clock without secondary source clock.
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
ticksTimer period in units of ticks
void QTMR_SetCompareValue ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint16_t  ticks 
)

This function sets the value used for comparison with the counter value.

Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
ticksTimer period in units of ticks.
static void QTMR_SetLoadValue ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint16_t  value 
)
inlinestatic

This function sets the value used to initialize the counter after a counter comparison.

Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
valueLoad register initialization value.
static uint16_t QTMR_GetCurrentTimerCount ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
inlinestatic

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

Note
User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
Returns
Current counter value in ticks
static void QTMR_StartTimer ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
qtmr_counting_mode_t  clockSource 
)
inlinestatic
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
clockSourceQuad Timer clock source
static void QTMR_StopTimer ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
inlinestatic
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
void QTMR_EnableDma ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
maskThe DMA to enable. This is a logical OR of members of the enumeration qtmr_dma_enable_t
void QTMR_DisableDma ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
maskThe DMA to enable. This is a logical OR of members of the enumeration qtmr_dma_enable_t
void QTMR_SetPwmOutputToIdle ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
bool  idleStatus 
)
Note
When the PWM is set again, the counting needs to be restarted.
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
idleStatusTrue: PWM output is high in idle status; false: PWM output is low in idle status.
static qtmr_pwm_out_state_t QTMR_GetPwmOutputStatus ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
inlinestatic
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
Returns
Current channel output status.
uint8_t QTMR_GetPwmChannelStatus ( TMR_Type *  base,
qtmr_channel_selection_t  channel 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
Returns
Current channel dutycycle value.
void QTMR_SetPwmClockMode ( TMR_Type *  base,
qtmr_channel_selection_t  channel,
qtmr_primary_count_source_t  prescaler 
)
Parameters
baseQuad Timer peripheral base address
channelQuad Timer channel number
prescalerSet prescaler value