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

Overview

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:

// PWM configuration structure for user
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.

Data Structures

struct  pwm_module_signal_setup_t
 Configuration structure for the user to define the PWM signal characteristics. More...
 

Macros

#define FLEXPWM_NO_PWM_OUT_SIGNAL   (0)
 Used to indicate that a particular pin in the submodule does NOT output a PWM signal.
 

Enumerations

enum  pwm_signal_type_t {
  kFlexPwmSignedCenterAligned = 0U,
  kFlexPwmCenterAligned,
  kFlexPwmSignedEdgeAligned,
  kFlexPwmEdgeAligned
}
 PWM Signal Type options. More...
 

Functions

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...
 

Variables

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...
 

Data Structure Documentation

struct pwm_module_signal_setup_t

Data Fields

uint32_t pwmPeriod
 PWM period specified in microseconds.
 
pwm_signal_type_t pwmType
 PWM type, edge or center, signed or unsigned.
 
uint32_t pwmAPulseWidth
 PWM A pulse width specified in microseconds. More...
 
uint32_t pwmBPulseWidth
 PWM B pulse width specified in microseconds. More...
 
bool pwmAPolarity
 true: if output is to be inverted; false: if no output inversion.
 
bool pwmBPolarity
 true: if output is to be inverted; false: if no output inversion.
 

Field Documentation

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.

Enumeration Type Documentation

Enumerator
kFlexPwmSignedCenterAligned 

Signed center-aligned.

kFlexPwmCenterAligned 

Unsigned cente-aligned.

kFlexPwmSignedEdgeAligned 

Signed edge-aligned.

kFlexPwmEdgeAligned 

Unsigned edge-aligned.

Function Documentation

pwm_status_t PWM_DRV_Init ( uint32_t  instance)

Enables the module clocks and interrupts in the interrupt controller.

Parameters
instanceInstance 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
instanceInstance number of the PWM module.
pwm_status_t PWM_DRV_SetupPwm ( uint32_t  instance,
pwm_module_t  subModule,
pwm_module_setup_t moduleSetupParams,
pwm_module_signal_setup_t signalParams 
)

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
instanceInstance number of the PWM module.
subModuleThe FlexPWM submodule that is configured
moduleSetupParamsThe initialization values used to set up the submodule
signalParamsSignal 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.
void PWM_DRV_UpdatePwmSignal ( uint32_t  instance,
pwm_module_t  subModule,
pwm_module_signal_setup_t signalParams 
)

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
instanceInstance number of the PWM module.
subModuleThe FlexPWM submodule that is configured
signalParamsSignal parameters which generate the submodules PWM signals
void PWM_DRV_SetTriggerCmd ( uint32_t  instance,
pwm_module_t  subModule,
pwm_val_regs_t  trigger,
bool  activate 
)

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
instanceInstance number of the PWM module.
subModuleThe FlexPWM submodule that is configured
triggerTrigger number that the user wants to activate
activateEnable or disable the trigger
void PWM_DRV_SetTriggerVal ( uint32_t  instance,
pwm_module_t  subModule,
pwm_val_regs_t  trigger,
uint16_t  triggerVal 
)

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
instanceInstance number of the PWM module.
subModuleThe FlexPWM submodule that is configured
triggerTrigger number that we wish to configure
triggerValTrigger value
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 
)

This function configures a fault parameter and enables the fault for the appropriate sub-module signals.

Parameters
instanceInstance number of the PWM module.
subModuleThe FlexPWM submodule that is configured
faultNumFault that should be configured
faultParamsParameters that configure the fault
pwmAtrue: PWM A is disabled by this fault; false: PWM A is not affected by this fault
pwmBtrue: PWM B is disabled by this fault; false: PWM A is not affected by this fault
pwmXtrue: 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
instanceInstance number of the PWM module.
valueSubmodules 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
instanceInstance number of the PWM module.
valueSubmodules 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
instanceInstance number of the PWM module.
externalClkFreqExternal clock frequency (in Hz).

Variable Documentation

PWM_Type* const g_pwmBase[PWM_INSTANCE_COUNT]
const IRQn_Type g_pwmCmpIrqId[FSL_FEATURE_PWM_CMP_INT_HANDLER_COUNT]