> 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-pulse-averaging.md).

# PWM Generator (Pulse Averaging)

## Description

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

The **PWM Generator (Pulse Averaging)** block, located in the **OPAL-RT SPS Software/Power Electronics/Power Electronics Control** library, generates pulses, averaged over the sample time model, to use with these converter blocks when they have a switching function model selected:

* Two-quadrant DC/DC Converter block
* Full-Bridge Converter block
* Two-Level Converter block
* Three-Level NPC Converter block To use an SPS interpolation technique or SPS switching function models, the SPS solver needs to know when a transition from high-to-low or low-to-high occurs within a sample time. The PWM Generator (Pulse Averaging) block can provide the timing for these transitions.

With this pulse-averaging generator (and the SPS switching function converter models), a much higher sample time can be used for the SPS Software model while maintaining a high-fidelity simulation. Consequently, this generator serves as a virtual FPGA.

This figure illustrates the operation of the generator for a specified carrier frequency (Fc) of 2 kHz and a duty cycle (D) of 0.8. The model execution time (Ts) is 50 microseconds.

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

The generator outputs a pulse value using a naturally sampled, carrier-based modulation technique. If a transition occurs within a sample time, the generator will output a pulse value representing the time ratio (a value between 0 and 1) for the on state over the sample time. For example, at the sample time identified by the first blue arrow, the generator outputs a value of 0.25, which represents that the pulse entered on at 0.25*Ts seconds (it was on during 25% of the model execution time).*

*The offset is represented by the red dashed area. Similarly, at the sample time identified by the second blue arrow, the generator outputs a value of 0.75, which represents that the pulse was on during 75% of the model execution time (it entered the off state 0.75*Ts seconds after the previous sample time).

## Ports

### Input

<table data-header-hidden><thead><tr><th width="250.22210693359375"></th><th></th></tr></thead><tbody><tr><td><strong>Vref</strong> — Reference voltage<br>Three-phase vector | single-phase scalar</td><td><p>Reference voltage signal used to generate the output pulses, specified as a three-phase vector or a single-phase scalar.</p><p>Connect this input to a single-phase sinusoidal signal to control a single-phase full-bridge converter, or to a three-phase sinusoidal signal to control a three-phase bridge converter.</p><p>For linear operation of this block, the magnitude at <strong>Vref</strong> must be between −1 and +1<strong>Dependencies</strong> This port is visible only if <strong>Generator type</strong> is set to one of these values:</p><ul><li>Full-bridge, single-phase</li><li>Two-level, three-phase</li><li>Three-level, three-phase</li></ul><p>.<strong>Data Types:</strong> double</p></td></tr><tr><td><strong>D</strong> — Duty cycle<br>Scalar</td><td><p>Duty cycle of the PWM generator.</p><p>The value must be between 0 and 1.</p><p><strong>Dependencies</strong> This port is visible only if <strong>Generator type</strong> is set to Two-quadrant.</p></td></tr></tbody></table>

### Output

<table data-header-hidden><thead><tr><th width="250.4444580078125"></th><th></th></tr></thead><tbody><tr><td><strong>P</strong> — Pulses<br>Vector</td><td>Output pulses, returned as a vector.<strong>Data Types:</strong>double</td></tr></tbody></table>

## Parameters

<table data-header-hidden><thead><tr><th width="249.888916015625"></th><th></th></tr></thead><tbody><tr><td><strong>Generator type</strong> — PWM model<br>Two-level, three-phase (default) | Two-quadrant | Full-bridge, single phase | Three-level, three-phase</td><td><p>Type of generator to control. The number of pulses generated by the block is proportional to the number of bridge arms to fire.</p><ul><li>Select Two-quadrant to fire the self-commutated devices of a two-quadrant converter.</li><li>The duty cycle of the generator is specified by the input <strong>D</strong>, which determines the percentage of the pulse period that the pulse is on</li><li>Select Full-bridge, single-phase to fire the self-commutated devices of a single-phase full-bridge converter.</li><li>Four pulses are then generated. Pulses 1 and 3 fire the upper devices of the first and second arm. Pulses 2 and 4 fire the lower devices</li><li>Select Two-level, three-phase (default) to fire the self-commutated devices of a three-phase bridge converter.</li><li>Pulses 1, 3, and 5 fire the upper devices of the first, second, and third arms.</li><li>Pulses 2, 4, and 6 fire the lower devices.</li><li>Select Three-level, three-phase to fire the self-commutated devices of a three-level three phase bridge.</li><li>Pulses (1, 2), (5, 6), and (9, 10) fire the upper devices of the first, second, and third arms.</li><li>Pulses (3, 4), (7, 8), and (11, 12) fire the lower devices of the three arms.</li></ul></td></tr><tr><td><strong>Carrier frequency (Hz)</strong> — Carrier signal frequency<br>2000 (default)</td><td>Frequency, in Hz, of the triangular carrier signal. The value must be greater than 0.</td></tr><tr><td><strong>Carrier initial phase (deg)</strong> — Carrier signal initial phase<br>0 (default)</td><td>Carrier signal initial phase, in deg. 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.</td></tr><tr><td><strong>Sample time (s)</strong> — Block sample time<br>50e-6 (default)</td><td>Sample time of the block, in s. The value must be positive and greater than 0.</td></tr></tbody></table>


---

# 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-pulse-averaging.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.
