MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PWM: Pulse Width Modulator

Overview

The MCUXpresso SDK provides a driver for the Pulse Width Modulator (PWM) of MCUXpresso SDK devices.

PWM: Pulse Width Modulator

Initialization and deinitialization

The function PWM_Init() initializes the PWM sub module with specified configurations, the function PWM_GetDefaultConfig() could help to get the default configurations. The initialization function configures the sub module for the requested register update mode for registers with buffers. It also sets up the sub module operation in debug and wait modes.

PWM Operations

The function PWM_SetupPwm() sets up PWM channels for PWM output, the function can set up PWM signal properties for multiple channels. The PWM has 2 channels: A and B. Each channel has its own duty cycle and level-mode specified, however the same PWM period and PWM mode is applied to all channels requesting PWM output. The signal duty cycle is provided as a percentage of the PWM period, its value should be between 0 and 100; 0=inactive signal(0% duty cycle) and 100=always active signal (100% duty cycle). The function also sets up the channel dead time value which is used when the user selects complementary mode of operation.

The function PWM_UpdatePwmDutycycle() updates the PWM signal duty cycle of a particular PWM channel.

Input capture operations

The function PWM_SetupInputCapture() sets up a PWM channel for input capture. The user can specify the capture edge and the mode; one-shot capture or free-running capture.

Fault operation

The function PWM_SetupFault() sets up the properties for each fault.

PWM Start and Stop operations

The function PWM_StartTimer() can be used to start one or multiple sub modules. The function PWM_StopTimer() can be used to stop one or multiple sub modules.

Status

Provide functions to get and clear the PWM status.

Interrupt

Provide functions to enable/disable PWM interrupts and get current enabled interrupts.

Register Update

Some of the PWM registers have buffers, the driver support various methods to update these registers with the content of the register buffer. The update mechanism for register with buffers can be specified through the following fields available in the configuration structure. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/pwmThe user can select one of the reload options provided in enumeration pwm_register_reload_t. When using immediate reload, the reloadFrequency field is not used.

The driver initialization function sets up the appropriate bits in the PWM module based on the register update options selected.

The below function should be used to initiate a register reload. The example shows register reload initiated on PWM sub modules 0, 1, and 2. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/pwm

Typical use case

PWM output

Output PWM signal on 3 PWM sub module with different dutycycles. Periodically update the PWM signal duty cycle. Each sub module runs in Complementary output mode with PWM A used to generate the complementary PWM pair. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/pwm

Data Structures

struct  pwm_signal_param_t
 Structure for the user to define the PWM signal characteristics. More...
 
struct  pwm_config_t
 PWM config structure. More...
 
struct  pwm_fault_input_filter_param_t
 Structure for the user to configure the fault input filter. More...
 
struct  pwm_fault_param_t
 Structure is used to hold the parameters to configure a PWM fault. More...
 
struct  pwm_input_capture_param_t
 Structure is used to hold parameters to configure the capture capability of a signal pin. More...
 

Macros

#define PWM_SUBMODULE_SWCONTROL_WIDTH   2
 Number of bits per submodule for software output control.
 

Enumerations

enum  pwm_submodule_t {
  kPWM_Module_0 = 0U,
  kPWM_Module_1,
  kPWM_Module_2,
  kPWM_Module_3
}
 List of PWM submodules. More...
 
enum  pwm_channels_t
 List of PWM channels in each module.
 
enum  pwm_value_register_t {
  kPWM_ValueRegister_0 = 0U,
  kPWM_ValueRegister_1,
  kPWM_ValueRegister_2,
  kPWM_ValueRegister_3,
  kPWM_ValueRegister_4,
  kPWM_ValueRegister_5
}
 List of PWM value registers. More...
 
enum  _pwm_value_register_mask {
  kPWM_ValueRegisterMask_0 = (1U << 0),
  kPWM_ValueRegisterMask_1 = (1U << 1),
  kPWM_ValueRegisterMask_2 = (1U << 2),
  kPWM_ValueRegisterMask_3 = (1U << 3),
  kPWM_ValueRegisterMask_4 = (1U << 4),
  kPWM_ValueRegisterMask_5 = (1U << 5)
}
 List of PWM value registers mask. More...
 
enum  pwm_clock_source_t {
  kPWM_BusClock = 0U,
  kPWM_ExternalClock,
  kPWM_Submodule0Clock
}
 PWM clock source selection. More...
 
enum  pwm_clock_prescale_t {
  kPWM_Prescale_Divide_1 = 0U,
  kPWM_Prescale_Divide_2,
  kPWM_Prescale_Divide_4,
  kPWM_Prescale_Divide_8,
  kPWM_Prescale_Divide_16,
  kPWM_Prescale_Divide_32,
  kPWM_Prescale_Divide_64,
  kPWM_Prescale_Divide_128
}
 PWM prescaler factor selection for clock source. More...
 
enum  pwm_force_output_trigger_t {
  kPWM_Force_Local = 0U,
  kPWM_Force_Master,
  kPWM_Force_LocalReload,
  kPWM_Force_MasterReload,
  kPWM_Force_LocalSync,
  kPWM_Force_MasterSync,
  kPWM_Force_External,
  kPWM_Force_ExternalSync
}
 Options that can trigger a PWM FORCE_OUT. More...
 
enum  pwm_init_source_t {
  kPWM_Initialize_LocalSync = 0U,
  kPWM_Initialize_MasterReload,
  kPWM_Initialize_MasterSync,
  kPWM_Initialize_ExtSync
}
 PWM counter initialization options. More...
 
