MCUXpresso SDK API Reference Manual  Rev. 0
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_t
 Quad Timer config structure. More...
 

Enumerations

enum  qtmr_primary_count_source_t {
  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_t {
  kQTMR_Counter0InputPin = 0,
  kQTMR_Counter1InputPin,
  kQTMR_Counter2InputPin,
  kQTMR_Counter3InputPin
}
 Quad Timer input sources selection. More...
 
enum  qtmr_counting_mode_t {
  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_output_mode_t {
  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_t {
  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_t {
  kQTMR_NoPreload = 0,
  kQTMR_LoadOnComp1,
  kQTMR_LoadOnComp2
}
 Quad Timer input capture edge mode, rising edge, or falling edge. More...
 
enum  qtmr_debug_action_t {
  kQTMR_RunNormalInDebug = 0U,
  kQTMR_HaltCounter,
  kQTMR_ForceOutToZero,
  kQTMR_HaltCountForceOutZero
}
 List of Quad Timer run options when in Debug mode. More...
 
enum  qtmr_interrupt_enable_t {
  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_t {
  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...
 

Functions

status_t QTMR_SetupPwm (TMR_Type *base, 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_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, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

void QTMR_Init (TMR_Type *base, const qtmr_config_t *config)
 Ungates the Quad Timer clock and configures the peripheral for basic operation. More...
 
void QTMR_Deinit (TMR_Type *base)
 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, uint32_t mask)
 Enables the selected Quad Timer interrupts. More...
 
void QTMR_DisableInterrupts (TMR_Type *base, uint32_t mask)
 Disables the selected Quad Timer interrupts. More...
 
uint32_t QTMR_GetEnabledInterrupts (TMR_Type *base)
 Gets the enabled Quad Timer interrupts. More...
 

Status Interface

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

Read and Write the timer period

void QTMR_SetTimerPeriod (TMR_Type *base, uint16_t ticks)
 Sets the timer period in ticks. More...
 
static uint16_t QTMR_GetCurrentTimerCount (TMR_Type *base)
 Reads the current timer counting value. More...
 

Timer Start and Stop

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

Data Structure Documentation

struct 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

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.
 

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 or 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_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.

Function Documentation

void QTMR_Init ( TMR_Type *  base,
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
configPointer to user's Quad Timer config structure
void QTMR_Deinit ( TMR_Type *  base)
Parameters
baseQuad Timer peripheral base address
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,
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
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_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
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,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration qtmr_interrupt_enable_t
void QTMR_DisableInterrupts ( TMR_Type *  base,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
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)
Parameters
baseQuad Timer peripheral base address
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)
Parameters
baseQuad Timer peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration qtmr_status_flags_t
void QTMR_ClearStatusFlags ( TMR_Type *  base,
uint32_t  mask 
)
Parameters
baseQuad Timer peripheral base address
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,
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
ticksTimer period in units of ticks
static uint16_t QTMR_GetCurrentTimerCount ( TMR_Type *  base)
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
Returns
Current counter value in ticks
static void QTMR_StartTimer ( TMR_Type *  base,
qtmr_counting_mode_t  clockSource 
)
inlinestatic
Parameters
baseQuad Timer peripheral base address
clockSourceQuad Timer clock source
static void QTMR_StopTimer ( TMR_Type *  base)
inlinestatic
Parameters
baseQuad Timer peripheral base address