The section describes the programming interface of the eFlexPWM Peripheral driver. The Pulse Width Modulator A (PWMA/eFlexPWM) module contains PWM sub modules, each of which is set up to control a single half-bridge power stage. Fault channel support is provided. This PWM module can generate various switching patterns, including highly sophisticated waveforms. It can be used to control all known Switched Mode Power Supplies (SMPS) topologies.
Initialization
To initialize the PWM driver, call the PWM_DRV_Init() function and pass the instance and sub module numbers of the relevant PWM. For instance, to use PWM0, pass a value of 0 to the initialization function. In addition, you should also pass a user configuration structure pwm_user_config_t, as shown here:
typedef struct PwmUserConfig {
uint8_t Clock;
uint8_t OutputTrigger;
uint8_t Polarity;
bool isFaultEnable;
} pwm_user_config_t;
Generate a PWM signal
The PWM calls the PWM_DRV_PwmStart() function to generate a PWM signal. Use this structure to configure different parameters related to this PWM signal:
typedef struct FtmPwmParam
typedef struct PwmParam
{
uint32_t uFrequencyHZ;
HAS TO BE UPDATED The mode options are kFtmEdgeAlignedPWM, kFtmCenterAlignedPWM and kFtmCombinedPWM. For edge mode, the options available are kFtmHighTrue and kFtmLowTrue. Specify the PWM signal frequency in Hertz and the duty cycle percentage (value between 0-100). When the PWM mode is kFtmCombinedPWM, specify a value for uFirstEdgeDelayPercent which delays the start of the PWM pulse.
|
pwm_status_t | PWM_DRV_Init (uint32_t instance) |
| Initializes the PWM module. More...
|
|
void | PWM_DRV_Deinit (uint32_t instance) |
| Shuts down the PWM driver. More...
|
|
pwm_status_t | PWM_DRV_SetupPwm (uint32_t instance, pwm_module_t subModule, pwm_module_setup_t *moduleSetupParams, pwm_module_signal_setup_t *signalParams) |
| Sets up the PWM signals from the FlewPWM module. More...
|
|
void | PWM_DRV_UpdatePwmSignal (uint32_t instance, pwm_module_t subModule, pwm_module_signal_setup_t *signalParams) |
| Updates the PWM signal settings. More...
|
|
void | PWM_DRV_SetTriggerCmd (uint32_t instance, pwm_module_t subModule, pwm_val_regs_t trigger, bool activate) |
| Enables or disables the PWM output trigger. More...
|
|
void | PWM_DRV_SetTriggerVal (uint32_t instance, pwm_module_t subModule, pwm_val_regs_t trigger, uint16_t triggerVal) |
| Sets the PWM trigger value. More...
|
|
void | PWM_DRV_SetupFault (uint32_t instance, pwm_module_t subModule, pwm_fault_input_t faultNum, pwm_fault_setup_t *faultParams, bool pwmA, bool pwmB, bool pwmX) |
| Sets up the PWM fault. More...
|
|
void | PWM_DRV_CounterStart (uint32_t instance, uint8_t value) |
| Starts the PWM counter. More...
|
|
void | PWM_DRV_CounterStop (uint32_t instance, uint8_t value) |
| Stops the PWM counter. More...
|
|
void | PWM_DRV_SetExternalClkFreq (uint32_t instance, uint32_t externalClkFreq) |
| Provides the frequency of the external clock source. More...
|
|
|
PWM_Type *const | g_pwmBase [PWM_INSTANCE_COUNT] |
| Table of base addresses for PWM instances. More...
|
|
const IRQn_Type | g_pwmCmpIrqId [FSL_FEATURE_PWM_CMP_INT_HANDLER_COUNT] |
| Table to save PWM IRQ enumeration numbers defined in CMSIS header file. More...
|
|
struct pwm_module_signal_setup_t |
uint32_t pwm_module_signal_setup_t::pwmAPulseWidth |
Specify FLEXPWM_NO_PWM_OUT_SIGNAL if no PWM output on this pin.
uint32_t pwm_module_signal_setup_t::pwmBPulseWidth |
Specify FLEXPWM_NO_PWM_OUT_SIGNAL if no PWM output on this pin.
Enumerator |
---|
kFlexPwmSignedCenterAligned |
Signed center-aligned.
|
kFlexPwmCenterAligned |
Unsigned cente-aligned.
|
kFlexPwmSignedEdgeAligned |
Signed edge-aligned.
|
kFlexPwmEdgeAligned |
Unsigned edge-aligned.
|
Enables the module clocks and interrupts in the interrupt controller.
- Parameters
-
instance | Instance number of the PWM module. |
- Returns
- kStatusPwmSuccess means success. Otherwise, means failure.
void PWM_DRV_Deinit |
( |
uint32_t |
instance | ) |
|
This function de-initializes the EflexPWM module and disables the clock for the submodules. It also disables the module-level interrupts.
- Parameters
-
instance | Instance number of the PWM module. |
The function initializes the submodule according to the parameters passed in by the user. The function also sets up the value compare registers to match the PWM signal requirements. If the dead time insertion logic is enabled, the pulse period is reduced by the dead time period specified by the user.
- Parameters
-
instance | Instance number of the PWM module. |
subModule | The FlexPWM submodule that is configured |
moduleSetupParams | The initialization values used to set up the submodule |
signalParams | Signal parameters which generate the submodules PWM signals |
- Returns
- Returns an error if the requested submodule clock is incorrect, i.e., the request for kFlexPwmModule0 for submodule 0 or request for external clock without informing the driver of the external clock frequency by calling PWM_DVR_SetExternalClkFreq(). Success otherwise.
The function updates the PWM signal to the new value that is passed in. If the dead time insertion logic is enabled then the pulse period is reduced by the dead time period specified by the user.
- Parameters
-
instance | Instance number of the PWM module. |
subModule | The FlexPWM submodule that is configured |
signalParams | Signal parameters which generate the submodules PWM signals |
This function allows the user to enable or disable the PWM trigger. The PWM has 2 triggers. The trigger 0 is activated when the counter matches VAL 0, VAL 2, or VAL 4 register. The trigger 1 is activated when the counter matches VAL 1, VAL 3, or VAL 5.
- Parameters
-
instance | Instance number of the PWM module. |
subModule | The FlexPWM submodule that is configured |
trigger | Trigger number that the user wants to activate |
activate | Enable or disable the trigger |
This function sets the value in the compare register that generates a trigger. Note that the user must make sure that the value of the register being modified is not currently used to generate a PWM signal.
- Parameters
-
instance | Instance number of the PWM module. |
subModule | The FlexPWM submodule that is configured |
trigger | Trigger number that we wish to configure |
triggerVal | Trigger value |
This function configures a fault parameter and enables the fault for the appropriate sub-module signals.
- Parameters
-
instance | Instance number of the PWM module. |
subModule | The FlexPWM submodule that is configured |
faultNum | Fault that should be configured |
faultParams | Parameters that configure the fault |
pwmA | true: PWM A is disabled by this fault; false: PWM A is not affected by this fault |
pwmB | true: PWM B is disabled by this fault; false: PWM A is not affected by this fault |
pwmX | true: PWM X is disabled by this fault; false: PWM A is not affected by this fault |
void PWM_DRV_CounterStart |
( |
uint32_t |
instance, |
|
|
uint8_t |
value |
|
) |
| |
This function starts the PWM submodule counters.
- Parameters
-
instance | Instance number of the PWM module. |
value | Submodules to start; 4 bit value, 1-bit for each submodule |
void PWM_DRV_CounterStop |
( |
uint32_t |
instance, |
|
|
uint8_t |
value |
|
) |
| |
This function stops the the PWM submodule counters.
- Parameters
-
instance | Instance number of the PWM module. |
value | Submodules to stop; 4 bit value, 1-bit for each submodule |
void PWM_DRV_SetExternalClkFreq |
( |
uint32_t |
instance, |
|
|
uint32_t |
externalClkFreq |
|
) |
| |
When using an external signal as clock source, the user should provide the frequency of this clock source so that this driver can calculate the register values used to generate the requested PWM signal.
- Parameters
-
instance | Instance number of the PWM module. |
externalClkFreq | External clock frequency (in Hz). |
PWM_Type* const g_pwmBase[PWM_INSTANCE_COUNT] |
const IRQn_Type g_pwmCmpIrqId[FSL_FEATURE_PWM_CMP_INT_HANDLER_COUNT] |