Kinetis SDK v.1.2 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexTimer HAL driver

Overview

This section describes the programming interface of the FlexTimer HAL driver.

Data Structures

struct  quadtmr_counter_params_t
 Quad timer counter parameters. More...
 

Enumerations

enum  quadtmr_pri_count_source_t {
  kQuadTmrCntr0InpPin = 0,
  kQuadTmrCntr1InpPin,
  kQuadTmrCntr2InpPin,
  kQuadTmrCntr3InpPin,
  kQuadTmrCntr0Out,
  kQuadTmrCntr1Out,
  kQuadTmrCntr2Out,
  kQuadTmrCntr3Out,
  kQuadTmrClkDiv1,
  kQuadTmrClkDiv2,
  kQuadTmrClkDiv4,
  kQuadTmrClkDiv8,
  kQuadTmrClkDiv16,
  kQuadTmrClkDiv32,
  kQuadTmrClkDiv64,
  kQuadTmrClkDiv128
}
 Quad timer primary clock source selection.
 
enum  quadtmr_input_source_t {
  kQuadTmr0InpPin = 0,
  kQuadTmr1InpPin,
  kQuadTmr2InpPin,
  kQuadTmr3InpPin
}
 Quad timer input sources selection.
 
enum  quadtmr_counting_mode_t {
  kQuadTmrCntNoOper = 0,
  kQuadTmrCntPriSrcRiseEdge,
  kQuadTmrCntPriSrcRiseAndFallEdge,
  kQuadTmrCntPriSrcRiseEdgeSecInpHigh,
  kQuadTmrQuadCntMode,
  kQuadTmrCntPriSrcRiseEdgeSecDir,
  kQuadTmrSecSrcTrigPriCnt,
  kQuadTmrCascadeCnt
}
 Quad timer counting mode selection. More...
 
enum  quadtmr_output_mode_t {
  kQuadTmrAssertWhenCntActive = 0,
  kQuadTmrClearOnCompare,
  kQuadTmrSetOnCompare,
  kQuadTmrTogOnCompare,
  kQuadTmrTogOnAltCompReg,
  kQuadTmrSetOnCompareClearOnSecSrcInp,
  kQuadTmrSetOnCompareClearOnCntRoll,
  kQuadTmrEnableGateClk
}
 Quad timer output mode selection. More...
 
enum  quadtmr_input_capture_edge_mode_t {
  kQuadTmrNoCapture = 0,
  kQuadTmrRisingEdge,
  kQuadTmrFallingEdge,
  kQuadTmrRisingAndFallingEdge
}
 Quad timers input capture edge mode, rising edge, or falling edge. More...
 
enum  quadtmr_preload_control_t {
  kQuadTmrNoPreload = 0,
  kQuadTmrLoadOnComp1,
  kQuadTmrLoadOnComp2,
  kQuadTmrReserved
}
 Quad timers input capture edge mode, rising edge, or falling edge. More...
 

Functions

void QUADTMR_HAL_Init (TMR_Type *tmrBase)
 Initializes the Quad Timer registers. More...
 
void QUADTMR_HAL_SetupCounter (TMR_Type *tmrBase, quadtmr_counter_params_t *params, bool src_polarity)
 Sets the Quad timer's counter properties. More...
 
void QUADTMR_HAL_ForceOutVal (TMR_Type *tmrBase, bool val, bool pol)
 Enables the user to write a value out on the OFLAG pin. More...
 
void QUADTMR_HAL_OutPulses (TMR_Type *tmrBase, uint16_t numOfPulses, quadtmr_pri_count_source_t src)
 Enables the user to output a certain number of pulses. More...
 
void QUADTMR_HAL_OutPwmSignal (TMR_Type *tmrBase, quadtmr_pri_count_source_t src, uint16_t highPulseCount, uint16_t lowPulseCount)
 Outputs a PWM signal on the OFLAG pin. More...
 
void QUADTMR_HAL_SetupInputCapture (TMR_Type *tmrBase, quadtmr_pri_count_source_t countSrc, quadtmr_input_source_t captureSrc, quadtmr_input_capture_edge_mode_t mode, bool inputPol)
 Allows the user to count the source clock cycles until a capture event arrives. More...
 