enum  pwm_load_frequency_t {
  kPWM_LoadEveryOportunity = 0U,
  kPWM_LoadEvery2Oportunity,
  kPWM_LoadEvery3Oportunity,
  kPWM_LoadEvery4Oportunity,
  kPWM_LoadEvery5Oportunity,
  kPWM_LoadEvery6Oportunity,
  kPWM_LoadEvery7Oportunity,
  kPWM_LoadEvery8Oportunity,
  kPWM_LoadEvery9Oportunity,
  kPWM_LoadEvery10Oportunity,
  kPWM_LoadEvery11Oportunity,
  kPWM_LoadEvery12Oportunity,
  kPWM_LoadEvery13Oportunity,
  kPWM_LoadEvery14Oportunity,
  kPWM_LoadEvery15Oportunity,
  kPWM_LoadEvery16Oportunity
}
 PWM load frequency selection. More...
 
enum  pwm_fault_input_t {
  kPWM_Fault_0 = 0U,
  kPWM_Fault_1,
  kPWM_Fault_2,
  kPWM_Fault_3
}
 List of PWM fault selections. More...
 
enum  pwm_fault_disable_t {
  kPWM_FaultDisable_0 = (1U << 0),
  kPWM_FaultDisable_1 = (1U << 1),
  kPWM_FaultDisable_2 = (1U << 2),
  kPWM_FaultDisable_3 = (1U << 3)
}
 List of PWM fault disable mapping selections. More...
 
enum  pwm_fault_channels_t
 List of PWM fault channels.
 
enum  pwm_input_capture_edge_t {
  kPWM_Disable = 0U,
  kPWM_FallingEdge,
  kPWM_RisingEdge,
  kPWM_RiseAndFallEdge
}
 PWM capture edge select. More...
 
enum  pwm_force_signal_t {
  kPWM_UsePwm = 0U,
  kPWM_InvertedPwm,
  kPWM_SoftwareControl,
  kPWM_UseExternal
}
 PWM output options when a FORCE_OUT signal is asserted. More...
 
enum  pwm_chnl_pair_operation_t {
  kPWM_Independent = 0U,
  kPWM_ComplementaryPwmA,
  kPWM_ComplementaryPwmB
}
 Options available for the PWM A & B pair operation. More...
 
enum  pwm_register_reload_t {
  kPWM_ReloadImmediate = 0U,
  kPWM_ReloadPwmHalfCycle,
  kPWM_ReloadPwmFullCycle,
  kPWM_ReloadPwmHalfAndFullCycle
}
 Options available on how to load the buffered-registers with new values. More...
 
enum  pwm_fault_recovery_mode_t {
  kPWM_NoRecovery = 0U,
  kPWM_RecoverHalfCycle,
  kPWM_RecoverFullCycle,
  kPWM_RecoverHalfAndFullCycle
}
 Options available on how to re-enable the PWM output when recovering from a fault. More...
 
enum  pwm_interrupt_enable_t {
  kPWM_CompareVal0InterruptEnable = (1U << 0),
  kPWM_CompareVal1InterruptEnable = (1U << 1),
  kPWM_CompareVal2InterruptEnable = (1U << 2),
  kPWM_CompareVal3InterruptEnable = (1U << 3),
  kPWM_CompareVal4InterruptEnable = (1U << 4),
  kPWM_CompareVal5InterruptEnable = (1U << 5),
  kPWM_CaptureX0InterruptEnable = (1U << 6),
  kPWM_CaptureX1InterruptEnable = (1U << 7),
  kPWM_CaptureB0InterruptEnable = (1U << 8),
  kPWM_CaptureB1InterruptEnable = (1U << 9),
  kPWM_CaptureA0InterruptEnable = (1U << 10),
  kPWM_CaptureA1InterruptEnable = (1U << 11),
  kPWM_ReloadInterruptEnable = (1U << 12),
  kPWM_ReloadErrorInterruptEnable = (1U << 13),
  kPWM_Fault0InterruptEnable = (1U << 16),
  kPWM_Fault1InterruptEnable = (1U << 17),
  kPWM_Fault2InterruptEnable = (1U << 18),
  kPWM_Fault3InterruptEnable = (1U << 19)
}
 List of PWM interrupt options. More...
 
enum  pwm_status_flags_t {
  kPWM_CompareVal0Flag = (1U << 0),
  kPWM_CompareVal1Flag = (1U << 1),
  kPWM_CompareVal2Flag = (1U << 2),
  kPWM_CompareVal3Flag = (1U << 3),
  kPWM_CompareVal4Flag = (1U << 4),
  kPWM_CompareVal5Flag = (1U << 5),
  kPWM_CaptureX0Flag = (1U << 6),
  kPWM_CaptureX1Flag = (1U << 7),
  kPWM_CaptureB0Flag = (1U << 8),
  kPWM_CaptureB1Flag = (1U << 9),
  kPWM_CaptureA0Flag = (1U << 10),
  kPWM_CaptureA1Flag = (1U << 11),
  kPWM_ReloadFlag = (1U << 12),
  kPWM_ReloadErrorFlag = (1U << 13),
  kPWM_RegUpdatedFlag = (1U << 14),
  kPWM_Fault0Flag = (1U << 16),
  kPWM_Fault1Flag = (1U << 17),
  kPWM_Fault2Flag = (1U << 18),
  kPWM_Fault3Flag = (1U << 19)
}
 List of PWM status flags. More...
 
