CMSIS-Driver_PIC32CZ-MC70  
Peripheral Library (PLIB) Documentation
 
Loading...
Searching...
No Matches
PWM Interface

Driver API for PWM (plib_pwm0.h) More...

Data Structures

struct  PWM_INTERRUPT_FLAGS
 PWM interrupt flags, one field per physical interrupt register bank. More...
 

Macros

#define PWM_FAULT_INPUT_COUNT   (8U) /* Fault inputs (width of FMR FPOL/FMOD/FFIL) */
 
#define PWM_STEPPER_PAIR_COUNT   (2U) /* Gray-count channel pairs (SMMR GCEN0/GCEN1) */
 
#define PWM_WP_GROUP_ALL   ((uint32_t)(PWM_WPCR_WPRG_Msk >> PWM_WPCR_WPRG_Pos))
 
#define PWM_CHANNEL_COUNTER_MAX   (0xFFFFU)
 
#define PWM_CHANNEL_0   ((uint32_t)0U)
 
#define PWM_CHANNEL_1   ((uint32_t)1U)
 
#define PWM_CHANNEL_2   ((uint32_t)2U)
 
#define PWM_CHANNEL_3   ((uint32_t)3U)
 

Typedefs

typedef void(* PWM_CALLBACK) (PWM_INTERRUPT_FLAGS int_cause)
 PWM interrupt callback handler type.
 

Functions

bool PWM0_EnableChannel (uint32_t channel)
 Enables (starts) a single PWM0 channel.
 
bool PWM0_DisableChannel (uint32_t channel)
 Disables (stops) a single PWM0 channel.
 
uint32_t PWM0_GetEnabledChannels (void)
 Reads the mask of currently-enabled PWM0 channels.
 
bool PWM0_SetPeriod (uint32_t channel, uint32_t period)
 Sets a PWM0 channel's period (glitch-free while running).
 
uint32_t PWM0_GetPeriod (uint32_t channel)
 Reads a PWM0 channel's active period.
 
bool PWM0_SetDutyCycle (uint32_t channel, uint32_t duty)
 Sets a PWM0 channel's duty cycle (glitch-free while running).
 
uint32_t PWM0_GetDutyCycle (uint32_t channel)
 Reads a PWM0 channel's active duty cycle.
 
uint32_t PWM0_GetCounter (uint32_t channel)
 Reads a PWM0 channel's live counter value.
 
bool PWM0_SetChannelClock (uint32_t channel, uint32_t source)
 Selects a PWM0 channel's input clock source.
 
bool PWM0_SetChannelAlignment (uint32_t channel, uint32_t alignment)
 Selects a PWM0 channel's waveform alignment.
 
bool PWM0_SetChannelPolarity (uint32_t channel, uint32_t polarity)
 Selects a PWM0 channel's output polarity (glitch-free while running).
 
bool PWM0_SetCounterEventSelection (uint32_t channel, uint32_t event)
 Selects when a PWM0 channel generates its counter (period) event.
 
bool PWM0_SetUpdateSelection (uint32_t channel, uint32_t selection)
 Selects a PWM0 channel's synchronous update timing.
 
bool PWM0_SetDisabledPolarity (uint32_t channel, bool inverted)
 Inverts a PWM0 channel's disabled-state output level.
 
bool PWM0_SetCounterTriggerSelection (uint32_t channel, uint32_t selection)
 Selects a PWM0 channel's timer-counter trigger source.
 
bool PWM0_ConfigureClockA (uint32_t prescaler, uint32_t divider)
 Configures the CLKA linear clock generator (source/prescaler/divider).
 
bool PWM0_ConfigureClockB (uint32_t prescaler, uint32_t divider)
 Configures the CLKB linear clock generator (source/prescaler/divider).
 
bool PWM0_SetDeadTime (uint32_t channel, uint16_t high, uint16_t low)
 Sets a PWM0 channel's dead-time (glitch-free while running).
 
bool PWM0_EnableDeadTime (uint32_t channel, bool invert_high, bool invert_low)
 Enables a PWM0 channel's dead-time generator.
 
bool PWM0_DisableDeadTime (uint32_t channel)
 Disables a PWM0 channel's dead-time generator.
 
bool PWM0_EnablePushPull (uint32_t channel)
 Enables push-pull output mode on a PWM0 channel.
 
bool PWM0_DisablePushPull (uint32_t channel)
 Disables push-pull output mode on a PWM0 channel.
 
bool PWM0_EnableOutputOverride (uint32_t channel, bool pwmh_level, bool pwml_level)
 Forces a PWM0 channel's PWMH/PWML outputs to fixed levels.
 
bool PWM0_GetOutputOverrideValues (uint32_t channel, bool *pwmh_level, bool *pwml_level)
 Reads the forced output levels programmed for a PWM0 channel.
 
bool PWM0_OutputOverrideIsEnabled (uint32_t channel, bool *pwmh_active, bool *pwml_active)
 Reads whether output override is currently active on a PWM0 channel.
 