void QUADTMR_HAL_SetupComparePreload (TMR_Type *tmrBase, uint8_t compareRegNum, uint16_t preloadVal, quadtmr_preload_control_t preloadProps)
 Sets up the Quad timers compare preload feature. More...
 
static void QUADTMR_HAL_SetCounter (TMR_Type *tmrBase, uint16_t val)
 Sets the Quad timer current counter value. More...
 
static void QUADTMR_HAL_SetComp1Val (TMR_Type *tmrBase, uint16_t val)
 Sets the Quad Timer compare register 1 value used in count up mode. More...
 
static void QUADTMR_HAL_SetComp1PreloadVal (TMR_Type *tmrBase, uint16_t val)
 Sets up the preload register for Quad Timer compare 1 register. More...
 
static void QUADTMR_HAL_SetComp2Val (TMR_Type *tmrBase, uint16_t val)
 Sets the Quad Timer compare register 2 value used in count up mode. More...
 
static void QUADTMR_HAL_SetComp2PreloadVal (TMR_Type *tmrBase, uint16_t val)
 Sets up the preload register for Quad Timer compare 2 register. More...
 
static void QUADTMR_HAL_SetLoadVal (TMR_Type *tmrBase, uint16_t val)
 Sets the Quad timer counter initial value. More...
 
static uint16_t QUADTMR_HAL_GetHoldVal (TMR_Type *tmrBase)
 Returns the Quad timer peripheral hold regiter value. More...
 
static uint16_t QUADTMR_HAL_GetCaptureVal (TMR_Type *tmrBase)
 Gets the Quad timer peripherals counter capture value. More...
 
static uint16_t QUADTMR_HAL_GetCounterVal (TMR_Type *tmrBase)
 Gets the Quad timer peripherals counter value. More...
 
static void QUADTMR_HAL_SetCountMode (TMR_Type *tmrBase, quadtmr_counting_mode_t mode)
 Sets up the Quad timer counter mode. More...
 
static void QUADTMR_HAL_SetPriCountSrc (TMR_Type *tmrBase, quadtmr_pri_count_source_t src)
 Sets up the Quad timer primary count source. More...
 
static void QUADTMR_HAL_SetSecCountSrc (TMR_Type *tmrBase, quadtmr_input_source_t src)
 Sets up the Quad timer secondary count source. More...
 
static void QUADTMR_HAL_SetCountOnceCmd (TMR_Type *tmrBase, bool once)
 Sets up the count once bit. More...
 
static void QUADTMR_HAL_SetOutputMode (TMR_Type *tmrBase, quadtmr_output_mode_t mode)
 Sets up the Quad timer output mode. More...
 
static void QUADTMR_HAL_SetInputPolSelCmd (TMR_Type *tmrBase, bool ips)
 Modifies the Quad timers input polarity select bit. More...
 
static bool QUADTMR_HAL_GetExtInputSignal (TMR_Type *tmrBase)
 Reads the Quad timers external input signal bit. More...
 
static void QUADTMR_HAL_SetCaptureMode (TMR_Type *tmrBase, quadtmr_input_capture_edge_mode_t mode)
 Sets the Quad timers input capture mode. More...
 
static void QUADTMR_HAL_SetOutEnableCmd (TMR_Type *tmrBase, bool enable)
 Modifies the value for the Quad timers output enable bit. More...
 
static void QUADTMR_HAL_SetInputFilterCnt (TMR_Type *tmrBase, uint8_t cnt)
 Sets input filter sample count. More...
 
static void QUADTMR_HAL_SetInputFilterPeriod (TMR_Type *tmrBase, uint8_t period)
 Sets input filter sample period. More...
 

Data Structure Documentation

struct quadtmr_counter_params_t

Data Fields

uint16_t counterVal
 Value to be written to the counter register.
 
uint16_t counterLoadVal
 Value to be loaded into the counter on compare or overflow.
 
uint16_t countUpCompareVal
 Value to be written to the count up compare register.
 
uint16_t countDownCompareVal
 Value to be written to the count down compare register.
 
quadtmr_pri_count_source_t primarySrc
 Specify the primary count source.
 
quadtmr_input_source_t secondarySrc
 Specify the secondary count source.
 
bool countOnce
 true: if counter should stop on compare, false: to run repeatedly
 