enum  pwm_dma_enable_t {
  kPWM_CaptureX0DMAEnable = (1U << 0),
  kPWM_CaptureX1DMAEnable = (1U << 1),
  kPWM_CaptureB0DMAEnable = (1U << 2),
  kPWM_CaptureB1DMAEnable = (1U << 3),
  kPWM_CaptureA0DMAEnable = (1U << 4),
  kPWM_CaptureA1DMAEnable = (1U << 5)
}
 List of PWM DMA options. More...
 
enum  pwm_dma_source_select_t {
  kPWM_DMARequestDisable = 0U,
  kPWM_DMAWatermarksEnable,
  kPWM_DMALocalSync,
  kPWM_DMALocalReload
}
 List of PWM capture DMA enable source select. More...
 
enum  pwm_watermark_control_t {
  kPWM_FIFOWatermarksOR = 0U,
  kPWM_FIFOWatermarksAND
}
 PWM FIFO Watermark AND Control. More...
 
enum  pwm_mode_t {
  kPWM_SignedCenterAligned = 0U,
  kPWM_CenterAligned,
  kPWM_SignedEdgeAligned,
  kPWM_EdgeAligned
}
 PWM operation mode. More...
 
enum  pwm_level_select_t {
  kPWM_HighTrue = 0U,
  kPWM_LowTrue
}
 PWM output pulse mode, high-true or low-true. More...
 
enum  pwm_fault_state_t {
  kPWM_PwmFaultState0,
  kPWM_PwmFaultState1,
  kPWM_PwmFaultState2,
  kPWM_PwmFaultState3
}
 PWM output fault status. More...
 
enum  pwm_reload_source_select_t {
  kPWM_LocalReload = 0U,
  kPWM_MasterReload
}
 PWM reload source select. More...
 
enum  pwm_fault_clear_t {
  kPWM_Automatic = 0U,
  kPWM_ManualNormal,
  kPWM_ManualSafety
}
 PWM fault clearing options. More...
 
enum  pwm_module_control_t {
  kPWM_Control_Module_0 = (1U << 0),
  kPWM_Control_Module_1 = (1U << 1),
  kPWM_Control_Module_2 = (1U << 2),
  kPWM_Control_Module_3 = (1U << 3)
}
 Options for submodule master control operation. More...
 

Functions

void PWM_SetupInputCapture (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmChannel, const pwm_input_capture_param_t *inputCaptureParams)
 Sets up the PWM input capture. More...
 
void PWM_SetupFaultInputFilter (PWM_Type *base, const pwm_fault_input_filter_param_t *faultInputFilterParams)
 Sets up the PWM fault input filter. More...
 
void PWM_SetupFaults (PWM_Type *base, pwm_fault_input_t faultNum, const pwm_fault_param_t *faultParams)
 Sets up the PWM fault protection. More...
 
void PWM_FaultDefaultConfig (pwm_fault_param_t *config)
 Fill in the PWM fault config struct with the default settings. More...
 
void PWM_SetupForceSignal (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmChannel, pwm_force_signal_t mode)
 Selects the signal to output on a PWM pin when a FORCE_OUT signal is asserted. More...
 
static void PWM_OutputTriggerEnable (PWM_Type *base, pwm_submodule_t subModule, pwm_value_register_t valueRegister, bool activate)
 Enables or disables the PWM output trigger. More...
 
static void PWM_ActivateOutputTrigger (PWM_Type *base, pwm_submodule_t subModule, uint16_t valueRegisterMask)
 Enables the PWM output trigger. More...
 
static void PWM_DeactivateOutputTrigger (PWM_Type *base, pwm_submodule_t subModule, uint16_t valueRegisterMask)
 Disables the PWM output trigger. More...
 
static void PWM_SetupSwCtrlOut (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmChannel, bool value)
 Sets the software control output for a pin to high or low. More...
 
static void PWM_SetPwmLdok (PWM_Type *base, uint8_t subModulesToUpdate, bool value)
 Sets or clears the PWM LDOK bit on a single or multiple submodules. More...
 
static void PWM_SetPwmFaultState (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmChannel, pwm_fault_state_t faultState)
 Set PWM output fault status. More...
 
static void PWM_SetupFaultDisableMap (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmChannel, pwm_fault_channels_t pwm_fault_channels, uint16_t value)
 Set PWM fault disable mapping. More...
 

Driver version

#define FSL_PWM_DRIVER_VERSION   (MAKE_VERSION(2, 2, 1))
 Version 2.2.1.
 

Initialization and deinitialization

status_t PWM_Init (PWM_Type *base, pwm_submodule_t subModule, const pwm_config_t *config)
 Ungates the PWM submodule clock and configures the peripheral for basic operation. More...
 
void PWM_Deinit (PWM_Type *base, pwm_submodule_t subModule)
 Gate the PWM submodule clock. More...
 
void PWM_GetDefaultConfig (pwm_config_t *config)
 Fill in the PWM config struct with the default settings. More...
 

Module PWM output

status_t PWM_SetupPwm (PWM_Type *base, pwm_submodule_t subModule, const pwm_signal_param_t *chnlParams, uint8_t numOfChnls, pwm_mode_t mode, uint32_t pwmFreq_Hz, uint32_t srcClock_Hz)
 Sets up the PWM signals for a PWM submodule. More...
 
void PWM_UpdatePwmDutycycle (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmSignal, pwm_mode_t currPwmMode, uint8_t dutyCyclePercent)
 Updates the PWM signal's dutycycle. More...
 
void PWM_UpdatePwmDutycycleHighAccuracy (PWM_Type *base, pwm_submodule_t subModule, pwm_channels_t pwmSignal, pwm_mode_t currPwmMode, uint16_t dutyCycle)
 Updates the PWM signal's dutycycle with 16-bit accuracy. More...
 

Interrupts Interface

