Pwm Highspeed Block Icon
This block is designed for demanding motor control and power conversion applications requiring precise timing, independent channel control, and high switching frequencies.

Block Inputs/Outputs

Block Inputs

InputTypeConditionDescription
Perioduint16 or uint16[]Period input enabledPeriod value(s). Label varies by mode: Period[1 2...] for master time base, Period Hx/Period Lx for independent mode
DutyCycle 1..Nuint16 or uint16[2]Duty cycle enabledDuty cycle values. Single value or [up down] for double update
Phase 1..Nuint16Phase input enabledPhase shift values for interleaved operation
Trigger 1..Nuint16Dynamic trigger enabledDynamic ADC trigger point values

Block Outputs

OutputTypeDescription
Fault State 1..NbooleanFault status output per PWM (if enabled)

Scaling

This block uses uint16 raw values for all inputs (period, duty cycle, phase, trigger). User scaling is required.

Input TypeRangeScalingDescription
Uint16 raw0 to PWMxmaxUser handles scalingDirect register 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.

Uint Raw Input

  • Uint raw: Integer values transfer directly to peripheral registers with no runtime computation—maximum efficiency.

The block creates workspace variables for user scaling:

VariableDescription
PWMmaxGlobal maximum period value (when using master time base)
PWM1maxPWMNmaxMaximum period per channel (based on Max Period in GUI)
PWMxmax_H, PWMxmax_LFor Independent mode with separate H/L periods

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:

  • Period input must always be < PWMxmax (Max Period in GUI)
  • Duty cycle normalizes to the actual period input, not PWMxmax
  • If ADC triggers from PWM events and drives the scheduler, changing period alters the control loop sample time

Center-Aligned vs Edge-Aligned

Center-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 (unless Immediate Update is enabled).

Double Update Mode

When Double Update is enabled (requires Center-Aligned Mode + Independent Period):

  • Duty cycle input becomes a 2-element vector: [val_up val_down]
  • First value applied during up-count, second during down-count
  • Enables asymmetric PWM waveforms for harmonic reduction

Workspace variables for double update:

  • PWMxmax_H — Maximum value for high-side (up-count)
  • PWMxmax_L — Maximum value for low-side (down-count)

Dead Time

  • 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

  • Note: Dead time scaling is identical in center-aligned and edge-aligned modes—the factor of 2 compensates for the halved PWMxmax

Block Parameters

This block uses a custom 5-tab GUI dialog. All parameters shown below are visible to users.

Main Tab
ParameterDescription
PWM-H and PWM-L modeComplementary (PWM-L is complement of PWM-H), Redundant (identical signals), Push-Pull (alternating on H/L), or Independent (separate control)
Independent PeriodEnable independent period per PWM channel (required for Center Aligned mode)
Independent Duty CycleEnable independent duty cycle per PWM channel
Enable ChannelsPer-channel enable checkboxes for PWM 1..N (H and L separately)
Max Period (s)Maximum period in seconds per channel. Defines PWMxmax workspace variables
Center Aligned ModeAlign PWMs to middle of up/down time. Resolution is divided by two
Immediate UpdateUpdate duty-cycle, phase, and period immediately (vs. at period boundary)
Double UpdateIn Center Aligned mode, update twice per PWM cycle. Input becomes [val1 val2] vector
Block Sampling Time (s)Sample time for block outputs
Block Input and Initialisation Tab
ParameterDescription
Initial Period (s)Starting period value per channel (H and L separately for Independent mode)
Period is a block InputEnable period block input per channel
Initial Duty Cycle (%)Starting duty cycle percentage per channel
Duty Cycle is a block InputEnable duty cycle block input per channel
Initial Phase (s)Starting phase shift in seconds per channel
Phase is a block InputEnable phase shift block input per channel
Initial ADC Trigger (s)Starting ADC trigger timing per channel
Trigger is a block inputEnable dynamic trigger adjustment per channel
Fault & Current-Limitation Tab
ParameterDescription
FaultFault source selection per PWM: Disabled, FLTx pin, Comparator, or combinations
Fault pinSelect fault input pin per PWM channel
Fault Pin ActiveHigh or Low - polarity of fault input
Fault PWMxH stateOutput state during fault: Low, High, or High-Z
Fault PWMxL stateOutput state during fault: Low, High, or High-Z
Fault State is a block outputEnable fault status output port per channel
Fault ModeNormal (Override Active/Inactive set to 0/1) or Independent (keeps PWM enabled/disabled)
Current-Limit SourceCurrent limit trigger source selection
Current Limit PWMxH/L stateOutput state during current limit
Fault & Cur-Lim Blanking Tab
ParameterDescription
Leading Edge BlankingEnable blanking after PWM transitions to ignore switching noise on fault inputs
LEB DurationBlanking time period in timer counts
LEB SourceTrigger source: Rising edge PWMxH, Falling edge PWMxH, or PWMxL edges
Dead Time Tab
ParameterDescription
Dead TimeMode selection: Disabled, Positive, Negative (edge-aligned only), or Compensation
Dead Time (s)Dead-time duration for PWMxH transitions (seconds) per channel
Alternate Dead Time (s)Dead-time duration for PWMxL transitions (seconds) per channel

