All block inputs can be individually enabled or disabled in the block configuration dialog. When disabled, the corresponding value set at initialization time remains constant.
Available block inputs:
Trigger 1..N (boolean) - Trigger output signalsStatus (uint16) - PWM status information (if enabled)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. dsPIC33A devices have 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…PWM8max | 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.
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
PWMxmax| Parameter | Description |
|---|---|
| PWM set with Period and | Alignment mode: Edge Aligned - Duty Cycle and Phase Shift, Edge Aligned - Rising and Falling Edge, Center Aligned, or Center Aligned - Double Update |
| Clock source | Clock routing: Use scaling circuit, Use divider circuit, or no scaling |
| Clock source resolution | Shows computed PWM resolution and maximum period. Dynamic display: [PWM res X.XX(ns) => period up to YY(µs)]. Must use “no scaling” for HiRES mode |
| Parameter | Description |
|---|---|
| Max Period (s) | Maximum PWM period defining the PWMxmax workspace variable. Dynamic display shows: PWM1max=PWM2max=...=XXXX (Nbits) represent YY(µs) |
| Initial Period (s) | Starting period value when period is not a block input |
| Initial Duty-Cycle (s) | Starting duty cycle value. Label changes to Initial Phase-Shift or Initial Rising/Falling Edge based on mode |
| Initial Phase-Shift (s) | Starting phase shift value (when applicable based on mode) |
| Block output sample time | Sample time for block outputs (typically matches PWM period) |
| Parameter | Description |
|---|---|
| High/Low side Mode | Output configuration: Complementary, Redundant, Push Pull, or Independent |
| PWM X Channel | Per-channel enable: PWMxH & PWMxL output enabled, PWMxH output enabled, PWMxL output enabled, or not used |
| Swap PWMx_H and PWMx_L | Exchange H and L output pin assignments |
| Invert PWMx_H/L output polarity | Active-low output. Dynamic display shows actual pin: (Bxx [pin] active low) |
Note: Up to 8 channels available depending on device. Polarity/swap options appear per enabled channel.
| Parameter | Description |
|---|---|
| Show Trigs for PWM X | Enable trigger configuration for each PWM generator (on/off) |
When enabled, trigger parameters (SEVTCMP, TRIG1, TRIG2) appear for ADC synchronization.
| Parameter | Description |
|---|---|
| Block input format | Independent Scalar (one input per channel) or Vectors (grouped by function) |
| Period | Not a block input, or select scaling: Uint raw, Float [0 1], Float [-1 1], Float (s) |
| Duty-Cycle | Input scaling for duty cycle. Same options as Period |
| Phase-Shift | Input scaling for phase shift (when mode supports it) |
| PWM Fault State is a block Output | Enable fault status output port |
| Parameter | Description |
|---|---|
| Dead Time mode | Disabled, Positive dead time, or Positive dead time with compensation |
| Positive dead time on rising edge of PWM_H (s) | Dead time inserted before PWM_H turns ON |
| Positive dead time on rising edge of PWM_L (s) | Dead time inserted before PWM_L turns ON |
Dead time prevents shoot-through in half-bridge configurations. Visible only when dead time mode is enabled.
| Feature | 33C WAC07 | 33A V3 (STX04) | 33A V4 (STX32/21) | Benefits |
|---|---|---|---|---|
| HiRES Mode | ✅ YES | ❌ NO | ✅ YES | 16× enhanced resolution |
| Max Channels | Variable | Variable | 12 max (STX32) | 8 max (STX21) |
| Register Width | 16-bit | 32-bit | 32-bit | Overflow protection |
| Dead Time | ✅ YES | ✅ YES | ✅ YES | Motor drive safety |
| ADC Triggers | ✅ YES | ✅ YES | ✅ YES | Synchronized sampling |
| Master/Slave | ✅ YES | ✅ YES | ✅ YES | Multi-channel coordination |
Reference: DS70005320 - dsPIC33/PIC24 Family Reference Manual - High-Resolution PWM with Fine Edge Placement , Section 4.1.3 - “High-Resolution PWM with Fine Edge Placement”
“High-Resolution mode CANNOT be used with frequency scaling or the clock divider.”
CLKSEL[1:0] bits (PGxCONL[4:3]) MUST be set to '01'
This selects pwm_master_clk DIRECTLY (no divider/scaling)
pwm_master_clk frequency requirements:
dsPIC33C: MUST be 500 MHz for High-Resolution mode
dsPIC33A: Refer to device datasheet timing requirements
STX32: 800 MHz typical
STX21: 400 MHz typical
| CLKSEL[1:0] | Clock Path | HiRES Compatible? | User Option |
|---|---|---|---|
| 00 | Off (no clock) | ❌ NO | Not applicable |
| 01 | Direct (master clock) | ✅ YES | “no scaling” |
| 10 | Divider circuit | ❌ NO (FORBIDDEN) | “Use divider circuit” (no PLL) |
| 11 | Scaling circuit | ❌ NO (FORBIDDEN) | “Use scaling circuit” (no PLL) |
| Constraint | Applies To | Reference |
|---|---|---|
| Dual PWM mode cannot be used with Complementary Output in HiRES | All families (HREN=1) | DS70005320 - dsPIC33/PIC24 Family Reference Manual - High-Resolution PWM with Fine Edge Placement , Sect. 4.1.3 |
| Minimum duty cycle: | 0x0020 | (vs. |
| Minimum period: | 0x0080 | (vs. |
| Some register LSBs forced to 0 (PGxLEB, PGxPHASE, etc.) | All families (HREN=1) | DS70005320 - dsPIC33/PIC24 Family Reference Manual - High-Resolution PWM with Fine Edge Placement , Sect. 4.1.3.1 |
Proper synchronization between PWM generation and ADC sampling is critical for motor control and power conversion applications. The PWM module can trigger ADC conversions at precise timing points, ensuring current measurements occur when switching noise is minimal.
The MCHP Blockset supports multiple strategies for triggering the control algorithm execution, each with specific advantages:
Configuration:
Use Cases:
Limitations:
Configuration:
Advantages:
Use Cases:
Configuration:
Key Benefits for Motor Control:
Typical SEVTCMP Timing (Center-Aligned PWM):
% For center-aligned PWM, sample at valley (maximum current flow)
SEVTCMP = 0; % Trigger at PWM valley
% Alternative: Sample at peak
SEVTCMP = Period; % Trigger at PWM peak
% For edge-aligned PWM, sample mid-period
SEVTCMP = Period/2; % Trigger at 50% duty cycle point
Use Cases:
Configuration:
Advanced Use Cases:
3-Phase motor control: Sample each phase current at different PWM timing
SEVTCMP: Phase A current (PWM valley)
TRIG1: Phase B current (25% into period)
TRIG2: Phase C current (75% into period)
Dual current sensing: Capture both rising and falling edge currents for average calculation
Multi-level inverters: Sample at different switching states
Ripple analysis: Capture peak and valley for DC-link ripple measurement
Configuration Example (3-Phase FOC):
% PWM Configuration:
PWMx_ECAM_ITB = 'Center aligned - Symmetric';
Period = 1/20e3; % 20 kHz PWM
% Trigger Configuration:
SEVTCMP = 0; % Trigger ADC1 at PWM valley (Phase A)
TRIG1 = Period/4; % Trigger ADC2 at 25% (Phase B)
TRIG2 = 3*Period/4; % Trigger ADC3 at 75% (Phase C)
% ADC Configuration:
% - ADC1 (Channel 0): Phase A current, triggered by SEVTCMP
% - ADC2 (Channel 1): Phase B current, triggered by TRIG1
% - ADC3 (Channel 2): Phase C current, triggered by TRIG2
% - All three conversions complete before control task executes
Always use PWM → ADC → Task for motor control applications
Set SEVTCMP timing carefully:
Center-aligned: Sample at valley (SEVTCMP = 0) for maximum current amplitude
Edge-aligned: Sample mid-period (SEVTCMP = Period/2) to avoid edges
Account for ADC conversion time: Ensure conversion completes before next PWM event
Match base sample time: Simulink base time step = PWM period (ensures proper code generation)
Verify trigger timing: Use Task State block to measure execution timing on oscilloscope
| Issue | Symptom | Solution |
|---|---|---|
| Noisy current measurements | High-frequency spikes in ADC readings | • Move SEVTCMP away from PWM edge transitions |
| Task overrun | MCU Load > 100%, control instability | • Reduce PWM frequency (increase period) |
| Incorrect trigger timing | ADC samples at wrong point in PWM cycle | • Verify SEVTCMP value calculation |
| Phase current mismatch | Sum of phase currents ≠ 0 (Kirchhoff violation) | • Synchronize all phase current ADC triggers to same PWM point |
Step-by-Step Configuration:
% In PWM_HS_FEP block dialog:
PWMx_ECAM_ITB = 'Center aligned - Symmetric';
Period = 1/20e3; % 20 kHz
SEVTCMP_Config = 'Constant';
SEVTCMP_Value = 0; % Sample at valley
% In ADC block dialog:
Trigger_Source = 'PWM Special Event';
PWM_Trigger_Select = 'PWM1 SEVTCMP'; % Match PWM generator
Sample_Time = 'Inherited'; % Triggers set ADC rate
% Configuration Parameters → Solver:
Solver = 'Fixed-step';
Fixed_step_size = 1/20e3; % Match PWM period
Tasking_mode = 'Multitasking'; % For rate monotonic scheduler
Checklist:
PWMx_ClockResolution set to "no scaling" (MANDATORY)Error: “HiRES mode cannot be used with divider or scaling circuit”
Solution: Change PWMx_ClockResolution to "no scaling". The divider and scaling circuits are incompatible with High-Resolution mode per DS70005320 - dsPIC33/PIC24 Family Reference Manual - High-Resolution PWM with Fine Edge Placement
Section 4.1.3.
Cause: HiRES mode has higher minimum duty cycle than standard mode.
Solution: Ensure duty cycle commands ≥ 0x0020. For very low duty cycles, use standard resolution mode.
| Family | Representative Chips | TLC Variant | HiRES Support | PWM Synthesis Freq |
|---|---|---|---|---|
| dsPIC33C | (Andromeda) | 33CK64MC105 | 33CK512MP608 | 33CK1024MP710 |
| dsPIC33A | (Perseus) | 33AK128MC106 | V3_STX04 | (Perseus) |
| dsPIC33A | (Pegasus) | (Serpens) | (BlueRidge) | 33AK512MPS512 |