void PWM_EnableInterrupts (PWM_Type *base, pwm_submodule_t subModule, uint32_t mask)
 Enables the selected PWM interrupts. More...
 
void PWM_DisableInterrupts (PWM_Type *base, pwm_submodule_t subModule, uint32_t mask)
 Disables the selected PWM interrupts. More...
 
uint32_t PWM_GetEnabledInterrupts (PWM_Type *base, pwm_submodule_t subModule)
 Gets the enabled PWM interrupts. More...
 

DMA Interface

static void PWM_DMAFIFOWatermarkControl (PWM_Type *base, pwm_submodule_t subModule, pwm_watermark_control_t pwm_watermark_control)
 Capture DMA Enable Source Select. More...
 
static void PWM_DMACaptureSourceSelect (PWM_Type *base, pwm_submodule_t subModule, pwm_dma_source_select_t pwm_dma_source_select)
 Capture DMA Enable Source Select. More...
 
static void PWM_EnableDMACapture (PWM_Type *base, pwm_submodule_t subModule, uint16_t mask, bool activate)
 Enables or disables the selected PWM DMA Capture read request. More...
 
static void PWM_EnableDMAWrite (PWM_Type *base, pwm_submodule_t subModule, bool activate)
 Enables or disables the PWM DMA write request. More...
 

Status Interface

uint32_t PWM_GetStatusFlags (PWM_Type *base, pwm_submodule_t subModule)
 Gets the PWM status flags. More...
 
void PWM_ClearStatusFlags (PWM_Type *base, pwm_submodule_t subModule, uint32_t mask)
 Clears the PWM status flags. More...
 

Timer Start and Stop

static void PWM_StartTimer (PWM_Type *base, uint8_t subModulesToStart)
 Starts the PWM counter for a single or multiple submodules. More...
 
static void PWM_StopTimer (PWM_Type *base, uint8_t subModulesToStop)
 Stops the PWM counter for a single or multiple submodules. More...
 

Data Structure Documentation

struct pwm_signal_param_t

Data Fields

pwm_channels_t pwmChannel
 PWM channel being configured; PWM A or PWM B.
 
uint8_t dutyCyclePercent
 PWM pulse width, value should be between 0 to 100 0=inactive signal(0% duty cycle)... More...
 
pwm_level_select_t level
 PWM output active level select.
 
uint16_t deadtimeValue
 The deadtime value; only used if channel pair is operating in complementary mode.
 
pwm_fault_state_t faultState
 PWM output fault status.
 

Field Documentation

uint8_t pwm_signal_param_t::dutyCyclePercent

100=always active signal (100% duty cycle)

struct pwm_config_t

This structure holds the configuration settings for the PWM peripheral. To initialize this structure to reasonable defaults, call the PWM_GetDefaultConfig() function and pass a pointer to your config structure instance.

The config struct can be made const so it resides in flash

Data Fields

bool enableDebugMode
 true: PWM continues to run in debug mode; false: PWM is paused in debug mode
 
bool enableWait
 true: PWM continues to run in WAIT mode; false: PWM is paused in WAIT mode
 
pwm_init_source_t initializationControl
 Option to initialize the counter.
 
pwm_clock_source_t clockSource
 Clock source for the counter.
 
pwm_clock_prescale_t prescale
 Pre-scaler to divide down the clock.
 
pwm_chnl_pair_operation_t pairOperation
 Channel pair in indepedent or complementary mode.
 
pwm_register_reload_t reloadLogic
 PWM Reload logic setup.
 
pwm_reload_source_select_t reloadSelect
 Reload source select.
 
pwm_load_frequency_t reloadFrequency
 Specifies when to reload, used when user's choice is not immediate reload.
 
pwm_force_output_trigger_t forceTrigger
 Specify which signal will trigger a FORCE_OUT.
 
struct pwm_fault_input_filter_param_t

Data Fields

uint8_t faultFilterCount
 Fault filter count.
 
uint8_t faultFilterPeriod
 Fault filter period;value of 0 will bypass the filter.
 
bool faultGlitchStretch
 Fault Glitch Stretch Enable: A logic 1 means that input fault signals will be stretched to at least 2 IPBus clock cycles.
 
struct pwm_fault_param_t

Data Fields

pwm_fault_clear_t faultClearingMode
 Fault clearing mode to use.
 
bool faultLevel
 true: Logic 1 indicates fault; false: Logic 0 indicates fault
 
bool enableCombinationalPath
 true: Combinational Path from fault input is enabled; false: No combination path is available
 
pwm_fault_recovery_mode_t recoverMode
 Specify when to re-enable the PWM output.
 
struct pwm_input_capture_param_t

Data Fields

bool captureInputSel
 true: Use the edge counter signal as source false: Use the raw input signal from the pin as source
 
uint8_t edgeCompareValue
 Compare value, used only if edge counter is used as source.
 
pwm_input_capture_edge_t edge0
 Specify which edge causes a capture for input circuitry 0.
 
pwm_input_capture_edge_t edge1
 Specify which edge causes a capture for input circuitry 1.
 
bool enableOneShotCapture
 true: Use one-shot capture mode; false: Use free-running capture mode
 
uint8_t fifoWatermark
 Watermark level for capture FIFO. More...
 

Field Documentation

uint8_t pwm_input_capture_param_t::fifoWatermark

The capture flags in the status register will set if the word count in the FIFO is greater than this watermark level

Enumeration Type Documentation

Enumerator
kPWM_Module_0 

Submodule 0.

kPWM_Module_1 

Submodule 1.

kPWM_Module_2 

Submodule 2.

kPWM_Module_3 

Submodule 3.

