FlexTimer Pulse Width Modulation Peripheral Driver.
The FTM of the S32K1xx is based on a 16 bits counter and supports: input capture, output compare, PWM and some instances include quadrature decoder.
For all operation modes (without Quadrature Decoder mode) the user need to configure ftm_user_config_t. This structure will be used for initialization (FTM_DRV_Init). The next functions used are specific for each operation mode.
For this mode, the user needs to configure parameters such: number of PWM channels, frequency, dead time, fault channels and duty cycle, alignment (edge or center). All this information is included in the ftm_pwm_param_t structure.
FTM_DRV_UpdatePwmChannel can be used to update duty cycles at run time. If the type of update in the duty cycle when the duty cycle can have value between 0x0 (0%) and 0x8000 (100%). If the type of update in ticks when the firstEdge and secondEdge variables can have value between 0 and ftmPeriod which is stored in the state structure.
Example:
For this mode the user needs to configure parameters such: number of PWM channels, frequency, dead time, fault channels and duty cycle, alignment (edge or center). All this information is included in ftm_pwm_param_t data type. The Modified Combine PWM mode is intended to support the generation of PWM signals where the period is not modified while the signal is being generated, but the duty cycle will be varied. FTM_DRV_UpdatePwmChannel can be used to update duty cycles at run time. If the type of update in the duty cycle when the duty cycle can have value between 0x0 (0%) and 0x8000 (100%). If the type of update in ticks when the firstEdge and secondEdge variables can have value between 0 and ftmPeriod which is stored in the state structure.In this mode, an even channel (n) and adjacent odd channel (n+1) are combined to generate a PWM signal in the channel (n) output. Thus, the channel (n) match edge is fixed and the channel (n+1) match edge can be varied.
Example:
Data Structures | |
struct | ftm_pwm_ch_fault_param_t |
FlexTimer driver PWM Fault channel parameters. More... | |
struct | ftm_pwm_fault_param_t |
FlexTimer driver PWM Fault parameter. More... | |
struct | ftm_independent_ch_param_t |
FlexTimer driver independent PWM parameter. More... | |
struct | ftm_combined_ch_param_t |
FlexTimer driver combined PWM parameter. More... | |
struct | ftm_pwm_param_t |
FlexTimer driver PWM parameters. More... | |
Macros | |
#define | FTM_MAX_DUTY_CYCLE (0x8000U) |
Maximum value for PWM duty cycle. More... | |
#define | FTM_DUTY_TO_TICKS_SHIFT (15U) |
Shift value which converts duty to ticks. More... | |
Enumerations | |
enum | ftm_pwm_update_option_t { FTM_PWM_UPDATE_IN_DUTY_CYCLE = 0x00U, FTM_PWM_UPDATE_IN_TICKS = 0x01U } |
FlexTimer Configure type of PWM update in the duty cycle or in ticks. More... | |
enum | ftm_polarity_t { FTM_POLARITY_LOW = 0x00U, FTM_POLARITY_HIGH = 0x01U } |
FlexTimer PWM output pulse mode, high-true or low-true on match up. More... | |
enum | ftm_second_channel_polarity_t { FTM_MAIN_INVERTED = 0x01U, FTM_MAIN_DUPLICATED = 0x00U } |
FlexTimer PWM channel (n+1) polarity for combine mode. More... | |
enum | ftm_fault_mode_t { FTM_FAULT_CONTROL_DISABLED = 0x00U, FTM_FAULT_CONTROL_MAN_EVEN = 0x01U, FTM_FAULT_CONTROL_MAN_ALL = 0x02U, FTM_FAULT_CONTROL_AUTO_ALL = 0x03U } |
FlexTimer fault control. More... | |
enum | ftm_safe_state_polarity_t { FTM_HIGH_TRUE_PULSE = 0x02U, FTM_LOW_TRUE_PULSE = 0x03U } |
Select level of the channel (n) output at the beginning. More... | |
Functions | |
status_t | FTM_DRV_DeinitPwm (uint32_t instance) |
Stops all PWM channels . More... | |
status_t | FTM_DRV_InitPwm (uint32_t instance, const ftm_pwm_param_t *param) |
Configures the duty cycle and frequency and starts outputting the PWM on all channels configured in param. More... | |
status_t | FTM_DRV_UpdatePwmChannel (uint32_t instance, uint8_t channel, ftm_pwm_update_option_t typeOfUpdate, uint16_t firstEdge, uint16_t secondEdge, bool softwareTrigger) |
This function updates the waveform output in PWM mode (duty cycle and phase). More... | |
status_t | FTM_DRV_FastUpdatePwmChannels (uint32_t instance, uint8_t numberOfChannels, const uint8_t *channels, const uint16_t *duty, bool softwareTrigger) |
This function will update the duty cycle of PWM output for multiple channels. More... | |
status_t | FTM_DRV_UpdatePwmPeriod (uint32_t instance, ftm_pwm_update_option_t typeOfUpdate, uint32_t newValue, bool softwareTrigger) |
This function will update the new period in the frequency or in the counter value into mode register which modify the period of PWM signal on the channel output. More... | |
status_t | FTM_DRV_UpdatePwmPeriodDither (uint32_t instance, uint8_t newModFracVal, bool softwareTrigger) |
This function will use in the PWM period dithering. This value is added to an internal accumulator at the end of each PWM period. The value is updated with its write buffer value according to the register synchronization. More... | |
status_t | FTM_DRV_UpdatePwmEdgeChannelDither (uint32_t instance, uint8_t channel, uint8_t newMatchFracVal, bool softwareTrigger) |
This function will use in the PWM edge dithering. This value is added to the channel (n) internal accumulator at the end of each PWM period. The FRACVAL is updated with its write buffer value according to the register synchronization. The PWM edge dithering is not available when the channel in the input capture modes, and the channel in output compare modes. More... | |
#define FTM_DUTY_TO_TICKS_SHIFT (15U) |
Shift value which converts duty to ticks.
Definition at line 45 of file ftm_pwm_driver.h.
#define FTM_MAX_DUTY_CYCLE (0x8000U) |
Maximum value for PWM duty cycle.
Definition at line 43 of file ftm_pwm_driver.h.
enum ftm_fault_mode_t |
FlexTimer fault control.
Implements : ftm_fault_mode_t_Class
Definition at line 87 of file ftm_pwm_driver.h.
enum ftm_polarity_t |
FlexTimer PWM output pulse mode, high-true or low-true on match up.
Implements : ftm_polarity_t_Class
Enumerator | |
---|---|
FTM_POLARITY_LOW |
When counter > CnV output signal is LOW |
FTM_POLARITY_HIGH |
When counter > CnV output signal is HIGH |
Definition at line 63 of file ftm_pwm_driver.h.
FlexTimer Configure type of PWM update in the duty cycle or in ticks.
Implements : ftm_pwm_update_option_t_Class
Enumerator | |
---|---|
FTM_PWM_UPDATE_IN_DUTY_CYCLE |
The type of PWM update in the duty cycle/pulse or also use in frequency update |
FTM_PWM_UPDATE_IN_TICKS |
The type of PWM update in ticks |
Definition at line 52 of file ftm_pwm_driver.h.
Select level of the channel (n) output at the beginning.
Implements : ftm_safe_state_polarity_t_Class
Definition at line 104 of file ftm_pwm_driver.h.
FlexTimer PWM channel (n+1) polarity for combine mode.
Implements : ftm_second_channel_polarity_t_Class
Enumerator | |
---|---|
FTM_MAIN_INVERTED |
The channel (n+1) output is the inverse of the channel (n) output |
FTM_MAIN_DUPLICATED |
The channel (n+1) output is the same as the channel (n) output |
Definition at line 74 of file ftm_pwm_driver.h.
status_t FTM_DRV_DeinitPwm | ( | uint32_t | instance | ) |
Stops all PWM channels .
[in] | instance | The FTM peripheral instance number. |
Definition at line 292 of file ftm_pwm_driver.c.
status_t FTM_DRV_FastUpdatePwmChannels | ( | uint32_t | instance, |
uint8_t | numberOfChannels, | ||
const uint8_t * | channels, | ||
const uint16_t * | duty, | ||
bool | softwareTrigger | ||
) |
This function will update the duty cycle of PWM output for multiple channels.
[in] | instance | The FTM peripheral instance number. |
[in] | numberOfChannels | The number of channels which should be updated. |
[in] | channels | The list of channels which should be updated. |
[in] | duty | The list of duty cycles for selected channels. |
[in] | softwareTrigger | If true a software trigger is generate to update PWM parameters. |
Definition at line 551 of file ftm_pwm_driver.c.
status_t FTM_DRV_InitPwm | ( | uint32_t | instance, |
const ftm_pwm_param_t * | param | ||
) |
Configures the duty cycle and frequency and starts outputting the PWM on all channels configured in param.
[in] | instance | The FTM peripheral instance number. |
[in] | param | FTM driver PWM parameter to configure PWM options. |
Definition at line 43 of file ftm_pwm_driver.c.
status_t FTM_DRV_UpdatePwmChannel | ( | uint32_t | instance, |
uint8_t | channel, | ||
ftm_pwm_update_option_t | typeOfUpdate, | ||
uint16_t | firstEdge, | ||
uint16_t | secondEdge, | ||
bool | softwareTrigger | ||
) |
This function updates the waveform output in PWM mode (duty cycle and phase).
[in] | instance | The FTM peripheral instance number. |
[in] | channel | The channel number. In combined mode, the code finds the channel. |
[in] | typeOfUpdate | The type of PWM update in the duty cycle/pulse or in ticks. |
[in] | firstEdge | Duty cycle or first edge time for PWM mode. Can take value between 0 - FTM_MAX_DUTY_CYCLE(0 = 0% from period and FTM_MAX_DUTY_CYCLE = 100% from period) Or value in ticks for the first of the PWM mode in which can have value between 0 and ftmPeriod is stored in the state structure. |
[in] | secondEdge | Second edge time - only for combined mode. Can take value between 0 - FTM_MAX_DUTY_CYCLE(0 = 0% from period and FTM_MAX_DUTY_CYCLE = 100% from period). Or value in ticks for the second of the PWM mode in which can have value between 0 and ftmPeriod is stored in the state structure. |
[in] | softwareTrigger | If true a software trigger is generate to update PWM parameters. |
Definition at line 356 of file ftm_pwm_driver.c.
status_t FTM_DRV_UpdatePwmEdgeChannelDither | ( | uint32_t | instance, |
uint8_t | channel, | ||
uint8_t | newMatchFracVal, | ||
bool | softwareTrigger | ||
) |
This function will use in the PWM edge dithering. This value is added to the channel (n) internal accumulator at the end of each PWM period. The FRACVAL is updated with its write buffer value according to the register synchronization. The PWM edge dithering is not available when the channel in the input capture modes, and the channel in output compare modes.
[in] | instance | The FTM peripheral instance number. |
[in] | channel | The channel number. |
[in] | newMatchFracVal | The channel (n) match fractional value . |
[in] | softwareTrigger | If true a software trigger is generate to update parameters. |
status_t FTM_DRV_UpdatePwmPeriod | ( | uint32_t | instance, |
ftm_pwm_update_option_t | typeOfUpdate, | ||
uint32_t | newValue, | ||
bool | softwareTrigger | ||
) |
This function will update the new period in the frequency or in the counter value into mode register which modify the period of PWM signal on the channel output.
[in] | instance | The FTM peripheral instance number. |
[in] | typeOfUpdate | The type of PWM update is a period in Hz or in ticks.
|
[in] | newValue | The frequency or the counter value which will select with modified value for PWM signal. If the type of update in the duty cycle, the newValue parameter must be value between 1U and maximum is the frequency of the FTM counter. If the type of update in ticks, the newValue parameter must be value between 1U and 0xFFFFU. |
[in] | softwareTrigger | If true a software trigger is generate to update PWM parameters. |
Definition at line 485 of file ftm_pwm_driver.c.
status_t FTM_DRV_UpdatePwmPeriodDither | ( | uint32_t | instance, |
uint8_t | newModFracVal, | ||
bool | softwareTrigger | ||
) |
This function will use in the PWM period dithering. This value is added to an internal accumulator at the end of each PWM period. The value is updated with its write buffer value according to the register synchronization.
[in] | instance | The FTM peripheral instance number. |
[in] | newModFracVal | The modulo fractional value. |
[in] | softwareTrigger | If true a software trigger is generate to update parameters. |