| Input | Type | Condition | Description |
|---|---|---|---|
| Period | uint16/uint32 | Variable period mode | PWM period value. Scalar for common time base, vector for independent time bases |
| DutyCycle [1..N] | uint16/uint32 | Per enabled PWM | Duty cycle value. Can be [single] or [val1 val2] for asymmetric mode |
| PhaseShift [1..N] | uint16/uint32 | If enabled | Phase shift value for interleaved operation |
| TRIG1..3 [1..N] | uint16/uint32 | Dynamic trigger | Runtime trigger point modification |
| DeadTimeH/L [1..N] | uint16 | Dynamic dead-time | Runtime dead-time adjustment |
| Fault_SW | boolean | If software fault enabled | Software-triggered fault input |
| Fault_Clear | boolean | Latched fault mode | Clear latched fault condition |
| Output | Type | Description |
|---|---|---|
| Fault_Status | uint16 | Current fault status register (bitfield of active faults) |
| Trigger 1..N | boolean | Trigger output signals for external synchronization |
| PWM_Status | uint16 | Overall PWM status (enable state, mode, etc.) |
The block supports 4 input datatype representations:
| Input Type | Range | Scaling | Description |
|---|---|---|---|
| Uint raw | 0 to PWMxmax | User handles scaling | Direct register value |
| Float [0 1] | 0.0 to 1.0 | Block scales internally | Normalized unipolar |
| Float [-1 1] | -1.0 to 1.0 | Block scales internally | Normalized bipolar |
| Float (s) | Time in seconds | Block scales internally | Physical time value |
⚠️ Important: The block performs no range checking on inputs. Users must clamp values before the block input (e.g., using a Saturation block) to prevent overflow, regardless of datatype.
Selecting a float datatype accepts either single or double precision floating-point values. PIC32MK has hardware FPU—float inputs are processed efficiently. dsPIC33C uses software emulation—consider uint raw inputs for time-critical loops.
The block creates workspace variables for user scaling:
| Variable | Description |
|---|---|
PWM1max…PWMNmax | Maximum timer count per channel (based on Max Period in GUI) |
Fixed Period (period input disabled):
$$\text{DutyCycle}_\text{raw} = \text{DutyCycle}_\text{normalized} \times \text{PWMxmax}$$
DutyCycle_raw = DutyCycle_normalized × PWMxmax
Where DutyCycle_normalized is in the range [0, 1] relative to the fixed Max Period.
Variable Period (period input enabled):
When the period is dynamically controlled via block input, both period and duty cycle use the same scaling:
$$\text{Period}_\text{raw} = \text{Period}_\text{normalized} \times \text{PWMxmax}$$
Period_raw = Period_normalized × PWMxmax
$$\text{DutyCycle}_\text{raw} = \text{DutyCycle}_\text{normalized} \times \text{Period}_\text{raw}$$
DutyCycle_raw = DutyCycle_normalized × Period_raw
⚠️ Constraints:
PWMxmaxCenter-Aligned Mode: The PWMxmax workspace variable is halved at configuration time because the timer counts both up and down. This applies to all input types (Uint raw, Float).
No runtime division: Since PWMxmax is already halved, the block passes integer inputs directly to registers without any runtime shift operation. Users simply scale their values to the halved PWMxmax.
Edge-Aligned Mode: The timer counts up only. PWMxmax represents the full period count. Duty cycle updates take effect at the next period boundary.
MCPWM supports two asymmetric center-aligned modes:
[val_up val_down]. First value applied during up-count, second during down-count.These modes enable asymmetric PWM waveforms for harmonic reduction and THD optimization.
GUI configuration: Specify in seconds (e.g., 1e-6 for 1 µs)
Integer block input: Dead time uses a different scaling base (full period, not halved).
⚠️ In center-aligned mode, multiply PWMxmax by 2 for dead time scaling:
$$\text{DeadTime}_\text{raw} = \frac{\text{DeadTime}_s \times 2 \times \text{PWMxmax}}{\text{MaxPeriod}_s}$$
DeadTime_raw = (DeadTime_s × 2 × PWMxmax) / MaxPeriod_s
PWMxmaxWhen Positive dead time with compensation mode is enabled:
This block uses a multi-tab GUI dialog with many parameters. Multiple instances can be used within a model to configure PWM channels with different characteristics or update at different rates.
| Parameter | Description |
|---|---|
| Period | PWM mode selection: Common - Edge aligned, Common - Center aligned - Symetric, Common - Center aligned - Symetric - Enhanced resolution, Common - Center aligned - Asymetric with double update, Common - Center aligned - Asymetric with simultaneous update, Independant - Edge aligned, Independant - Center aligned - Symetric, Independant - Center aligned - Asymetric with double update, Independant - Center aligned - Asymetric with simultaneous update |
| Clock source | Primary master timer or Secondary master timer |
| Clock source resolution | Clock prescaler selection. Prompt shows effective resolution (e.g., “PWM res 8.333(ns) => periode up to 546(us)”) |
| Max Period (s) | Maximum period in seconds. Defines PWMxmax workspace variables. Prompt shows calculated values |
| Initial Period (s) | Starting period value |
| Initial Duty Cycle (s) | Starting duty cycle in seconds |
| Initial second half Duty Cycle (s) | For asymmetric center-aligned modes |
| Initial Phase (s) | Starting phase shift (-1 for disabled) |
| Block output sample time | Sample time for block outputs |
| Parameter | Description |
|---|---|
| High/Low side Mode | Complementary, Redundant, or Push Pull |
| PWM 1 Channel | PWMxH & PWMxL output enabled, PWMxH output enabled, PWMxL output enabled, not used, or Enabled with NO output |
| Swap PWM1_H and PWM1_L | Swap high and low outputs |
| invert PWM1_H output polarity | Active low output. Prompt shows pin (e.g., “B14 [4] active low”) |
| invert PWM1_L output polarity | Active low output. Prompt shows pin |
| PWM 2 Channel | Channel 2 enable options |
| Swap PWM2_H and PWM2_L | Swap high and low outputs |
| invert PWM2_H/L output polarity | Active low outputs |
| … | Parameters repeat for PWM 3-12 depending on device |
| Parameter | Description |
|---|---|
| Dead Time Control | Disabled, Positive dead time, Negative dead time (edge aligned only), or Positive dead time with compensation mode |
| Dead Time High-side (s) | Dead-time duration for high-side transitions |
| Dead Time Low-side (s) | Dead-time duration for low-side transitions |
| Dead Time Compensation | Comparator source for compensation mode |
| Parameter | Description |
|---|---|
| Fault Source | Fault input selection per PWM: Fault pin inputs, Digital comparator outputs, Software fault, or Combination (OR/AND logic) |
| Fault Pin | Physical fault input pin selection |
| Fault Pin Polarity | Active high or active low |
| Fault Mode | Latched (requires manual clear) or Cycle-by-cycle (auto-restart when fault clears) |
| Fault PWMxH state | Output state during fault: Low, High, or High-Z |
| Fault PWMxL state | Output state during fault: Low, High, or High-Z |
| Fault State is a block output | Enable Fault_Status output port |
| Parameter | Description |
|---|---|
| Leading Edge Blanking | Enable blanking after PWM transitions to ignore switching noise on fault inputs |
| LEB Duration | Blanking time period (typically 200-1000 ns) |
| LEB Trigger Source | Rising edge PWMxH, Falling edge PWMxH, or PWMxL edges |
| Parameter | Description |
|---|---|
| Primary Event Trigger (s) | Special event compare for primary ADC trigger (SEVTCMP) |
| Secondary Event Trigger (s) | Secondary special event trigger |
| Trigger 1 (s) | ADC/DAC trigger point 1 per PWM |
| Trigger 2 (s) | ADC/DAC trigger point 2 per PWM |
| Trigger 3 (s) | ADC/DAC trigger point 3 per PWM |
| Trigger is a block input | Enable dynamic trigger adjustment per channel |
| Parameter | Description |
|---|---|
| Input Format | Scalar (same value for all channels) or Vector (individual values) |
| Period is a block Input | Enable period block input |
| Duty Cycle is a block Input | Enable duty cycle block input per channel |
| Phase Shift is a block Input | Enable phase shift block input per channel |
| Dead Time is a block Input | Enable dynamic dead-time adjustment |
MCPWM provides multiple trigger outputs (TRIG1..3, SEVTCMP) to precisely coordinate ADC conversions with PWM waveform timing.
Configuration Example (Center-Aligned PWM):
% In MCPWM block:
Period = 'Center aligned - Symmetric';
Max_Period = 1/20e3; % 20 kHz PWM frequency
% Trigger ADC at PWM valley (center point - all low-side FETs ON):
Primary_Event_Trigger = 0; % Valley trigger
% In ADC block:
Trigger_Source = 'PWM1 Special Event';
Sample_Time = 'Inherited'; % ADC rate follows PWM (20 kHz)
MCPWM supports up to 3 trigger outputs per PWM generator for high-performance control requiring multiple measurements per PWM cycle:
% Center-aligned PWM with 3 trigger points:
Period = 'Center aligned - Symmetric';
% Trigger 1: Before valley (rising edge phase currents)
Trigger_1 = Period * 0.4;
% Trigger 2: At valley (all low-side ON)
Primary_Event_Trigger = 0;
% Trigger 3: After valley (falling edge phase currents)
Trigger_2 = Period * 0.6;
| Application | Recommended Strategy | Key Settings |
|---|---|---|
| 3-Phase Motor FOC | PWM → ADC → Task | Center-aligned, SEVTCMP = 0 (valley) |
| Single Shunt FOC | Multiple Triggers | TRIG1, TRIG2 at sector transitions |
| PFC Boost Converter | PWM → ADC → Task | Edge-aligned, SEVTCMP at 90% period |
| Interleaved Converters | Multiple Triggers | Independent time bases, phase-shifted triggers |
% Configuration:
Period = 'Center aligned - Symmetric';
Dead_Time_Control = 'Positive dead time with compensation mode';
% Dead-time settings:
Dead_Time_High = 1.2e-6; % 1.2 µs high-side
Dead_Time_Low = 1.0e-6; % 1.0 µs low-side
% Compensation comparator (current sensing):
% Dead-time automatically adjusted based on current direction
% Fast overcurrent shutdown with noise immunity:
Fault_Mode = 'Cycle-by-cycle'; % Auto-restart when fault clears
Fault_State = 'All Low'; % Safe state
% Leading-Edge Blanking:
Leading_Edge_Blanking = 'on';
LEB_Duration = 500e-9; % 500 ns blanking
LEB_Trigger = 'Rising edge PWMxH'; % Blank after high-side turn-on
Cause: Latched fault mode requires manual clear.
Solution: Send pulse to Fault_Clear input, or change to cycle-by-cycle mode for auto-restart.
Solutions:
Checklist:
| Family | Representative Devices | Key Features |
|---|---|---|
| PIC32MK | PIC32MK MCJ/MCM/MCA families | Full MCPWM with digital comparators, advanced fault handling |
| dsPIC33C (selected) | 33CH, 33CK families with MCPWM | High-speed MCPWM, multiple fault sources |
| dsPIC33A | Latest 33A families | Enhanced MCPWM with fine edge placement |