Enumerator
kPWM_ValueRegister_0 

PWM Value0 register.

kPWM_ValueRegister_1 

PWM Value1 register.

kPWM_ValueRegister_2 

PWM Value2 register.

kPWM_ValueRegister_3 

PWM Value3 register.

kPWM_ValueRegister_4 

PWM Value4 register.

kPWM_ValueRegister_5 

PWM Value5 register.

Enumerator
kPWM_ValueRegisterMask_0 

PWM Value0 register mask.

kPWM_ValueRegisterMask_1 

PWM Value1 register mask.

kPWM_ValueRegisterMask_2 

PWM Value2 register mask.

kPWM_ValueRegisterMask_3 

PWM Value3 register mask.

kPWM_ValueRegisterMask_4 

PWM Value4 register mask.

kPWM_ValueRegisterMask_5 

PWM Value5 register mask.

Enumerator
kPWM_BusClock 

The IPBus clock is used as the clock.

kPWM_ExternalClock 

EXT_CLK is used as the clock.

kPWM_Submodule0Clock 

Clock of the submodule 0 (AUX_CLK) is used as the source clock.

Enumerator
kPWM_Prescale_Divide_1 

PWM clock frequency = fclk/1.

kPWM_Prescale_Divide_2 

PWM clock frequency = fclk/2.

kPWM_Prescale_Divide_4 

PWM clock frequency = fclk/4.

kPWM_Prescale_Divide_8 

PWM clock frequency = fclk/8.

kPWM_Prescale_Divide_16 

PWM clock frequency = fclk/16.

kPWM_Prescale_Divide_32 

PWM clock frequency = fclk/32.

kPWM_Prescale_Divide_64 

PWM clock frequency = fclk/64.

kPWM_Prescale_Divide_128 

PWM clock frequency = fclk/128.

Enumerator
kPWM_Force_Local 

The local force signal, CTRL2[FORCE], from the submodule is used to force updates.

kPWM_Force_Master 

The master force signal from submodule 0 is used to force updates.

kPWM_Force_LocalReload 

The local reload signal from this submodule is used to force updates without regard to the state of LDOK.

kPWM_Force_MasterReload 

The master reload signal from submodule 0 is used to force updates if LDOK is set.

kPWM_Force_LocalSync 

The local sync signal from this submodule is used to force updates.

kPWM_Force_MasterSync 

The master sync signal from submodule0 is used to force updates.

kPWM_Force_External 

The external force signal, EXT_FORCE, from outside the PWM module causes updates.

kPWM_Force_ExternalSync 

The external sync signal, EXT_SYNC, from outside the PWM module causes updates.

Enumerator
kPWM_Initialize_LocalSync 

Local sync causes initialization.

kPWM_Initialize_MasterReload 

Master reload from submodule 0 causes initialization.

kPWM_Initialize_MasterSync 

Master sync from submodule 0 causes initialization.

kPWM_Initialize_ExtSync 

EXT_SYNC causes initialization.

Enumerator
kPWM_LoadEveryOportunity 

Every PWM opportunity.

kPWM_LoadEvery2Oportunity 

Every 2 PWM opportunities.

kPWM_LoadEvery3Oportunity 

Every 3 PWM opportunities.

kPWM_LoadEvery4Oportunity 

Every 4 PWM opportunities.

kPWM_LoadEvery5Oportunity 

Every 5 PWM opportunities.

kPWM_LoadEvery6Oportunity 

Every 6 PWM opportunities.

kPWM_LoadEvery7Oportunity 

Every 7 PWM opportunities.

kPWM_LoadEvery8Oportunity 

Every 8 PWM opportunities.

kPWM_LoadEvery9Oportunity 

Every 9 PWM opportunities.

kPWM_LoadEvery10Oportunity 

Every 10 PWM opportunities.

kPWM_LoadEvery11Oportunity 

Every 11 PWM opportunities.

kPWM_LoadEvery12Oportunity 

Every 12 PWM opportunities.

kPWM_LoadEvery13Oportunity 

Every 13 PWM opportunities.

kPWM_LoadEvery14Oportunity 

Every 14 PWM opportunities.

kPWM_LoadEvery15Oportunity 

Every 15 PWM opportunities.

kPWM_LoadEvery16Oportunity 

Every 16 PWM opportunities.

Enumerator
kPWM_Fault_0 

Fault 0 input pin.

kPWM_Fault_1 

Fault 1 input pin.

kPWM_Fault_2 

Fault 2 input pin.

kPWM_Fault_3 

Fault 3 input pin.

Enumerator
kPWM_FaultDisable_0 

Fault 0 disable mapping.

kPWM_FaultDisable_1 

Fault 1 disable mapping.

kPWM_FaultDisable_2 

Fault 2 disable mapping.

kPWM_FaultDisable_3 

Fault 3 disable mapping.

Enumerator
kPWM_Disable 

Disabled.

kPWM_FallingEdge 

Capture on falling edge only.

kPWM_RisingEdge 

Capture on rising edge only.

kPWM_RiseAndFallEdge 

Capture on rising or falling edge.

Enumerator
kPWM_UsePwm 

Generated PWM signal is used by the deadtime logic.

kPWM_InvertedPwm 

Inverted PWM signal is used by the deadtime logic.

kPWM_SoftwareControl 

Software controlled value is used by the deadtime logic.

kPWM_UseExternal 

PWM_EXTA signal is used by the deadtime logic.

Enumerator
kPWM_Independent 

PWM A & PWM B operate as 2 independent channels.

kPWM_ComplementaryPwmA 

PWM A & PWM B are complementary channels, PWM A generates the signal.

