> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/control-and-measurements/pulse-and-signal-generators/pwm-generator-2-level.md).

# PWM Generator (2-Level)

## Description

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-bd22ab13605e5e75a4981d6a2248b4164f76d455%2FPWM_generator_2level_block.png?alt=media" alt=""><figcaption></figcaption></figure>

The **PWM Generator (2-Level)** block, located in the **OPAL-RT SPS Software/Power Electronics/Power Electronics Control** library, generates pulses for carrier-based pulse width modulation (PWM) converters using two-level topology. The block can control switching devices (FETs, GTOs, or IGBTs) of three different converter types: single-phase half-bridge (1 arm), single-phase full-bridge (2 arms), or three-phase bridge (3 arms).

The reference signal (Uref input), also called modulating signal, is compared with a symmetrical triangle carrier. When the reference signal is greater than the carrier, the pulse for the upper switching device is high (1), and the pulse for the lower device is low (0).

To control a single-phase full-bridge device, you can select unipolar or bipolar PWM modulation. Using the unipolar modulation, each arm is controlled independently. A second reference signal is internally generated by phase-shifting the original reference signal by 180 degrees. Using the bipolar modulation, the state of the lower switching device of the second arm is the same as the state of the upper switch of the first arm, and the state of the upper switch of the second arm is the same as the state of the lower switch of the first arm. The unipolar modulation produces better quality AC waveform, but the bipolar modulation produces very low-varying common-mode voltage.

The figure describes the three techniques to sample the reference signal Uref.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-dfcfd0a7b7e5b9807cf6653ae540d5d7ea1f8c38%2FPWM_generator_2level_samplingtechnique.png?alt=media" alt=""><figcaption><p>Reference Signal Sampling Techniques</p></figcaption></figure>

The natural sampling technique models the behavior of an analog implementation of a PWM generator. Using the two regular sampling techniques, Uref can be sampled twice at both the valley and the peak of the carrier or only once at the valley of the carrier. The former is referred to as asymmetrical sampling or double-edge technique. The latter is called symmetrical sampling or single-edge technique.

## Characteristics

<table data-header-hidden><thead><tr><th width="250.00006103515625"></th><th></th></tr></thead><tbody><tr><td>Sample Time</td><td>Specified in the <strong>Sample Time</strong> parameter Continuous if <strong>Sample Time</strong> = 0</td></tr><tr><td>Scalar Expansion</td><td>No</td></tr><tr><td>Dimensionalized</td><td>No</td></tr></tbody></table>

## Ports

### Input

<table data-header-hidden><thead><tr><th width="249.88885498046875"></th><th></th></tr></thead><tbody><tr><td><strong>Uref</strong> — Reference signal used to generate output pulses<br></td><td><p>Vectorized reference signal used to generate the output pulses.</p><p>Connect this input to a single-phase sinusoidal signal when the block is used to control a single-phase half- or full-bridge converter, or to a three-phase sinusoidal signal when the PWM Generator block is controlling a three-phase bridge converter. For linear operation of this block, the magnitude of <strong>Uref</strong> must be between −1 and +1.</p><p><strong>Dependencies</strong> To enable this port, clear the <strong>Internal generation of modulating signal (s)</strong> parameter.</p></td></tr><tr><td><strong>wt</strong> — External reference signal used to synchronize carrier<br></td><td><p>External reference signal used to synchronize the carrier.</p><p><strong>Dependencies</strong> To enable this port, set <strong>Carrier: Mode of operation</strong> to Unsynchronized.</p></td></tr></tbody></table>

### Output

<table data-header-hidden><thead><tr><th width="250.44439697265625"></th><th></th></tr></thead><tbody><tr><td><strong>P</strong> — Pulse signals used to fire self-commutated devices<br></td><td>Output contains the two, four, or six pulse signals used to fire the self-commutated devices (MOSFETs, GTOs, or IGBTs) of a one-, two- or three-arm converter.</td></tr><tr><td><strong>m</strong> — Measurement output<br></td><td><p>Measurement output that returns the carrier signal used to determine the output pulses and the sampled reference signal.</p><p><strong>Dependencies</strong> To enable this port, select the <strong>Show measurement port</strong> parameter.</p></td></tr></tbody></table>

