PWM

PWM Generator

Sources
Live-Beispiel starten Kostenlos · ohne Anmeldung · läuft im Browser

The PWMGenerator block produces a Pulse-Width Modulated (PWM) switching waveform by comparing a normalized duty-cycle command D∈[0,1]D \in [0, 1] against a periodic sawtooth or triangle carrier wave. It is designed to drive power electronic switches (MOSFET, ControlledSwitch) and proportional hydraulic/pneumatic valves without manually wiring carrier generators and comparators.

Mathematisches Modell

The normalized carrier phase ϕ(t)∈[0,1)\phi(t) \in [0, 1) is computed from the switching frequency fswf_{\text{sw}} and phase offset θ0\theta_0:

ϕ(t)=(t⋅fsw+θ0360∘) mod 1\phi(t) = \left( t \cdot f_{\text{sw}} + \frac{\theta_0}{360^\circ} \right) \bmod 1

For a trailing-edge sawtooth carrier c(ϕ)=ϕc(\phi) = \phi or a center-aligned triangle carrier c(ϕ)=1−∣2ϕ−1∣c(\phi) = 1 - |2\phi - 1|, the output is:

y(t)={Vhigh,D>c(ϕ) or D≥1Vlow,otherwisey(t) = \begin{cases} V_{\text{high}}, & D > c(\phi) \text{ or } D \ge 1 \\ V_{\text{low}}, & \text{otherwise} \end{cases}

Ein- & Ausgänge

Direction ID Label Typ Status
→ In duty D number Optional
← Out out PWM number Output
← Out carrier Carrier number Output

Parameter

Parameter Label Typ Standardwert Beschreibung
frequency Carrier Frequency number 1000 PWM switching frequency f_sw
dutyCycle Duty Cycle number 0.5 Default normalized duty cycle [0..1] when Duty input is disconnected
highLevel High Level number 1 Output voltage when the PWM pulse is active
lowLevel Low Level number 0 Output voltage when the PWM pulse is inactive
carrierType Carrier Waveform select sawtooth Carrier wave shape used for comparator modulation
phase Phase Offset number 0 Carrier phase shift in degrees for interleaved converters

Anwendungsbeispiele

Open-Loop Buck Converter Gate Drive

Set frequency to 5000 Hz, dutyCycle to 0.4, highLevel to 10 V, and connect out to the gate g of a MOSFET to step down a Battery supply voltage.

Closed-Loop DC Motor Speed Control

Connect the normalized output of a PIDController (clamped to [0, 1]) to the duty input port, and drive a ControlledSwitch or MOSFET feeding a DCMotor.

Hinweise & Best Practices

  • Nyquist Sampling Rate: Choose a simulation sample time Ts≤120fswT_s \le \frac{1}{20 f_{\text{sw}}} so the duty-cycle resolution is accurately captured.
  • Interleaved Phases: Use two PWMGenerator blocks with phase set to 0 and 180 degrees to drive complementary or interleaved converter legs.

Verwandte Blöcke