kPWM_ComplementaryPwmB 

PWM A & PWM B are complementary channels, PWM B generates the signal.

Enumerator
kPWM_ReloadImmediate 

Buffered-registers get loaded with new values as soon as LDOK bit is set.

kPWM_ReloadPwmHalfCycle 

Registers loaded on a PWM half cycle.

kPWM_ReloadPwmFullCycle 

Registers loaded on a PWM full cycle.

kPWM_ReloadPwmHalfAndFullCycle 

Registers loaded on a PWM half & full cycle.

Enumerator
kPWM_NoRecovery 

PWM output will stay inactive.

kPWM_RecoverHalfCycle 

PWM output re-enabled at the first half cycle.

kPWM_RecoverFullCycle 

PWM output re-enabled at the first full cycle.

kPWM_RecoverHalfAndFullCycle 

PWM output re-enabled at the first half or full cycle.

Enumerator
kPWM_CompareVal0InterruptEnable 

PWM VAL0 compare interrupt.

kPWM_CompareVal1InterruptEnable 

PWM VAL1 compare interrupt.

kPWM_CompareVal2InterruptEnable 

PWM VAL2 compare interrupt.

kPWM_CompareVal3InterruptEnable 

PWM VAL3 compare interrupt.

kPWM_CompareVal4InterruptEnable 

PWM VAL4 compare interrupt.

kPWM_CompareVal5InterruptEnable 

PWM VAL5 compare interrupt.

kPWM_CaptureX0InterruptEnable 

PWM capture X0 interrupt.

kPWM_CaptureX1InterruptEnable 

PWM capture X1 interrupt.

kPWM_CaptureB0InterruptEnable 

PWM capture B0 interrupt.

kPWM_CaptureB1InterruptEnable 

PWM capture B1 interrupt.

kPWM_CaptureA0InterruptEnable 

PWM capture A0 interrupt.

kPWM_CaptureA1InterruptEnable 

PWM capture A1 interrupt.

kPWM_ReloadInterruptEnable 

PWM reload interrupt.

kPWM_ReloadErrorInterruptEnable 

PWM reload error interrupt.

kPWM_Fault0InterruptEnable 

PWM fault 0 interrupt.

kPWM_Fault1InterruptEnable 

PWM fault 1 interrupt.

kPWM_Fault2InterruptEnable 

PWM fault 2 interrupt.

kPWM_Fault3InterruptEnable 

PWM fault 3 interrupt.

Enumerator
kPWM_CompareVal0Flag 

PWM VAL0 compare flag.

kPWM_CompareVal1Flag 

PWM VAL1 compare flag.

kPWM_CompareVal2Flag 

PWM VAL2 compare flag.

kPWM_CompareVal3Flag 

PWM VAL3 compare flag.

kPWM_CompareVal4Flag 

PWM VAL4 compare flag.

kPWM_CompareVal5Flag 

PWM VAL5 compare flag.

kPWM_CaptureX0Flag 

PWM capture X0 flag.

kPWM_CaptureX1Flag 

PWM capture X1 flag.

kPWM_CaptureB0Flag 

PWM capture B0 flag.

kPWM_CaptureB1Flag 

PWM capture B1 flag.

kPWM_CaptureA0Flag 

PWM capture A0 flag.

kPWM_CaptureA1Flag 

PWM capture A1 flag.

kPWM_ReloadFlag 

PWM reload flag.

kPWM_ReloadErrorFlag 

PWM reload error flag.

kPWM_RegUpdatedFlag 

PWM registers updated flag.

kPWM_Fault0Flag 

PWM fault 0 flag.

kPWM_Fault1Flag 

PWM fault 1 flag.

kPWM_Fault2Flag 

PWM fault 2 flag.

kPWM_Fault3Flag 

PWM fault 3 flag.

Enumerator
kPWM_CaptureX0DMAEnable 

PWM capture X0 DMA.

kPWM_CaptureX1DMAEnable 

PWM capture X1 DMA.

kPWM_CaptureB0DMAEnable 

PWM capture B0 DMA.

kPWM_CaptureB1DMAEnable 

PWM capture B1 DMA.

kPWM_CaptureA0DMAEnable 

PWM capture A0 DMA.

kPWM_CaptureA1DMAEnable 

PWM capture A1 DMA.

Enumerator
kPWM_DMARequestDisable 

Read DMA requests disabled.

kPWM_DMAWatermarksEnable 

Exceeding a FIFO watermark sets the DMA read request.

kPWM_DMALocalSync 

A local sync (VAL1 matches counter) sets the read DMA request.

kPWM_DMALocalReload 

A local reload (STS[RF] being set) sets the read DMA request.

Enumerator
kPWM_FIFOWatermarksOR 

Selected FIFO watermarks are OR'ed together.

kPWM_FIFOWatermarksAND 

Selected FIFO watermarks are AND'ed together.

enum pwm_mode_t
Enumerator
kPWM_SignedCenterAligned 

Signed center-aligned.

kPWM_CenterAligned 

Unsigned cente-aligned.

kPWM_SignedEdgeAligned 

Signed edge-aligned.

kPWM_EdgeAligned 

Unsigned edge-aligned.

Enumerator
kPWM_HighTrue 

High level represents "on" or "active" state.

kPWM_LowTrue 

Low level represents "on" or "active" state.

Enumerator
kPWM_PwmFaultState0 

Output is forced to logic 0 state prior to consideration of output polarity control.

kPWM_PwmFaultState1 

Output is forced to logic 1 state prior to consideration of output polarity control.

kPWM_PwmFaultState2 

Output is tristated.