bool countLength
 true: re-initialize on compare match, false: count till roll-over
 
bool countDir
 true: Count down, false: Count up
 

Enumeration Type Documentation

Enumerator
kQuadTmrCntNoOper 

No operation.

kQuadTmrCntPriSrcRiseEdge 

Count rising edges or primary source.

kQuadTmrCntPriSrcRiseAndFallEdge 

Count rising and falling edges of primary source.

kQuadTmrCntPriSrcRiseEdgeSecInpHigh 

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

kQuadTmrQuadCntMode 

Quadature count mode, uses pri and sec sources.

kQuadTmrCntPriSrcRiseEdgeSecDir 

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

kQuadTmrSecSrcTrigPriCnt 

Edge of sec src trigger primary count until compare.

kQuadTmrCascadeCnt 

Cascaded counte mode (up/down)

Enumerator
kQuadTmrAssertWhenCntActive 

Assert OFLAG while counter is active.

kQuadTmrClearOnCompare 

Clear OFLAG on successful compare.

kQuadTmrSetOnCompare 

Set OFLAG on successful compare.

kQuadTmrTogOnCompare 

Toggle OFLAG on successful compare.

kQuadTmrTogOnAltCompReg 

Toggle OFLAG using alternating compare registers.

kQuadTmrSetOnCompareClearOnSecSrcInp 

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

kQuadTmrSetOnCompareClearOnCntRoll 

Set OFLAG on comapre, clear on counter rollover.

kQuadTmrEnableGateClk 

Enable gated clock output while count is active.

Enumerator
kQuadTmrNoCapture 

Capture is disabled.

kQuadTmrRisingEdge 

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

kQuadTmrFallingEdge 

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

kQuadTmrRisingAndFallingEdge 

Capture on both edges.

Enumerator
kQuadTmrNoPreload 

Never preload.

kQuadTmrLoadOnComp1 

Load upon successful compare with value in COMP1.

kQuadTmrLoadOnComp2 

Load upon successful compare with value in COMP2.

Function Documentation

void QUADTMR_HAL_Init ( TMR_Type *  tmrBase)
Parameters
tmrBaseThe Quad timer base address pointer
void QUADTMR_HAL_SetupCounter ( TMR_Type *  tmrBase,
quadtmr_counter_params_t params,
bool  src_polarity 
)

The primary source and in some cases secondary clock control how the to increment the counter. The parameters provided by the user will be used to setup counter properties like match value, rollover behaviour, direction. The function will not start the counter, the user will have to make a separate call to QUADTMR_HAL_SetCountMode to set count mode.

Parameters
tmrBaseThe Quad timer base address pointer
paramsUsed to setup the counter behaviour.
src_polaritytrue: Source clock will be inverted, false: no inversion of the input signal
void QUADTMR_HAL_ForceOutVal ( TMR_Type *  tmrBase,
bool  val,
bool  pol 
)
Parameters
tmrBaseThe Quad timer base address pointer
valtrue: high value is written, false: low value is written
poltrue: invert polarity of the output signal, false: no inversion
void QUADTMR_HAL_OutPulses ( TMR_Type *  tmrBase,
uint16_t  numOfPulses,
quadtmr_pri_count_source_t  src 
)

The number of pulses to be outputted is provided as an argument. The output pulse stream has the same frequency as the source clock provided.

Parameters
tmrBaseThe Quad timer base address pointer
numOfPulsesThe number of pulses to be outputted on the OFLAG pin
srcSource clock for the counter that is used to generate the pulse stream
void QUADTMR_HAL_OutPwmSignal ( TMR_Type *  tmrBase,
quadtmr_pri_count_source_t  src,
uint16_t  highPulseCount,
uint16_t  lowPulseCount 
)

The high and low pulse width values should be a count in terms of number of source clock cycles. The user has to calculate these values based on the source clock frequency, desired PWM frequncy and duty cycle.

Parameters
tmrBaseThe Quad timer base address pointer
srcSource clock for the counter that is used to generate the PWM signal
highPulseCountSpecify the number of source clock cycles to get the high period
lowPulseCount Specify the number of source clock cycles to get the low period
void QUADTMR_HAL_SetupInputCapture ( TMR_Type *  tmrBase,
quadtmr_pri_count_source_t  countSrc,
quadtmr_input_source_t  captureSrc,
quadtmr_input_capture_edge_mode_t  mode,
bool  inputPol 
)

