This section describes the programming interface of the FlexTimer Peripheral driver.
FlexTimer Overview
The FlexTimer module is a timer that supports input capture, output compare, and generation of PWM signals. The current Kinetis SDK driver only supports the generation of PWM signals. The input capture and output compare will be supported in upcoming Kinetis SDK releases.
FlexTimer Initialization
-
To initialize the FlexTimer driver, call the FTM_DRV_Init() function and pass the instance number of the relevant FTM. For example, to use FTM0, pass a value of 0 to the initialization function.
-
Pass a user configuration structure ftm_user_config_t, as shown here:
typedef struct FtmUserConfig {
uint8_t tofFrequency;
bool isFTMMode;
uint8_t BDMMode;
bool isWriteProtection;
bool isTimerOverFlowInterrupt;
bool isFaultInterrupt;
FlexTimer Generate a PWM signal
FTM calls the FTM_DRV_PwmStart() function to generate a PWM signal. Use this structure to configure different parameters for the PWM signal.
typedef struct FtmPwmParam
{
uint32_t uFrequencyHZ;
uint32_t uDutyCyclePercent;
0 = inactive signal(0% duty cycle)...
100 = active signal (100% duty cycle).
uint16_t uFirstEdgeDelayPercent;
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
The mode options are kFtmEdgeAlignedPWM, kFtmCenterAlignedPWM, and kFtmCombinedPWM. For edge mode, the options available are kFtmHighTrue and kFtmLowTrue. Specify the PWM signal frequency in Hz and the duty cycle percentage (value between 0-100). If the PWM mode is kFtmCombinedPWM and if the user chooses to specify a value for the uFirstEdgeDelayPercent, start of the PWM pulse is delayed.
|
ftm_status_t | FTM_DRV_Init (uint32_t instance, const ftm_user_config_t *info) |
| Initializes the FTM driver. More...
|
|
void | FTM_DRV_Deinit (uint32_t instance) |
| Shuts down the FTM driver. More...
|
|
void | FTM_DRV_PwmStop (uint32_t instance, ftm_pwm_param_t *param, uint8_t channel) |
| Stops the channel PWM. More...
|
|
ftm_status_t | FTM_DRV_PwmStart (uint32_t instance, ftm_pwm_param_t *param, uint8_t channel) |
| Configures the duty cycle and frequency and starts outputting the PWM on a specified channel . More...
|
|
void | FTM_DRV_QuadDecodeStart (uint32_t instance, ftm_phase_params_t *phaseAParams, ftm_phase_params_t *phaseBParams, ftm_quad_decode_mode_t quadMode) |
| Configures the parameters and activates the quadrature decode mode. More...
|
|
void | FTM_DRV_QuadDecodeStop (uint32_t instance) |
| Deactivates the quadrature decode mode. More...
|
|
void | FTM_DRV_CounterStart (uint32_t instance, ftm_counting_mode_t countMode, uint32_t countStartVal, uint32_t countFinalVal, bool enableOverflowInt) |
| Starts the FTM counter. More...
|
|
void | FTM_DRV_CounterStop (uint32_t instance) |
| Stops the FTM counter. More...
|
|
uint32_t | FTM_DRV_CounterRead (uint32_t instance) |
| Reads back the current value of the FTM counter. More...
|
|
void | FTM_DRV_SetClock (uint8_t instance, ftm_clock_source_t clock, ftm_clock_ps_t clockPs) |
| Sets the FTM clock source. More...
|
|
uint32_t | FTM_DRV_GetClock (uint8_t instance) |
| Retrieves the frequency of the clock source feeding the FTM counter. More...
|
|
void | FTM_DRV_SetTimeOverflowIntCmd (uint32_t instance, bool overflowEnable) |
| Enables or disables the timer overflow interrupt. More...
|
|
void | FTM_DRV_SetFaultIntCmd (uint32_t instance, bool faultEnable) |
| Enables or disables the fault interrupt. More...
|
|
void | FTM_DRV_SetupChnInputCapture (uint32_t instance, ftm_input_capture_edge_mode_t captureMode, uint8_t channel, uint8_t filterVal) |
| Enables capturing an input signal on the channel using the function parameters. More...
|
|
void | FTM_DRV_SetupChnOutputCompare (uint32_t instance, ftm_output_compare_edge_mode_t compareMode, uint8_t channel, uint32_t compareVal) |
| Configures the FTM to generate timed pulses. More...
|
|
void | FTM_DRV_SetupChnDualEdgeCapture (uint32_t instance, ftm_dual_edge_capture_param_t *param, uint8_t channel, uint8_t filterVal) |
| Configures the dual edge capture mode of the FTM. More...
|
|
void | FTM_DRV_IRQHandler (uint32_t instance) |
| Action to take when an FTM interrupt is triggered. More...
|
|
|
FTM_Type *const | g_ftmBase [FTM_INSTANCE_COUNT] |
| Table of base addresses for FTM instances. More...
|
|
const IRQn_Type | g_ftmIrqId [FTM_INSTANCE_COUNT] |
| Table to save FTM IRQ enumeration numbers defined in the CMSIS header file. More...
|
|
Data Fields |
uint8_t | tofFrequency |
| Select ratio between number of overflows to times TOF is set.
|
|
ftm_bdm_mode_t | BDMMode |
| Select FTM behavior in BDM mode.
|
|
bool | isWriteProtection |
| true: enable write protection, false: write protection is disabled
|
|
uint32_t | syncMethod |
| Register synch options available in the ftm_sync_method_t enumeration.
|
|
- Parameters
-
instance | The FTM peripheral instance number. |
info | The FTM user configuration structure, see ftm_user_config_t. |
- Returns
- kStatusFtmSuccess means success. Otherwise means failure.
void FTM_DRV_Deinit |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The FTM peripheral instance number. |
void FTM_DRV_PwmStop |
( |
uint32_t |
instance, |
|
|
ftm_pwm_param_t * |
param, |
|
|
uint8_t |
channel |
|
) |
| |
- Parameters
-
instance | The FTM peripheral instance number. |
param | FTM driver PWM parameter to configure PWM options |
channel | The channel number. In combined mode, the code finds the channel pair associated with the channel number passed in. |
- Parameters
-
instance | The FTM peripheral instance number. |
param | FTM driver PWM parameter to configure PWM options |
channel | The channel number. In combined mode, the code finds the channel pair associated with the channel number passed in. |
- Returns
- kStatusFtmSuccess if the PWM setup was successful, kStatusFtmError on failure as the PWM counter is disabled
- Parameters
-
instance | Instance number of the FTM module. |
phaseAParams | Phase A configuration parameters |
phaseBParams | Phase B configuration parameters |
quadMode | Selects encoding mode used in quadrature decoder mode |
void FTM_DRV_QuadDecodeStop |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | Instance number of the FTM module. |
void FTM_DRV_CounterStart |
( |
uint32_t |
instance, |
|
|
ftm_counting_mode_t |
countMode, |
|
|
uint32_t |
countStartVal, |
|
|
uint32_t |
countFinalVal, |
|
|
bool |
enableOverflowInt |
|
) |
| |
This function provides access to the FTM counter. The counter can be run in up-counting and up-down counting modes. To run the counter in free running mode, choose the up-counting option and provide 0x0 for the countStartVal and 0xFFFF for countFinalVal.
- Parameters
-
instance | The FTM peripheral instance number. |
countMode | The FTM counter mode defined by ftm_counting_mode_t. |
countStartVal | The starting value that is stored in the CNTIN register. |
countFinalVal | The final value that is stored in the MOD register. |
enableOverflowInt | true: enable timer overflow interrupt; false: disable |
void FTM_DRV_CounterStop |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The FTM peripheral instance number. |
uint32_t FTM_DRV_CounterRead |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The FTM peripheral instance number. |
- Returns
- The counter value.
This function saves the user's clock source selection in the driver to set the clock source and use features provided by the driver-like counter, PWM generation, and so on. This function also sets the clock divider.
- Parameters
-
instance | The FTM peripheral instance number. |
clock | The clock source to use, cannot pick None. |
clockPs | The clock divider value. |
uint32_t FTM_DRV_GetClock |
( |
uint8_t |
instance | ) |
|
This function returns zero if no clock source is selected and the FTM counter is disabled.
- Parameters
-
instance | The FTM peripheral instance number. |
- Returns
- The frequency of the clock source running the FTM counter, returns 0 if counter is disabled
void FTM_DRV_SetTimeOverflowIntCmd |
( |
uint32_t |
instance, |
|
|
bool |
overflowEnable |
|
) |
| |
- Parameters
-
instance | The FTM peripheral instance number. |
overflowEnable | true: enable the timer overflow interrupt, false: disable |
void FTM_DRV_SetFaultIntCmd |
( |
uint32_t |
instance, |
|
|
bool |
faultEnable |
|
) |
| |
- Parameters
-
instance | The FTM peripheral instance number. |
faultEnable | true: enable the fault interrupt, false: disable |
When the edge specified in the captureMode argument occurs on the channel, the FTM counter is captured into the CnV register. The user has to read the CnV register separately to get this value. The filter function is disabled if the filterVal argument passed in is 0. The filter function is available only for 0, 1, 2, 3 channels.
- Parameters
-
instance | The FTM peripheral instance number |
captureMode | Specifies which edge to capture |
channel | The channel number |
filterVal | Filter value to be used, specify 0 to disable filter. Available only for channels 0-3 |
When the FTM 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
-
instance | The FTM peripheral instance number. |
compareMode | Action to take on the channel output when the compare condition is met |
channel | The channel number |
compareVal | Value to be programmed in the CnV register. |
This function sets up the dual edge capture mode on a channel pair. The capture edge for the channel pair and the capture mode (one-shot or continuous) is specified in the parameter argument. The filter function is disabled if the filterVal argument passed is zero. The filter function is available only on channels 0 and 2. The user has to read the channel CnV registers separately to get the capture values.
- Parameters
-
instance | The FTM peripheral instance number. |
param | Controls the dual edge capture function |
channel | The channel number, the code finds the channel pair associated with the channel number passed in. |
filterVal | Filter value to be used, specify 0 to disable filter. Available only for channels 0, 2 |
void FTM_DRV_IRQHandler |
( |
uint32_t |
instance | ) |
|
The timer overflow flag is checked and cleared if set.
- Parameters
-
instance | Instance number of the FTM module. |
FTM_Type* const g_ftmBase[FTM_INSTANCE_COUNT] |
const IRQn_Type g_ftmIrqId[FTM_INSTANCE_COUNT] |