kPWM_PwmFaultState3 

Output is tristated.

Enumerator
kPWM_LocalReload 

The local reload signal is used to reload registers.

kPWM_MasterReload 

The master reload signal (from submodule 0) is used to reload.

Enumerator
kPWM_Automatic 

Automatic fault clearing.

kPWM_ManualNormal 

Manual fault clearing with no fault safety mode.

kPWM_ManualSafety 

Manual fault clearing with fault safety mode.

Enumerator
kPWM_Control_Module_0 

Control submodule 0's start/stop,buffer reload operation.

kPWM_Control_Module_1 

Control submodule 1's start/stop,buffer reload operation.

kPWM_Control_Module_2 

Control submodule 2's start/stop,buffer reload operation.

kPWM_Control_Module_3 

Control submodule 3's start/stop,buffer reload operation.

Function Documentation

status_t PWM_Init ( PWM_Type *  base,
pwm_submodule_t  subModule,
const pwm_config_t config 
)
Note
This API should be called at the beginning of the application using the PWM driver.
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
configPointer to user's PWM config structure.
Returns
kStatus_Success means success; else failed.
void PWM_Deinit ( PWM_Type *  base,
pwm_submodule_t  subModule 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to deinitialize
void PWM_GetDefaultConfig ( pwm_config_t config)

The default values are:

* config->enableDebugMode = false;
* config->enableWait = false;
* config->reloadSelect = kPWM_LocalReload;
* config->clockSource = kPWM_BusClock;
* config->prescale = kPWM_Prescale_Divide_1;
* config->initializationControl = kPWM_Initialize_LocalSync;
* config->forceTrigger = kPWM_Force_Local;
* config->reloadFrequency = kPWM_LoadEveryOportunity;
* config->reloadLogic = kPWM_ReloadImmediate;
* config->pairOperation = kPWM_Independent;
*
Parameters
configPointer to user's PWM config structure.
status_t PWM_SetupPwm ( PWM_Type *  base,
pwm_submodule_t  subModule,
const pwm_signal_param_t chnlParams,
uint8_t  numOfChnls,
pwm_mode_t  mode,
uint32_t  pwmFreq_Hz,
uint32_t  srcClock_Hz 
)

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
basePWM peripheral base address
subModulePWM submodule to configure
chnlParamsArray of PWM channel parameters to configure the channel(s)
numOfChnlsNumber of channels to configure, this should be the size of the array passed in. Array size should not be more than 2 as each submodule has 2 pins to output PWM
modePWM operation mode, options available in enumeration pwm_mode_t
pwmFreq_HzPWM signal frequency in Hz
srcClock_HzPWM main counter clock in Hz.
Returns
Returns kStatusFail if there was error setting up the signal; kStatusSuccess otherwise
void PWM_UpdatePwmDutycycle ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmSignal,
pwm_mode_t  currPwmMode,
uint8_t  dutyCyclePercent 
)

The function updates the PWM dutycyle 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
basePWM peripheral base address
subModulePWM submodule to configure
pwmSignalSignal (PWM A or PWM B) to update
currPwmModeThe current PWM mode set during PWM setup
dutyCyclePercentNew PWM pulse width, value should be between 0 to 100 0=inactive signal(0% duty cycle)... 100=active signal (100% duty cycle)
void PWM_UpdatePwmDutycycleHighAccuracy ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmSignal,
pwm_mode_t  currPwmMode,
uint16_t  dutyCycle 
)

The function updates the PWM dutycyle 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
basePWM peripheral base address
subModulePWM submodule to configure
pwmSignalSignal (PWM A or PWM B) to update
currPwmModeThe current PWM mode set during PWM setup
dutyCycleNew PWM pulse width, value should be between 0 to 65535 0=inactive signal(0% duty cycle)... 65535=active signal (100% duty cycle)
void PWM_SetupInputCapture ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmChannel,
const pwm_input_capture_param_t inputCaptureParams 
)

Each PWM submodule has 3 pins that can be configured for use as input capture pins. This function sets up the capture parameters for each pin and enables the pin for input capture operation.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwmChannelChannel in the submodule to setup
inputCaptureParamsParameters passed in to set up the input pin
void PWM_SetupFaultInputFilter ( PWM_Type *  base,
const pwm_fault_input_filter_param_t faultInputFilterParams 
)
Parameters
basePWM peripheral base address
faultInputFilterParamsParameters passed in to set up the fault input filter.
void PWM_SetupFaults ( PWM_Type *  base,
pwm_fault_input_t  faultNum,
const pwm_fault_param_t faultParams 
)

PWM has 4 fault inputs.

Parameters
basePWM peripheral base address
faultNumPWM fault to configure.
faultParamsPointer to the PWM fault config structure
void PWM_FaultDefaultConfig ( pwm_fault_param_t config)

The default values are:

* config->faultClearingMode = kPWM_Automatic;
* config->faultLevel = false;
* config->enableCombinationalPath = true;
* config->recoverMode = kPWM_NoRecovery;
*
Parameters
configPointer to user's PWM fault config structure.
void PWM_SetupForceSignal ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmChannel,
pwm_force_signal_t  mode 
)