The count will be stored in the capture register.

Parameters
tmrBaseThe Quad timer base address pointer
srcSource clock for the counter
captureSrcPin through which we will receive the input signal to trigger the capture
modeSpecifies which edge of the input signal will trigger a capture
poltrue: invert polarity of the input signal, false: no inversion
void QUADTMR_HAL_SetupComparePreload ( TMR_Type *  tmrBase,
uint8_t  compareRegNum,
uint16_t  preloadVal,
quadtmr_preload_control_t  preloadProps 
)
Parameters
tmrBaseThe Quad timer base address pointer
compareRegNumOptions are 1 or 2, 1=COMP1; 2=COMP2
preloadValValue to be written to the comparators preload register
preloadPropsControls when a compare register is preloaded with the value from the preload reg.
static void QUADTMR_HAL_SetCounter ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
valQuad timer counter value to be set
static void QUADTMR_HAL_SetComp1Val ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe Quad Timer base address pointer
valThe value to be set
static void QUADTMR_HAL_SetComp1PreloadVal ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe Quad Timer base address pointer
valThe value to be set
static void QUADTMR_HAL_SetComp2Val ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe Quad Timer base address pointer
valThe value to be set
static void QUADTMR_HAL_SetComp2PreloadVal ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe Quad Timer base address pointer
valThe value to be set
static void QUADTMR_HAL_SetLoadVal ( TMR_Type *  tmrBase,
uint16_t  val 
)
inlinestatic
Parameters
tmrBaseThe FTM base address pointer
valinitial value to be set
static uint16_t QUADTMR_HAL_GetHoldVal ( TMR_Type *  tmrBase)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
Returns
Quad timer hold value
static uint16_t QUADTMR_HAL_GetCaptureVal ( TMR_Type *  tmrBase)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
Returns
Returns the value captured from the counter
static uint16_t QUADTMR_HAL_GetCounterVal ( TMR_Type *  tmrBase)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
Returns
Returns the counter value
static void QUADTMR_HAL_SetCountMode ( TMR_Type *  tmrBase,
quadtmr_counting_mode_t  mode 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
modeCount mode, options available in quadtmr_counting_mode_t enum
static void QUADTMR_HAL_SetPriCountSrc ( TMR_Type *  tmrBase,
quadtmr_pri_count_source_t  src 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
srcPrimary count source, options available in the quadtmr_pri_count_source_t enum
static void QUADTMR_HAL_SetSecCountSrc ( TMR_Type *  tmrBase,
quadtmr_input_source_t  src 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
srcSecondary count source, options available in the quadtmr_input_source_t enum
static void QUADTMR_HAL_SetCountOnceCmd ( TMR_Type *  tmrBase,
bool  once 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
oncetrue: count until compare and then stop, false: count repeatedly
static void QUADTMR_HAL_SetOutputMode ( TMR_Type *  tmrBase,
quadtmr_output_mode_t  mode 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
modeOutput mode, options available in the quadtmr_output_mode_t enum
static void QUADTMR_HAL_SetInputPolSelCmd ( TMR_Type *  tmrBase,
bool  ips 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
ipstrue: inverts the input signal polarity, false: no inversion
static bool QUADTMR_HAL_GetExtInputSignal ( TMR_Type *  tmrBase)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
Returns
Returns the current state of the external input pin selected via the sec. count source
static void QUADTMR_HAL_SetCaptureMode ( TMR_Type *  tmrBase,
quadtmr_input_capture_edge_mode_t  mode 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
modeCapture mode, options specified in the quadtmr_input_capture_edge_mode_t enum
static void QUADTMR_HAL_SetOutEnableCmd ( TMR_Type *  tmrBase,
bool  enable 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
enabletrue: OFLAG output signal driven on pin, false: External pin configured as input
static void QUADTMR_HAL_SetInputFilterCnt ( TMR_Type *  tmrBase,
uint8_t  cnt 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
countInput filter sample count
static void QUADTMR_HAL_SetInputFilterPeriod ( TMR_Type *  tmrBase,
uint8_t  period 
)
inlinestatic
Parameters
tmrBaseThe Quad timer base address pointer
countInput filter sample period