PWM generator

Compares the duty-cycle input (0…1) with a sawtooth to produce fire and its complement.

  • signal
  • Boolean
  • Modelica Standard Library
  • 3 ports
  • 1 parameter
BlockPWM generatorKindpwmSignalLibraryConverters

Description

Generates a pulse-width-modulated fire signal and its complement. The duty-cycle input is clipped to 0…1, sampled at the start of each switching period, and compared with a sawtooth carrier that rises from 0 to 1 once per period.

Example

DC-DC converters Buck, boost, and bidirectional half-bridge converters switching at 10 kHz with 50 % duty.

Duty A 0.5PWM 10 kHzC A 100 µFLoad A 10 Ωv out A24 VGround (buck)BuckL 1 mHDuty B 0.5PWM 10 kHz (boost)C B 100 µFLoad B 50 Ωv out B12 VGround (boost)L 1 mH (boost)BoostDuty C 0.5PWM 10 kHz (half-bridge)C C 100 µFLoad C 50 Ωv out C12 V (half-bridge)Ground (half-bridge)L 1 mH (half-bridge)Half-bridge
In Gradara, select a PWM generator block and press F1, then choose Open example. It opens as a new model in My models, ready to run.

Also in this example:DC voltageVoltage sensorConstantGroundResistorCapacitorInductorBuck converterBoost converterBuck-boost converter

Ports

Inputs 1

  • ddutyCycle

    Duty cycle, dimensionless. Values outside 0…1 are clipped.

Outputs 2

  • fire

    PWM output (Boolean): true while the held duty cycle exceeds the carrier.

  • fire̅notFire

    Complement of fire.

Parameters

  • Switching frequencyf10000 Hz

    ≥ 0

    Switching frequency, in Hz. Positive; the switching period is 1 / f.

Equations

Modelica
dk = min(max(dutyCycle(k / f), 0), 1), held for k / f ≤ time < (k + 1) / f
carrier = f · time − floor(f · time)
fire = dk > carrier, notFire = not fire

Implementation

Modelica Standard Library 4.1.0Modelica.Electrical.PowerConverters.DCDC.Control.SignalPWM
MSL documentation

Assumptions and limitations

  • Sawtooth carrier only, starting at time 0 (trailing-edge modulation). No dead time between fire and notFire.
  • The duty cycle is sampled once per period, so the output lags the input by up to one period.

Tips

  • Each period adds two events; keep the maximum step size well below 1 / f.

Used in

These larger examples use it too. Open them from Examples in the app.

  • 480 VAC → 24 VDC flyback

See also

Select a block in Gradara and press F1 to open its page offline.