bool PWM0_DisableOutputOverride (uint32_t channel)
 Releases the output override on a PWM0 channel.
 
bool PWM0_EnableSyncChannel (uint32_t channel)
 Adds a channel to the PWM0 synchronous group (shares channel 0's counter).
 
bool PWM0_DisableSyncChannel (uint32_t channel)
 Removes a channel from the PWM0 synchronous group.
 
bool PWM0_SetSyncUpdateMode (uint32_t mode)
 Selects the synchronous-channels update method.
 
bool PWM0_SetSyncUpdatePeriod (uint32_t update_period)
 Sets the automatic update period for the synchronous channels.
 
void PWM0_TriggerSyncUpdate (void)
 Triggers a synchronous update of the double-buffered registers.
 
bool PWM0_SetCompareValue (uint32_t unit, uint32_t value)
 Sets a PWM0 comparison unit's value (glitch-free while running).
 
bool PWM0_ConfigureCompare (uint32_t unit, uint32_t value_mode, uint32_t trigger, uint32_t period, uint32_t update_period)
 Configures a PWM0 comparison unit's mode, trigger and periodicity.
 
bool PWM0_EnableCompare (uint32_t unit)
 Enables a PWM0 comparison unit.
 
bool PWM0_DisableCompare (uint32_t unit)
 Disables a PWM0 comparison unit.
 
bool PWM0_ConfigureEventLine (uint32_t line, uint32_t compare_mask)
 Selects which comparison units drive a PWM0 event line.
 
bool PWM0_ConfigureFault (uint32_t fault, bool polarity, bool activation_mode, bool filter_enable)
 Configures one PWM0 fault input's polarity, activation mode and filter.
 
bool PWM0_EnableFaultProtection (uint32_t channel, uint32_t fault_mask)
 Selects which fault inputs trip fault protection on a PWM0 channel.
 
bool PWM0_DisableFaultProtection (uint32_t channel, uint32_t fault_mask)
 Clears the selected fault inputs from tripping fault protection on a PWM0 channel, leaving the other fault inputs' enable state unchanged.
 
bool PWM0_SetFaultOutputValues (uint32_t channel, bool pwmh_level, bool pwml_level, bool pwmh_high_z, bool pwml_high_z)
 Sets the forced output levels for a PWM0 channel during a fault.
 
uint32_t PWM0_GetFaultStatus (void)
 Reads the PWM0 fault status register.
 
void PWM0_ClearFault (uint32_t fault_mask)
 Clears latched PWM0 fault status.
 
bool PWM0_ConfigureExternalTrigger (uint32_t channel, uint32_t source, uint32_t mode, uint32_t edge, uint32_t filter)
 Configures the external trigger source/mode/edge/filter for PWM0 channel 1 or 2.
 
bool PWM0_ConfigureLeadingEdgeBlanking (uint32_t channel, uint32_t delay, uint32_t edges)
 Configures leading-edge blanking for PWM0 channel 1 or 2.
 
bool PWM0_EnableRecoverableFault (uint32_t channel)
 Enables recoverable fault on PWM0 channel 1 or 2.
 
bool PWM0_DisableRecoverableFault (uint32_t channel)
 Disables recoverable fault on PWM0 channel 1 or 2.
 
uint32_t PWM0_GetMaxTriggerCount (uint32_t channel)
 Reads (and clears) the peak counter value captured by the external trigger on PWM0 channel 1 or 2.
 
bool PWM0_EnableStepperMode (uint32_t pair, bool count_down)
 Enables gray-code stepper mode on a PWM0 channel pair.
 
bool PWM0_DisableStepperMode (uint32_t pair)
 Disables gray-code stepper mode on a PWM0 channel pair.
 
bool PWM0_ConfigureSpreadSpectrum (uint32_t range, uint32_t mode)
 Configures spread-spectrum modulation of the channel-0 period.
 
bool PWM0_SetSpreadSpectrumUpdate (uint32_t range)
 Updates the spread-spectrum limit while channel 0 is running.
 
bool PWM0_WriteDMADutyCycle (uint32_t value)
 Writes a duty-cycle value to the PWM0 DMA holding register.
 
bool PWM0_ConfigureDMARequest (bool on_comparison, uint32_t compare_select)
 Selects the DMA transfer-request source for the synchronous channels.
 
void PWM0_EnableInterrupt (PWM_INTERRUPT_FLAGS interrupt_mask)
 Enables one or more PWM0 interrupt sources.
 
void PWM0_DisableInterrupt (PWM_INTERRUPT_FLAGS interrupt_mask)
 Disables one or more PWM0 interrupt sources.
 
PWM_INTERRUPT_FLAGS PWM0_GetInterruptMask (void)
 Returns the mask of currently-enabled PWM0 interrupt sources.
 
PWM_INTERRUPT_FLAGS PWM0_GetInterruptStatus (void)
 Reads and clears the pending PWM0 interrupt status flags.
 
void PWM0_SetCallbackHandler (PWM_CALLBACK callback)
 Registers a function to be called from the PWM0 interrupt handler.
 
bool PWM0_EnableWriteProtection (uint32_t groups, bool hardware)
 Enables write protection on the selected PWM0 register groups.
 
bool PWM0_DisableWriteProtection (uint32_t groups)
 Disables software write protection on the selected PWM0 register groups.
 
uint32_t PWM0_GetWriteProtectionStatus (void)
 Reads the PWM0 write-protection status register.
 

Variables

uint32_t PWM_INTERRUPT_FLAGS::channel_events
 Bank 1 flags: channel period (CHIDx) and fault (FCHIDx) sources.
 
uint32_t PWM_INTERRUPT_FLAGS::compare_events
 Bank 2 flags: sync-update (WRDY/UNRE) and comparison (CMPMx/CMPUx) sources.
 

Description

Driver API for PWM (plib_pwm0.h)

Usage Example

The following example demonstrates typical usage of the PWM peripheral:

/*******************************************************************************
* @file configure_pwm0.c
* @brief Pulse Width Modulation (PWM) configuration template
*
* @details
* The PWM controller on the PIC32CZ-CA70 / MC70 generates output pulses on four
* independent channels. Each channel runs a 16-bit counter from a selectable
* clock; the counter's top value (CPRD) sets the period/frequency and the
* compare value (CDTY) sets the duty cycle.
*
* Key concepts:
* - Clock: each channel picks one of 13 sources (MCK, MCK/2..MCK/1024, CLKA,
* CLKB). This template uses MCK/8.
* - Period / duty: for a left-aligned channel, f_pwm = f_clk / CPRD, and the
* high-time fraction is (CPRD - CDTY) / CPRD.
* - Glitch-free updates: while a channel is running, writing the period/duty
* setters updates shadow registers that load at the next period boundary, so
* the waveform never glitches.
* - Interrupts: the channel can raise a period-complete interrupt; a single
* callback receives a cause mask identifying which events fired.
*
* In this template:
* - PWM0 channel 0 is clocked from MCK/8, left-aligned, low polarity.
* - CPRD = 600 and CDTY = 420 give ~30% duty. With MCK = 96 MHz (MCK/8 = 12 MHz)
* this is a 20 kHz output; adjust CPRD/CDTY for your MCK and target frequency.
* - The period-complete interrupt source is enabled and a user callback is
* registered; enabling the NVIC line is left to the caller (application
* code decides when interrupts start firing, not the peripheral template).
* - The channel is started last, once configuration is complete.
******************************************************************************/
#include "plib_pwm0.h"
#include <pic32c.h>
#include <stdint.h>
#include <stdbool.h>
volatile bool pwm_period_elapsed = false;
volatile uint32_t pwm_period_count = 0U;
static void PWM_EventCallback(PWM_INTERRUPT_FLAGS int_cause)
{
if ((int_cause.channel_events & PWM_IER1_CHID0_Msk) != 0U)
{
pwm_period_elapsed = true;
pwm_period_count++;
}
}
int32_t configure_pwm0(void)
{
const uint32_t pwm_period = 600U; /* 12 MHz / 600 = 20 kHz */
const uint32_t pwm_duty_cycle = 420U; /* (600 - 420)/600 = 30% high time */
/* Put the peripheral in a known state: unlock software write protection,
* stop every channel, silence both interrupt banks, clear latched faults,
* discard pending status, and reset the driver callback. */
PWM0_DisableInterrupt((PWM_INTERRUPT_FLAGS){ .channel_events = 0xFFFFFFFFU,
.compare_events = 0xFFFFFFFFU });
PWM0_ClearFault(PWM_FCR_FCLR_Msk);
/* Configure channel 0 while it is stopped. */
(void)PWM0_SetChannelClock(PWM_CHANNEL_0, PWM_CMR_CPRE_MCK_DIV_8);
(void)PWM0_SetChannelAlignment(PWM_CHANNEL_0, PWM_CMR_CALG_LEFT_ALIGNED);
(void)PWM0_SetChannelPolarity(PWM_CHANNEL_0, PWM_CMR_CPOL_LOW_POLARITY);
/* Program the period (frequency) and duty cycle. */
(void)PWM0_SetPeriod(PWM_CHANNEL_0, pwm_period);
(void)PWM0_SetDutyCycle(PWM_CHANNEL_0, pwm_duty_cycle);
/* Hand the callback to the PLIB before enabling interrupts. */
PWM0_SetCallbackHandler(&PWM_EventCallback);
/* Fire an interrupt at the end of every channel-0 period. */
PWM0_EnableInterrupt((PWM_INTERRUPT_FLAGS){ .channel_events = PWM_IER1_CHID0_Msk, .compare_events = 0U });
/* Start the channel. NVIC enablement is the caller's responsibility. */
return 0;
}
bool PWM0_SetChannelAlignment(uint32_t channel, uint32_t alignment)
Selects a PWM0 channel's waveform alignment.
uint32_t channel_events
Bank 1 flags: channel period (CHIDx) and fault (FCHIDx) sources.
Definition plib_pwm_common.h:51
#define PWM_CHANNEL_1
Definition plib_pwm_common.h:78
#define PWM_WP_GROUP_ALL
Definition plib_pwm_common.h:69
bool PWM0_SetChannelPolarity(uint32_t channel, uint32_t polarity)
Selects a PWM0 channel's output polarity (glitch-free while running).
void PWM0_DisableInterrupt(PWM_INTERRUPT_FLAGS interrupt_mask)
Disables one or more PWM0 interrupt sources.
bool PWM0_SetChannelClock(uint32_t channel, uint32_t source)
Selects a PWM0 channel's input clock source.
bool PWM0_SetPeriod(uint32_t channel, uint32_t period)
Sets a PWM0 channel's period (glitch-free while running).
bool PWM0_SetDutyCycle(uint32_t channel, uint32_t duty)
Sets a PWM0 channel's duty cycle (glitch-free while running).
void PWM0_SetCallbackHandler(PWM_CALLBACK callback)
Registers a function to be called from the PWM0 interrupt handler.
#define PWM_CHANNEL_2
Definition plib_pwm_common.h:79
bool PWM0_DisableWriteProtection(uint32_t groups)
Disables software write protection on the selected PWM0 register groups.
#define PWM_CHANNEL_0
Definition plib_pwm_common.h:77
PWM_INTERRUPT_FLAGS PWM0_GetInterruptStatus(void)
Reads and clears the pending PWM0 interrupt status flags.
bool PWM0_DisableChannel(uint32_t channel)
Disables (stops) a single PWM0 channel.
void PWM0_EnableInterrupt(PWM_INTERRUPT_FLAGS interrupt_mask)
Enables one or more PWM0 interrupt sources.
void PWM0_ClearFault(uint32_t fault_mask)
Clears latched PWM0 fault status.
bool PWM0_EnableChannel(uint32_t channel)
Enables (starts) a single PWM0 channel.
#define PWM_CHANNEL_3
Definition plib_pwm_common.h:80
PWM interrupt flags, one field per physical interrupt register bank.
Definition plib_pwm_common.h:49

Macro Definition Documentation

◆ PWM_CHANNEL_0

#define PWM_CHANNEL_0   ((uint32_t)0U)

◆ PWM_CHANNEL_1

#define PWM_CHANNEL_1   ((uint32_t)1U)

◆ PWM_CHANNEL_2

#define PWM_CHANNEL_2   ((uint32_t)2U)

◆ PWM_CHANNEL_3

#define PWM_CHANNEL_3   ((uint32_t)3U)

◆ PWM_CHANNEL_COUNTER_MAX

#define PWM_CHANNEL_COUNTER_MAX   (0xFFFFU)

◆ PWM_FAULT_INPUT_COUNT

#define PWM_FAULT_INPUT_COUNT   (8U) /* Fault inputs (width of FMR FPOL/FMOD/FFIL) */

◆ PWM_STEPPER_PAIR_COUNT

#define PWM_STEPPER_PAIR_COUNT   (2U) /* Gray-count channel pairs (SMMR GCEN0/GCEN1) */

◆ PWM_WP_GROUP_ALL

#define PWM_WP_GROUP_ALL   ((uint32_t)(PWM_WPCR_WPRG_Msk >> PWM_WPCR_WPRG_Pos))

Typedef Documentation

◆ PWM_CALLBACK

typedef void(* PWM_CALLBACK) (PWM_INTERRUPT_FLAGS int_cause)

PWM interrupt callback handler type.

Parameters
int_causePWM interrupt-cause flags that triggered the callback.

Function Documentation

◆ PWM0_ClearFault()

void PWM0_ClearFault ( uint32_t fault_mask)

Clears latched PWM0 fault status.

Parameters
fault_maskBitmask of fault inputs to clear (bit i clears fault i, 0..7).
Returns
None

◆ PWM0_ConfigureClockA()

bool PWM0_ConfigureClockA ( uint32_t prescaler,
uint32_t divider )

Configures the CLKA linear clock generator (source/prescaler/divider).

Parameters
prescalerOne of the PWM_CLK_PREA_* device macros.
dividerLinear divide factor (0..255); 0 turns CLKA off.
Returns
true on success; false if divider exceeds 255.

◆ PWM0_ConfigureClockB()

bool PWM0_ConfigureClockB ( uint32_t prescaler,
uint32_t divider )

Configures the CLKB linear clock generator (source/prescaler/divider).

Parameters
prescalerOne of the PWM_CLK_PREB_* device macros.
dividerLinear divide factor (0..255); 0 turns CLKB off.
Returns
true on success; false if divider exceeds 255.

◆ PWM0_ConfigureCompare()

bool PWM0_ConfigureCompare ( uint32_t unit,
uint32_t value_mode,
uint32_t trigger,
uint32_t period,
uint32_t update_period )

Configures a PWM0 comparison unit's mode, trigger and periodicity.

Parameters
unitComparison-unit index (0..7).
value_modePWM_CMPV_CVM_COMPARE_AT_INCREMENT or _AT_DECREMENT.
triggerComparison trigger value CTR (0..15).
periodComparison period CPR (0..15); matches every CPR+1 periods.
update_periodComparison update period CUPR (0..15).
Returns
true on success; false if unit, trigger, period, or update_period is out of range.

◆ PWM0_ConfigureDMARequest()

bool PWM0_ConfigureDMARequest ( bool on_comparison,
uint32_t compare_select )

Selects the DMA transfer-request source for the synchronous channels.

Note
Channel 0 must be stopped.
Parameters
on_comparisontrue requests on a comparison match; false on the synchronous-update event.
compare_selectComparison unit used when on_comparison is true (0..7).
Returns
true on success; false if channel 0 is running or compare_select is out of range.

◆ PWM0_ConfigureEventLine()

bool PWM0_ConfigureEventLine ( uint32_t line,
uint32_t compare_mask )

Selects which comparison units drive a PWM0 event line.

Parameters
lineEvent-line index (0..1).
compare_maskBitmask of comparison units (bit i selects unit i, 0..7).
Returns
true on success; false if line is out of range.

◆ PWM0_ConfigureExternalTrigger()

bool PWM0_ConfigureExternalTrigger ( uint32_t channel,
uint32_t source,
uint32_t mode,
uint32_t edge,
uint32_t filter )

Configures the external trigger source/mode/edge/filter for PWM0 channel 1 or 2.

Parameters
channelChannel index (1 or 2 only).
sourceTrigger source (PWM_ETRG1_TRGSRC_Msk selects the alternate source).
modePWM_ETRG1_TRGMODE_OFF/MODE1/MODE2/MODE3.
edgePWM_ETRG1_TRGEDGE_FALLING_ZERO or PWM_ETRG1_TRGEDGE_RISING_ONE.
filterPWM_ETRG1_TRGFILT_Msk to filter the input, else 0.
Returns
true on success; false if channel is not 1 or 2.

◆ PWM0_ConfigureFault()

bool PWM0_ConfigureFault ( uint32_t fault,
bool polarity,
bool activation_mode,
bool filter_enable )

Configures one PWM0 fault input's polarity, activation mode and filter.

Parameters
faultFault input index (0..7).
polaritytrue sets the fault-active polarity.
activation_modetrue keeps the fault latched until cleared.
filter_enabletrue enables glitch filtering on the input.
Returns
true on success; false if fault is out of range.

◆ PWM0_ConfigureLeadingEdgeBlanking()

bool PWM0_ConfigureLeadingEdgeBlanking ( uint32_t channel,
uint32_t delay,
uint32_t edges )

Configures leading-edge blanking for PWM0 channel 1 or 2.

Parameters
channelChannel index (1 or 2 only).
delayBlanking delay in peripheral-clock cycles (0..127).
edgesBitmask of edges to blank (PWM_LEBR1_PWMHREN/HFEN/LREN/LFEN_Msk).
Returns
true on success; false if channel is not 1 or 2 or delay > 127.

◆ PWM0_ConfigureSpreadSpectrum()

bool PWM0_ConfigureSpreadSpectrum ( uint32_t range,
uint32_t mode )

Configures spread-spectrum modulation of the channel-0 period.

Note
Channel 0 must be stopped.
Parameters
rangeSpread-spectrum limit value (0..0xFFFF).
modePWM_SSPR_SPRDM_Msk for random mode, or 0 for triangular mode.
Returns
true on success; false if channel 0 is running or range is out of range.

◆ PWM0_DisableChannel()

bool PWM0_DisableChannel ( uint32_t channel)

Disables (stops) a single PWM0 channel.

Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range.

◆ PWM0_DisableCompare()

bool PWM0_DisableCompare ( uint32_t unit)

Disables a PWM0 comparison unit.

Parameters
unitComparison-unit index (0..7).
Returns
true on success; false if unit is out of range.

◆ PWM0_DisableDeadTime()

bool PWM0_DisableDeadTime ( uint32_t channel)

Disables a PWM0 channel's dead-time generator.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range or running.

◆ PWM0_DisableFaultProtection()

bool PWM0_DisableFaultProtection ( uint32_t channel,
uint32_t fault_mask )

Clears the selected fault inputs from tripping fault protection on a PWM0 channel, leaving the other fault inputs' enable state unchanged.

Parameters
channelChannel index (0..3).
fault_maskBitmask of fault inputs to disable (bit i disables fault input i, 0..7).
Returns
true on success; false if channel is out of range.

◆ PWM0_DisableInterrupt()

void PWM0_DisableInterrupt ( PWM_INTERRUPT_FLAGS interrupt_mask)

Disables one or more PWM0 interrupt sources.

Parameters
interrupt_maskFlags to disable (see PWM_INT_* macros).
Returns
None

◆ PWM0_DisableOutputOverride()

bool PWM0_DisableOutputOverride ( uint32_t channel)

Releases the output override on a PWM0 channel.

Note
Shares the same one-write-per-period OSSUPD/OSCUPD restriction as PWM0_EnableOutputOverride() while the channel is running.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range.

◆ PWM0_DisablePushPull()

bool PWM0_DisablePushPull ( uint32_t channel)

Disables push-pull output mode on a PWM0 channel.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range or running.

◆ PWM0_DisableRecoverableFault()

bool PWM0_DisableRecoverableFault ( uint32_t channel)

Disables recoverable fault on PWM0 channel 1 or 2.

Parameters
channelChannel index (1 or 2 only).
Returns
true on success; false if channel is not 1 or 2.

◆ PWM0_DisableStepperMode()

bool PWM0_DisableStepperMode ( uint32_t pair)

Disables gray-code stepper mode on a PWM0 channel pair.

Parameters
pairChannel-pair index (0 or 1).
Returns
true on success; false if pair is out of range.

◆ PWM0_DisableSyncChannel()

bool PWM0_DisableSyncChannel ( uint32_t channel)

Removes a channel from the PWM0 synchronous group.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range or running.

◆ PWM0_DisableWriteProtection()

bool PWM0_DisableWriteProtection ( uint32_t groups)

Disables software write protection on the selected PWM0 register groups.

Note
Hardware write protection can only be cleared by a hardware reset.
Parameters
groupsBitmask of register groups to unprotect (6 groups).
Returns
true on success; false if groups has bits set outside the 6 defined groups.

◆ PWM0_EnableChannel()

bool PWM0_EnableChannel ( uint32_t channel)

Enables (starts) a single PWM0 channel.

Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range.

◆ PWM0_EnableCompare()

bool PWM0_EnableCompare ( uint32_t unit)

Enables a PWM0 comparison unit.

Parameters
unitComparison-unit index (0..7).
Returns
true on success; false if unit is out of range.

◆ PWM0_EnableDeadTime()

bool PWM0_EnableDeadTime ( uint32_t channel,
bool invert_high,
bool invert_low )

Enables a PWM0 channel's dead-time generator.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
invert_hightrue inverts the PWMH dead-time output.
invert_lowtrue inverts the PWML dead-time output.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_EnableFaultProtection()

bool PWM0_EnableFaultProtection ( uint32_t channel,
uint32_t fault_mask )

Selects which fault inputs trip fault protection on a PWM0 channel.

Parameters
channelChannel index (0..3).
fault_maskBitmask of fault inputs (bit i enables fault input i, 0..7).
Returns
true on success; false if channel is out of range.

◆ PWM0_EnableInterrupt()

void PWM0_EnableInterrupt ( PWM_INTERRUPT_FLAGS interrupt_mask)

Enables one or more PWM0 interrupt sources.

Parameters
interrupt_maskFlags to enable (see PWM_INT_* macros).
Returns
None

◆ PWM0_EnableOutputOverride()

bool PWM0_EnableOutputOverride ( uint32_t channel,
bool pwmh_level,
bool pwml_level )

Forces a PWM0 channel's PWMH/PWML outputs to fixed levels.

Note
While the channel is running, this and PWM0_DisableOutputOverride() both go through the shared OSSUPD/OSCUPD shadow registers, and the hardware allows only one such write per PWM period across all channels; a second call within the same period overwrites the first before it latches. Space calls at least one period apart, or call while stopped.
Parameters
channelChannel index (0..3).
pwmh_levelForced level for PWMH (true = high).
pwml_levelForced level for PWML (true = high).
Returns
true on success; false if channel is out of range.

◆ PWM0_EnablePushPull()

bool PWM0_EnablePushPull ( uint32_t channel)

Enables push-pull output mode on a PWM0 channel.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range or running.

◆ PWM0_EnableRecoverableFault()

bool PWM0_EnableRecoverableFault ( uint32_t channel)

Enables recoverable fault on PWM0 channel 1 or 2.

Parameters
channelChannel index (1 or 2 only).
Returns
true on success; false if channel is not 1 or 2.

◆ PWM0_EnableStepperMode()

bool PWM0_EnableStepperMode ( uint32_t pair,
bool count_down )

Enables gray-code stepper mode on a PWM0 channel pair.

Parameters
pairChannel-pair index (0 = channels 0/1, 1 = channels 2/3).
count_downtrue counts down; false counts up.
Returns
true on success; false if pair is out of range.

◆ PWM0_EnableSyncChannel()

bool PWM0_EnableSyncChannel ( uint32_t channel)

Adds a channel to the PWM0 synchronous group (shares channel 0's counter).

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
Returns
true on success; false if channel is out of range or running.

◆ PWM0_EnableWriteProtection()

bool PWM0_EnableWriteProtection ( uint32_t groups,
bool hardware )

Enables write protection on the selected PWM0 register groups.

Parameters
groupsBitmask of register groups to protect (6 groups).
hardwaretrue for hardware protection (cleared only by a hardware reset); false for software protection.
Returns
true on success; false if groups has bits set outside the 6 defined groups.

◆ PWM0_GetCounter()

uint32_t PWM0_GetCounter ( uint32_t channel)

Reads a PWM0 channel's live counter value.

Parameters
channelChannel index (0..3).
Returns
Counter value, or 0 if channel is out of range.

◆ PWM0_GetDutyCycle()

uint32_t PWM0_GetDutyCycle ( uint32_t channel)

Reads a PWM0 channel's active duty cycle.

Parameters
channelChannel index (0..3).
Returns
Duty value, or 0 if channel is out of range.

◆ PWM0_GetEnabledChannels()

uint32_t PWM0_GetEnabledChannels ( void )

Reads the mask of currently-enabled PWM0 channels.

Returns
Bitmask of enabled channels (bit i set means channel i runs).

◆ PWM0_GetFaultStatus()

uint32_t PWM0_GetFaultStatus ( void )

Reads the PWM0 fault status register.

Returns
Fault status: current fault-input values (bits 7:0) and latched fault status (bits 15:8).

◆ PWM0_GetInterruptMask()

PWM_INTERRUPT_FLAGS PWM0_GetInterruptMask ( void )

Returns the mask of currently-enabled PWM0 interrupt sources.

Returns
Interrupt-enable flags, one field per register bank.

◆ PWM0_GetInterruptStatus()

PWM_INTERRUPT_FLAGS PWM0_GetInterruptStatus ( void )

Reads and clears the pending PWM0 interrupt status flags.

Note
For polling only; clears the same flags an interrupt handler would see.
Returns
Pending-status flags, one field per register bank.

◆ PWM0_GetMaxTriggerCount()

uint32_t PWM0_GetMaxTriggerCount ( uint32_t channel)

Reads (and clears) the peak counter value captured by the external trigger on PWM0 channel 1 or 2.

Note
Reading clears MAXCNT; PWM0_ConfigureExternalTrigger() on the same channel preserves it instead (writes the same bits back).
Parameters
channelChannel index (1 or 2 only).
Returns
Captured value, or 0 if channel is not 1 or 2.

◆ PWM0_GetOutputOverrideValues()

bool PWM0_GetOutputOverrideValues ( uint32_t channel,
bool * pwmh_level,
bool * pwml_level )

Reads the forced output levels programmed for a PWM0 channel.

Note
Reflects the level PWM_OOV would force, regardless of whether the override is currently active; use PWM0_OutputOverrideIsEnabled() for that.
Parameters
channelChannel index (0..3).
pwmh_levelSet to the forced level for PWMH (true = high).
pwml_levelSet to the forced level for PWML (true = high).
Returns
true on success; false if channel is out of range or either output pointer is NULL.

◆ PWM0_GetPeriod()

uint32_t PWM0_GetPeriod ( uint32_t channel)

Reads a PWM0 channel's active period.

Parameters
channelChannel index (0..3).
Returns
Period value, or 0 if channel is out of range.

◆ PWM0_GetWriteProtectionStatus()

uint32_t PWM0_GetWriteProtectionStatus ( void )

Reads the PWM0 write-protection status register.

Note
Reading also clears the write-protection violation status.
Returns
Violation flag/source and the active SW/HW protection group flags.

◆ PWM0_OutputOverrideIsEnabled()

bool PWM0_OutputOverrideIsEnabled ( uint32_t channel,
bool * pwmh_active,
bool * pwml_active )

Reads whether output override is currently active on a PWM0 channel.

Parameters
channelChannel index (0..3).
pwmh_activeSet to true if PWMH is currently overridden.
pwml_activeSet to true if PWML is currently overridden.
Returns
true on success; false if channel is out of range or either output pointer is NULL.

◆ PWM0_SetCallbackHandler()

void PWM0_SetCallbackHandler ( PWM_CALLBACK callback)

Registers a function to be called from the PWM0 interrupt handler.

Parameters
callbackCallback pointer, or NULL to unregister.
Returns
None

◆ PWM0_SetChannelAlignment()

bool PWM0_SetChannelAlignment ( uint32_t channel,
uint32_t alignment )

Selects a PWM0 channel's waveform alignment.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
alignmentPWM_CMR_CALG_LEFT_ALIGNED or PWM_CMR_CALG_CENTER_ALIGNED.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_SetChannelClock()

bool PWM0_SetChannelClock ( uint32_t channel,
uint32_t source )

Selects a PWM0 channel's input clock source.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
sourceOne of the PWM_CMR_CPRE_* device macros.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_SetChannelPolarity()

bool PWM0_SetChannelPolarity ( uint32_t channel,
uint32_t polarity )

Selects a PWM0 channel's output polarity (glitch-free while running).

Parameters
channelChannel index (0..3).
polarityPWM_CMR_CPOL_LOW_POLARITY or PWM_CMR_CPOL_HIGH_POLARITY.
Returns
true on success; false if channel is out of range.

◆ PWM0_SetCompareValue()

bool PWM0_SetCompareValue ( uint32_t unit,
uint32_t value )

Sets a PWM0 comparison unit's value (glitch-free while running).

Parameters
unitComparison-unit index (0..7).
valueComparison value against the channel-0 counter (0..0xFFFF).
Returns
true on success; false if unit or value is out of range.

◆ PWM0_SetCounterEventSelection()

bool PWM0_SetCounterEventSelection ( uint32_t channel,
uint32_t event )

Selects when a PWM0 channel generates its counter (period) event.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
eventPWM_CMR_CES_SINGLE_EVENT or PWM_CMR_CES_DOUBLE_EVENT.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_SetCounterTriggerSelection()

bool PWM0_SetCounterTriggerSelection ( uint32_t channel,
uint32_t selection )

Selects a PWM0 channel's timer-counter trigger source.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
selection0 or PWM_CMR_TCTS_Msk.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_SetDeadTime()

bool PWM0_SetDeadTime ( uint32_t channel,
uint16_t high,
uint16_t low )

Sets a PWM0 channel's dead-time (glitch-free while running).

Parameters
channelChannel index (0..3).
highDead-time for PWMH, in channel-clock ticks (0..65535).
lowDead-time for PWML, in channel-clock ticks (0..65535).
Returns
true on success; false if channel is out of range.

◆ PWM0_SetDisabledPolarity()

bool PWM0_SetDisabledPolarity ( uint32_t channel,
bool inverted )

Inverts a PWM0 channel's disabled-state output level.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
invertedtrue inverts the level driven while disabled.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_SetDutyCycle()

bool PWM0_SetDutyCycle ( uint32_t channel,
uint32_t duty )

Sets a PWM0 channel's duty cycle (glitch-free while running).

Parameters
channelChannel index (0..3).
dutyDuty value in channel-clock ticks (0..0xFFFF).
Returns
true on success; false if channel or duty is out of range.

◆ PWM0_SetFaultOutputValues()

bool PWM0_SetFaultOutputValues ( uint32_t channel,
bool pwmh_level,
bool pwml_level,
bool pwmh_high_z,
bool pwml_high_z )

Sets the forced output levels for a PWM0 channel during a fault.

Parameters
channelChannel index (0..3).
pwmh_levelForced level for PWMH when not high-impedance.
pwml_levelForced level for PWML when not high-impedance.
pwmh_high_ztrue drives PWMH to high-impedance on fault.
pwml_high_ztrue drives PWML to high-impedance on fault.
Returns
true on success; false if channel is out of range.

◆ PWM0_SetPeriod()

bool PWM0_SetPeriod ( uint32_t channel,
uint32_t period )

Sets a PWM0 channel's period (glitch-free while running).

Parameters
channelChannel index (0..3).
periodPeriod in channel-clock ticks (0..0xFFFF).
Returns
true on success; false if channel or period is out of range.

◆ PWM0_SetSpreadSpectrumUpdate()

bool PWM0_SetSpreadSpectrumUpdate ( uint32_t range)

Updates the spread-spectrum limit while channel 0 is running.

Parameters
rangeSpread-spectrum limit value (0..0xFFFF).
Returns
true on success; false if range exceeds the 16-bit field.

◆ PWM0_SetSyncUpdateMode()

bool PWM0_SetSyncUpdateMode ( uint32_t mode)

Selects the synchronous-channels update method.

Parameters
modePWM_SCM_UPDM_MODE0, MODE1 or MODE2.
Returns
true on success; false if mode is invalid.

◆ PWM0_SetSyncUpdatePeriod()

bool PWM0_SetSyncUpdatePeriod ( uint32_t update_period)

Sets the automatic update period for the synchronous channels.

Parameters
update_periodUpdate period, in PWM periods (0..15).
Returns
true on success; false if update_period exceeds 15.

◆ PWM0_SetUpdateSelection()

bool PWM0_SetUpdateSelection ( uint32_t channel,
uint32_t selection )

Selects a PWM0 channel's synchronous update timing.

Note
Channel must be stopped.
Parameters
channelChannel index (0..3).
selectionPWM_CMR_UPDS_UPDATE_AT_PERIOD or PWM_CMR_UPDS_UPDATE_AT_HALF_PERIOD.
Returns
true on success; false if channel is out of range or running.

◆ PWM0_TriggerSyncUpdate()

void PWM0_TriggerSyncUpdate ( void )

Triggers a synchronous update of the double-buffered registers.

Returns
None

◆ PWM0_WriteDMADutyCycle()

bool PWM0_WriteDMADutyCycle ( uint32_t value)

Writes a duty-cycle value to the PWM0 DMA holding register.

Parameters
valueDuty-cycle value (0..0xFFFF).
Returns
true on success; false if value exceeds the 16-bit field.

Variable Documentation

◆ channel_events

uint32_t PWM_INTERRUPT_FLAGS::channel_events

Bank 1 flags: channel period (CHIDx) and fault (FCHIDx) sources.

◆ compare_events

uint32_t PWM_INTERRUPT_FLAGS::compare_events

Bank 2 flags: sync-update (WRDY/UNRE) and comparison (CMPMx/CMPUx) sources.