Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TPM Peripheral driver

Overview

The section describes the programming interface of the TPM Peripheral driver. The TPM module is a timer that supports input capture, ouput compare, and generation of PWM signals. The current SDK driver supports supports all features.

TPM Initialization

  1. To initialize the TPM driver, call the TPM_DRV_Init() function and pass the instance number of the relevant TPM. For example, to use TPM0, pass a value 0 to the initialization function.
  2. Pass a user configuration structure tpm_general_config_t, as shown here:

    // TPM configuration structure for. The user needs to set the relevant configurations.
    typedef struct TpmGeneralConfig {
    bool isDBGMode;
    bool isGlobalTimeBase;
    bool isTriggerMode;
    bool isStopCountOnOveflow;
    bool isCountReloadOnTrig;
    tpm_trigger_source_t triggerSource;

TPM Generate a PWM signal

Call the TPM_DRV_PwmStart() function to generate a PWM signal. Use this structure to configure the different parameters related to this PWM signal.

typedef struct TpmPwmParam
{
uint32_t uFrequencyHZ;
uint32_t uDutyCyclePercent;
0=inactive signal(0% duty cycle)...
100=active signal (100% duty cycle). //

The mode options are kTpmEdgeAlignedPWM and kTpmCenterAlignedPWM. For edge mode, the options are kTpmHighTrue and kTpmLowTrue. Specify the PWM signal frequency in Hertz and the duty cycle percentage (value between 0-100).

TPM Input Capture

Call the TPM_DRV_InputCaptureEnable() function to set up the channel for input capture. Use this enumeration to specify the capture mode:

typedef enum _tpm_input_capture_mode_t
{
kTpmRisingEdge = 1,
kTpmFallingEdge,
kTpmRiseOrFallEdge

To enable channel interrupts, use the intEnable argument of the function.

Call the TPM_DRV_GetChnVal() function to read the captured LPTPM counter value.

TPM Output Compare

Call the TPM_DRV_OutputCompareEnable() function to set up the channel for output compare. Use this enumeration to specify the compare mode:

typedef enum _tpm_output_compare_mode_t
{
kTpmOutputNone = 0,
kTpmToggleOutput,
kTpmClearOutput,
kTpmSetOutput,
kTpmHighPulseOutput,
kTpmLowPulseOutput

To enable channel interrupts, use the intEnable argument of the function. The matchVal argument of the function is written to the CnV register.

TPM Interrupt handler

The TPM driver provides an interrupt handler for the counter overflow and channel interrupts. These handlers clear the status bits.

To add more actions to the default handler, add calls to the functions inside the interrupt handlers TPMx_IRQHandler() function, where x=0, 1, 2 depending on the TPM instance.

Data Structures

struct  tpm_general_config_t
 Internal driver state information grouped by names. More...
 

Functions

tpm_status_t TPM_DRV_Init (uint32_t instance, const tpm_general_config_t *info)
 Initializes the TPM driver. More...
 
void TPM_DRV_PwmStop (uint32_t instance, tpm_pwm_param_t *param, uint8_t channel)
 Stops the channel PWM. More...
 
tpm_status_t TPM_DRV_PwmStart (uint32_t instance, tpm_pwm_param_t *param, uint8_t channel)
 Configures the duty cycle and frequency and starts outputting PWM on a specified channel. More...
 
void TPM_DRV_SetTimeOverflowIntCmd (uint32_t instance, bool overflowEnable)
 Enables or disables the timer overflow interrupt. More...
 
void TPM_DRV_SetChnIntCmd (uint32_t instance, uint8_t channelNum, bool enable)
 Enables or disables the channel interrupt. More...
 
void TPM_DRV_SetClock (uint32_t instance, tpm_clock_mode_t clock, tpm_clock_ps_t clockPs)
 Sets the TPM clock source. More...
 
uint32_t TPM_DRV_GetClock (uint32_t instance)
 Gets the TPM clock frequency. More...
 
void TPM_DRV_CounterStart (uint32_t instance, tpm_counting_mode_t countMode, uint32_t countFinalVal, bool enableOverflowInt)
 Starts the TPM counter. More...
 
void TPM_DRV_CounterStop (uint32_t instance)
 Stops the TPM counter. More...
 
uint32_t TPM_DRV_CounterRead (uint32_t instance)
 Reads back the current value of the TPM counter. More...
 
void TPM_DRV_InputCaptureEnable (uint32_t instance, uint8_t channel, tpm_input_capture_mode_t mode, uint32_t countFinalVal, bool intEnable)
 TPM input capture mode setup. More...
 
uint32_t TPM_DRV_GetChnVal (uint32_t instance, uint8_t channel)
 Reads back the current value of the TPM channel value. More...
 
void TPM_DRV_OutputCompareEnable (uint32_t instance, uint8_t channel, tpm_output_compare_mode_t mode, uint32_t countFinalVal, uint32_t matchVal, bool intEnable)
 TPM output compare mode setup. More...
 
void TPM_DRV_Deinit (uint32_t instance)
 Shuts down the TPM driver. More...
 
void TPM_DRV_IRQHandler (uint32_t instance)
 Action to take when an TPM interrupt is triggered. More...
 

Variables

TPM_Type *const g_tpmBase [TPM_INSTANCE_COUNT]
 Table of base addresses for TPM instances. More...
 
const IRQn_Type g_tpmIrqId [TPM_INSTANCE_COUNT]
 Table to save TPM IRQ numbers for TPM instances. More...
 

Data Structure Documentation

struct tpm_general_config_t

User needs to set the relevant ones.

Data Fields

bool isDBGMode
 DBGMode behavioral, false to pause, true to continue run in DBG mode.
 
bool isGlobalTimeBase
 If Global time base enabled, true to enable, false to disable.
 
bool isTriggerMode
 If Trigger mode enabled, true to enable, false to disable.
 
bool isStopCountOnOveflow
 True to stop counter after overflow, false to continue running.
 
bool isCountReloadOnTrig
 True to reload counter on trigger, false means counter is not reloaded.
 
tpm_trigger_source_t triggerSource
 Trigger source if trigger mode enabled.
 

Function Documentation

tpm_status_t TPM_DRV_Init ( uint32_t  instance,
const tpm_general_config_t info 
)
Parameters
instanceThe TPM peripheral instance number.
infoPointer to the TPM user configuration structure, see tpm_general_config_t.
Returns
kStatusTpmSuccess means success; Otherwise means failure.
void TPM_DRV_PwmStop ( uint32_t  instance,
tpm_pwm_param_t param,
uint8_t  channel 
)
Parameters
instanceThe TPM peripheral instance number.
paramPWM parameter to configure PWM options
channelThe channel number.
tpm_status_t TPM_DRV_PwmStart ( uint32_t  instance,
tpm_pwm_param_t param,
uint8_t  channel 
)
Parameters
instanceThe TPM peripheral instance number.
paramPWM parameter to configure PWM options, see tpm_pwm_param_t.
channelThe channel number.
Returns
kStatusTpmSuccess means success; Otherwise means failure.
void TPM_DRV_SetTimeOverflowIntCmd ( uint32_t  instance,
bool  overflowEnable 
)
Parameters
instanceThe TPM peripheral instance number.
overflowEnabletrue: enable the timer overflow interrupt, false: disable
void TPM_DRV_SetChnIntCmd ( uint32_t  instance,
uint8_t  channelNum,
bool  enable 
)
Parameters
instanceThe TPM peripheral instance number.
channelNumThe channel number.
enabletrue: enable the channel interrupt, false: disable
void TPM_DRV_SetClock ( uint32_t  instance,
tpm_clock_mode_t  clock,
tpm_clock_ps_t  clockPs 
)
Parameters
instanceThe TPM peripheral instance number.
clockThe TPM peripheral clock selection, see tpm_clock_mode_t.
clockPsThe TPM peripheral clock prescale factor, see tpm_clock_ps_t.
uint32_t TPM_DRV_GetClock ( uint32_t  instance)
Parameters
instanceThe TPM peripheral instance number.
Returns
The function returns the frequency of the TPM clock.
void TPM_DRV_CounterStart ( uint32_t  instance,
tpm_counting_mode_t  countMode,
uint32_t  countFinalVal,
bool  enableOverflowInt 
)

This function provides access to the TPM counter. The counter can run in up-counting and up-down counting modes.

Parameters
instanceThe TPM peripheral instance number.
countModeThe TPM counter mode defined by tpm_counting_mode_t.
countFinalValThe final value that is stored in the MOD register.
enableOverflowInttrue: enable timer overflow interrupt; false: disable
void TPM_DRV_CounterStop ( uint32_t  instance)
Parameters
instanceThe TPM peripheral instance number.
uint32_t TPM_DRV_CounterRead ( uint32_t  instance)
Parameters
instanceThe TPM peripheral instance number.
Returns
The current value of the TPM counter.
void TPM_DRV_InputCaptureEnable ( uint32_t  instance,
uint8_t  channel,
tpm_input_capture_mode_t  mode,
uint32_t  countFinalVal,
bool  intEnable 
)
Parameters
instanceThe TPM peripheral instance number.
channelThe channel number.
modeThe TPM input mode defined by tpm_input_capture_mode_t.
countFinalValThe final value that is stored in the MOD register.
intEnabletrue: enable channel interrupt; false: disable
uint32_t TPM_DRV_GetChnVal ( uint32_t  instance,
uint8_t  channel 
)
Parameters
instanceThe TPM peripheral instance number.
channelThe channel number.
Returns
The current value of the TPM channel value.
void TPM_DRV_OutputCompareEnable ( uint32_t  instance,
uint8_t  channel,
tpm_output_compare_mode_t  mode,
uint32_t  countFinalVal,
uint32_t  matchVal,
bool  intEnable 
)
Parameters
instanceThe TPM peripheral instance number.
channelThe channel number.
modeThe TPM output mode defined by tpm_output_compare_mode_t.
countFinalValThe final value that is stored in the MOD register.
matchValThe channel compare value stored in the CnV register
intEnabletrue: enable channel interrupt; false: disable
void TPM_DRV_Deinit ( uint32_t  instance)
Parameters
instanceThe TPM peripheral instance number.
void TPM_DRV_IRQHandler ( uint32_t  instance)

The timer overflow flag is checked and cleared if set.

Parameters
instanceInstance number of the TPM module.

Variable Documentation

TPM_Type* const g_tpmBase[TPM_INSTANCE_COUNT]
const IRQn_Type g_tpmIrqId[TPM_INSTANCE_COUNT]