Output Modes

ModeDescriptionUse Case
ComplementaryPWM-L is complement of PWM-H with dead-time insertionStandard motor drive, half-bridge converters
RedundantPWM-L is identical to PWM-HParallel drive, increased current capability
Push-PullPWM pulses alternate on PWM-H and PWM-L outputsPush-pull converters, full-bridge DC-DC
IndependentPWM-H and PWM-L have separate period and duty cycleDual independent loads, asymmetric control

Additional Features

PWM-ADC Synchronization

Synchronizing ADC sampling with PWM switching is essential for accurate current measurement in motor control and power conversion.

Option 3: PWM → ADC → Task (Motor Control Standard)

Configuration using Initial ADC Trigger:

% In PWM HighSpeed GUI, Block Input and Initialisation tab:
Initial_ADC_Trigger = 0;  % Trigger at valley (center-aligned)
% Or for edge-aligned:
Initial_ADC_Trigger = Max_Period / 2;  % Trigger at mid-period

% In ADC block:
Trigger_Source = 'PWM Trigger 1';
Sample_Time = 'Inherited';

Benefits:

  • Synchronized current sensing with PWM switching
  • Sample when low-side FET is ON (minimal switching noise)
  • Control loop rate automatically matches PWM frequency

Best Practices

PWM ModeRecommended Trigger TimingConfiguration
Center-AlignedAt valley (maximum current flow)Initial ADC Trigger = 0
Edge-AlignedMid-period (stable PWM state)Initial ADC Trigger = Max_Period / 2
Interleaved PhasesStaggered triggers per phaseDifferent trigger values per PWM

Usage Examples

Example 1: 3-Phase Motor Control (Complementary Mode)

% Main tab:
PWM_HL_mode = 'Complementary';
Independent_Period = false;      % Master time base
Independent_Duty_Cycle = true;   % Per-channel control
Center_Aligned_Mode = true;
Immediate_Update = false;        % Synchronized updates
Double_Update = false;

% Max Period for 20 kHz PWM:
Max_Period = 1/20000;  % 50 µs

% Dead Time tab:
Dead_Time = 1e-6;      % 1 µs
Alt_Dead_Time = 1e-6;  % 1 µs

Example 2: Asymmetric Center-Aligned (Double Update)

% Main tab:
Independent_Period = true;       % Required for Double Update
Center_Aligned_Mode = true;      % Required for Double Update
Double_Update = true;            % Enable asymmetric PWM

% Duty cycle input becomes [val1 val2] for up/down count
% Use case: Harmonic reduction, EMI optimization

Troubleshooting

Double Update Mode Requirements

Double Update requires:

  • Independent Period = enabled
  • Center Aligned Mode = enabled

If conditions not met, double update is automatically disabled.

Immediate vs. Synchronized Update

  • Immediate Update = off (default): Updates at period boundary. Eliminates pulse width glitches. Recommended for motor control.
  • Immediate Update = on: Updates immediately. Use for fast transient response but may cause glitches.

Supported Device Families

FamilyMasksetsKey Features
dsPIC33F (selected)DOS_00958_pwm_TLAH, DOS_00958_pwm_TLAYHigh-speed PWM, Auxiliary clock support
dsPIC33EP (GS)DOS_00958_pwm_TLAH, DOS_00958_pwm_TLAYEnhanced features, APLL clock, up to 12 channels
dsPIC33C/CH/CKVarious (WAC, WBH masksets)Full-featured high-speed PWM, independent time bases

See Also

Datasheets