The user specifies which channel to configure by supplying the submodule number and whether to modify PWM A or PWM B within that submodule.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwmChannelChannel to configure
modeSignal to output when a FORCE_OUT is triggered
void PWM_EnableInterrupts ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint32_t  mask 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
maskThe interrupts to enable. This is a logical OR of members of the enumeration pwm_interrupt_enable_t
void PWM_DisableInterrupts ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint32_t  mask 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
maskThe interrupts to enable. This is a logical OR of members of the enumeration pwm_interrupt_enable_t
uint32_t PWM_GetEnabledInterrupts ( PWM_Type *  base,
pwm_submodule_t  subModule 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
Returns
The enabled interrupts. This is the logical OR of members of the enumeration pwm_interrupt_enable_t
static void PWM_DMAFIFOWatermarkControl ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_watermark_control_t  pwm_watermark_control 
)
inlinestatic
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwm_watermark_controlPWM FIFO watermark and control
static void PWM_DMACaptureSourceSelect ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_dma_source_select_t  pwm_dma_source_select 
)
inlinestatic
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwm_dma_source_selectPWM capture DMA enable source select
static void PWM_EnableDMACapture ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint16_t  mask,
bool  activate 
)
inlinestatic
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
maskThe DMA to enable or disable. This is a logical OR of members of the enumeration pwm_dma_enable_t
activatetrue: Enable DMA read request; false: Disable DMA read request
static void PWM_EnableDMAWrite ( PWM_Type *  base,
pwm_submodule_t  subModule,
bool  activate 
)
inlinestatic
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
activatetrue: Enable DMA write request; false: Disable DMA write request
uint32_t PWM_GetStatusFlags ( PWM_Type *  base,
pwm_submodule_t  subModule 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
Returns
The status flags. This is the logical OR of members of the enumeration pwm_status_flags_t
void PWM_ClearStatusFlags ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint32_t  mask 
)
Parameters
basePWM peripheral base address
subModulePWM submodule to configure
maskThe status flags to clear. This is a logical OR of members of the enumeration pwm_status_flags_t
static void PWM_StartTimer ( PWM_Type *  base,
uint8_t  subModulesToStart 
)
inlinestatic

Sets the Run bit which enables the clocks to the PWM submodule. This function can start multiple submodules at the same time.

Parameters
basePWM peripheral base address
subModulesToStartPWM submodules to start. This is a logical OR of members of the enumeration pwm_module_control_t
static void PWM_StopTimer ( PWM_Type *  base,
uint8_t  subModulesToStop 
)
inlinestatic

Clears the Run bit which resets the submodule's counter. This function can stop multiple submodules at the same time.

Parameters
basePWM peripheral base address
subModulesToStopPWM submodules to stop. This is a logical OR of members of the enumeration pwm_module_control_t
static void PWM_OutputTriggerEnable ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_value_register_t  valueRegister,
bool  activate 
)
inlinestatic

This function allows the user to enable or disable the PWM trigger. The PWM has 2 triggers. Trigger 0 is activated when the counter matches VAL 0, VAL 2, or VAL 4 register. Trigger 1 is activated when the counter matches VAL 1, VAL 3, or VAL 5 register.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
valueRegisterValue register that will activate the trigger
activatetrue: Enable the trigger; false: Disable the trigger
static void PWM_ActivateOutputTrigger ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint16_t  valueRegisterMask 
)
inlinestatic

This function allows the user to enable one or more (VAL0-5) PWM trigger.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
valueRegisterMaskValue register mask that will activate one or more (VAL0-5) trigger enumeration _pwm_value_register_mask
static void PWM_DeactivateOutputTrigger ( PWM_Type *  base,
pwm_submodule_t  subModule,
uint16_t  valueRegisterMask 
)
inlinestatic

This function allows the user to disables one or more (VAL0-5) PWM trigger.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
valueRegisterMaskValue register mask that will Deactivate one or more (VAL0-5) trigger enumeration _pwm_value_register_mask
static void PWM_SetupSwCtrlOut ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmChannel,
bool  value 
)
inlinestatic

The user specifies which channel to modify by supplying the submodule number and whether to modify PWM A or PWM B within that submodule.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwmChannelChannel to configure
valuetrue: Supply a logic 1, false: Supply a logic 0.
static void PWM_SetPwmLdok ( PWM_Type *  base,
uint8_t  subModulesToUpdate,
bool  value 
)
inlinestatic

Set LDOK bit to load buffered values into CTRL[PRSC] and the INIT, FRACVAL and VAL registers. The values are loaded immediately if kPWM_ReloadImmediate option was choosen during config. Else the values are loaded at the next PWM reload point. This function can issue the load command to multiple submodules at the same time.

Parameters
basePWM peripheral base address
subModulesToUpdatePWM submodules to update with buffered values. This is a logical OR of members of the enumeration pwm_module_control_t
valuetrue: Set LDOK bit for the submodule list; false: Clear LDOK bit
static void PWM_SetPwmFaultState ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmChannel,
pwm_fault_state_t  faultState 
)
inlinestatic

These bits determine the fault state for the PWM_A output in fault conditions and STOP mode. It may also define the output state in WAIT and DEBUG modes depending on the settings of CTRL2[WAITEN] and CTRL2[DBGEN]. This function can update PWM output fault status.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwmChannelChannel to configure
faultStatePWM output fault status
static void PWM_SetupFaultDisableMap ( PWM_Type *  base,
pwm_submodule_t  subModule,
pwm_channels_t  pwmChannel,
pwm_fault_channels_t  pwm_fault_channels,
uint16_t  value 
)
inlinestatic

Each of the four bits of this read/write field is one-to-one associated with the four FAULTx inputs of fault channel 0/1. The PWM output will be turned off if there is a logic 1 on an FAULTx input and a 1 in the corresponding bit of this field. A reset sets all bits in this field.

Parameters
basePWM peripheral base address
subModulePWM submodule to configure
pwmChannelPWM channel to configure
pwm_fault_channelsPWM fault channel to configure
valueFault disable mapping mask value enumeration pwm_fault_disable_t