## Parameters

<table data-header-hidden><thead><tr><th width="249.6666259765625"></th><th></th></tr></thead><tbody><tr><td><strong>Generator type</strong> — Number of pulses to generate<br>Single-phase half-bridge (2 pulses) (default) | Single-phase full-bridge (4 pulses) | Single-phase full-bridge - Bipolar modulation (4 pulses) | Three-phase bridge (6 pulses)</td><td><p>Specify the number of pulses to generate. The number of pulses generated by the block is proportional to the number of bridge arms to fire.</p><p>Select Single-phase half-bridge (2 pulses) to fire the self-commutated devices of a single-phase half-bridge converter.</p><p>Pulse 1 fires the upper device, and pulse 2 fires the lower device.</p><p>Select Single-phase full-bridge (4 pulses) to fire the self-commutated devices of a single-phase full-bridge converter.</p><p>Four pulses are then generated.</p><p>Pulses 1 and 3 fire the upper devices of the first and second arm.</p><p>Pulses 2 and 4 fire the lower devices. Select Single-phase full-bridge - Bipolar modulation (4 pulses) to fire the self-commutated devices of a single-phase full-bridge converter.</p><p>Four pulses are then generated.</p><p>Pulses 1 and 3 fire the upper devices of the first and second arm.</p><p>Pulses 2 and 4 fire the lower devices. Pulses 1 and 4 are identical.</p><p>Pulses 2 and 3 are identical.</p><p>Select Three-phase bridge (6 pulses) (default) to fire the self-commutated devices of a three-phase bridge converter.</p><p>Pulses 1, 3, and 5 fire the upper devices of the first, second, and third arms. Pulses 2, 4, and 6 fire the lower devices.</p></td></tr><tr><td><strong>Carrier: Mode of operation</strong> — Mode of operation of carrier signal<br>Unsynchronized (default) | Synchronized</td><td><p>When set to Unsynchronized (default), the frequency of the unsynchronized carrier signal is determined by the <strong>Frequency</strong> parameter.</p><p>When set to Synchronized, the carrier signal is synchronized to an external reference signal (input wt) and the carrier frequency is determined by the <strong>Switching ratio</strong> parameter.</p></td></tr><tr><td><strong>Carrier: Frequency (Hz)</strong> — Frequency of triangular carrier signal<br>27*60 (default)</td><td><p>Frequency, in hertz, of the triangular carrier signal.</p><p><strong>Dependencies</strong> To enable this parameter, set <strong>Mode of operation</strong> to Unsynchronized.</p></td></tr><tr><td><strong>Carrier: Initial phase (degrees)</strong> — Carrier initial phase<br>90 (default)</td><td><p>Carrier initial phase, in degrees.</p><p>A value of 90 degrees means that the triangle carrier initial position is set to midpoint between its minimum and maximum value and the slope is positive.</p><p><strong>Dependencies</strong> To enable this parameter, set <strong>Mode of operation</strong> to Unsynchronized.</p></td></tr><tr><td><strong>Carrier: Minimum and maximum values</strong> — Minimum and maximum values of triangular carrier signal<br>[ -1 1 ] (default)</td><td>Minimum (valley) and maximum (peak) values of the triangular carrier signal.</td></tr><tr><td><strong>Switching ratio (carrier frequency/output frequency)</strong> — Frequency of triangular carrier signal<br>27 (default)</td><td>Frequency (<em>F</em><sub><em>c</em></sub>) of the triangular carrier signal. > <em>Fc</em>=<em>SwitchingRatio</em>×<em>OutputVoltageFrequency</em>#### Dependencies To enable this parameter, set <strong>Mode of operation</strong> to Synchronized.</td></tr><tr><td><strong>Reference signal: Sampling technique</strong> — Sampling technique of reference signal<br>Natural (default) | Asymmetrical regular (double edge) | Symmetrical regular (single edge)</td><td><p>Specify how the reference signal is sampled: Natural (default), Asymmetrical regular (double edge), or Symmetrical regular (single edge).</p><p>If you select a regular sampling technique, the <strong>Sample time</strong> parameter must be an integer submultiple of the sampling period.</p><p>The sampling period is equal to 1/<strong>Carrier Frequency</strong>/2 for asymmetrical sampling and to 1/<strong>Carrier Frequency</strong> for symmetrical sampling.</p></td></tr><tr><td><strong>Reference signal: Internal generation of reference signal</strong> — Internal generation of reference signal<br>off (default) | on</td><td><p>When selected, the reference signal is generated by the block.</p><p>Default is cleared.</p><p>When not selected, external reference signals are used for pulse generation.</p><p>This parameter is available only if the <strong>Mode of operation</strong> parameter is set to Unsynchronized.</p><p><strong>Dependencies</strong> To enable this parameter, set <strong>Mode of operation</strong> to Unsynchronized.</p></td></tr><tr><td><strong>Reference signal: Modulation index</strong> — Modulation index<br>0.8 (default)</td><td><p>Modulation index to control the amplitude of the fundamental component of the output voltage of the converter.</p><p>The modulation index must be greater than 0 and lower than or equal to 1.</p><p><strong>Dependencies</strong> To enable this parameter, select the <strong>Internal generation of reference signal</strong> parameter.</p></td></tr><tr><td><strong>Reference signal: Frequency (Hz)</strong> — Frequency of reference signal<br>60 (default)</td><td><p>Output voltage frequency used to control the frequency of the fundamental component of the output voltage of the converter.</p><p><strong>Dependencies</strong> To enable this parameter, select the <strong>Internal generation of modulating signal (s)</strong> parameter.</p></td></tr><tr><td><strong>Reference signal: Phase (degrees)</strong> — Phase of reference signal<br>0 (default)</td><td><p>Phase of the fundamental component of the output voltage of the converter.</p><p><strong>Dependencies</strong> To enable this parameter, select the <strong>Internal generation of modulating signal (s)</strong> parameter.</p></td></tr><tr><td><strong>Sample time</strong> — Sample time<br>0 (default)</td><td><p>Sample time of the block, in seconds.</p><p>Set to <code>0</code> to implement a continuous block.</p><p>If you select a regular sampling technique, the <strong>Sample time</strong> parameter must be an integer submultiple of the sampling period.</p><p>The sampling period is equal to 1/<strong>Carrier Frequency</strong>/2 for asymmetrical sampling and to 1/<strong>Carrier Frequency</strong> for symmetrical sampling.</p></td></tr><tr><td><strong>Show measurement port</strong> — Show measurement port<br>off (default) | on</td><td><p>Select this check box to add a Simulink output to the block.</p><p>The output returns the carrier signal that is used to determine the output pulses and the sampled reference signal.</p></td></tr></tbody></table>

## Examples

The power\_PWMGenerator2Level model uses a simple circuit to illustrate the operation of the PWM Generator (2-Level). Run the simulation and use the FFT Analysis tool of the Powergui block to see the harmonics and the THD value of the voltages produced by the three-phase two-level converter.

The model sample time is parameterized by the Ts variable set to a default value of 50e-6 s. Set Ts to 0 in the command window and change the **Simulation type** parameter of the Powergui block to Continuous to simulate the model in continuous mode.

The power\_Bipolar PWM Generator model shows a comparison between unipolar PWM and bipolar PWM techniques.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/control-and-measurements/pulse-and-signal-generators/pwm-generator-2-level.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
