> 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/hypersim/library-blocks-reference/control-sources/pwm-average-generator-for-2-level-converter-switching-function.md).

# PWM Average Generator for 2-Level Converter (Switching Function)

## Description

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-60b4f9dee21e3be318dcac42a8db7c09f6eb1a90%2Fimage%20(973).png?alt=media" alt="" width="203"><figcaption></figcaption></figure>

The **PWM average generator for 2-level converter** block is a pulse generator that outputs the average value of a PWM signal over the simulator time step. It uses interpolation to determine the exact transition instants within each sample time.

The interpolation method detects transitions from low-to-high and high-to-low within a sample time, enabling accurate timing of these transitions while averaging over the simulator time step. Using this PWM with a converter modeled by a switching function allows larger sample times while maintaining high fidelity.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-1dfde32d44909bcecc3e138a0d13b0ff9e93b852%2Fimage%20(974).png?alt=media" alt="" width="563"><figcaption><p>Operating principle of this model for a carrier frequency (Fc) of 2 kHz and a duty cycle of 0.8. The time step is 50 μs.</p></figcaption></figure>

The generator emits a pulse value based on natural sampling and the simulator time step. If a transition occurs within a sample, the output is the ON-time ratio over that step (a value between 0 and 1). For example, a value of 0.25 means the signal was ON during 25% of the time step (transition at 0.25 · Ts). A value of 0.75 for a falling edge means the signal was ON for 75% of the time step (transition at 0.75 · Ts).

When **Use signal as PWM carrier frequency** is enabled, the block reads the input frequency Fc at the first step and uses the initial phase parameter to calculate the initial interpolation of the carrier. At subsequent steps, it recalculates the carrier only if Fc changes; otherwise, it reuses the previous carrier computation.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-31fe783c3d0bb11187b1a186781809f479ee44d1%2Fimage%20(547).png?alt=media" alt="" width="336"><figcaption><p>Operation of the block</p></figcaption></figure>

{% hint style="danger" %}
To properly initialize this block, select **Solve Control inputs before** in the Advanced tab of **Simulation Settings**.\
Use this block with the **2-Level Converter (Switching Function)**.
{% endhint %}

## Mask parameters

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-3e45de16544804554914b594d7a20eb5f1ba7eca%2Fimage%20(548).png?alt=media" alt="" width="545"><figcaption></figcaption></figure>

<table><thead><tr><th width="259.5999755859375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Use this field to add information about the block.</td></tr><tr><td><strong>Use signal as PWM carrier frequency</strong></td><td>When enabled, the component uses the frequency input signal to compute the carrier. Otherwise, it uses the PWM carrier frequency parameter. use_sig_Fc = [0, 1].</td></tr><tr><td><strong>PWM carrier frequency</strong></td><td>Frequency of the triangular carrier signal (Hz), FrequencyCarrier = [0, 1e12] .</td></tr><tr><td><strong>PWM carrier initial phase</strong></td><td>Initial phase of the carrier (°), InitialPhase = [0, 360].</td></tr><tr><td><strong>PWM dead time</strong></td><td>Dead time protection (s) to avoid simultaneous conduction of complementary arms. Must not be greater than the simulator time step Ts. Deadtime = [0, Ts].</td></tr></tbody></table>

{% hint style="info" %}
The simulator time step must not exceed one tenth of the **carrier period** (Ts ≤ (1/10) · (1/Fc)).\
The **Deadtime** value must not be greater than the simulator time step Ts.
{% endhint %}

## Inputs

<table><thead><tr><th width="179.5999755859375">Input</th><th>Description</th></tr></thead><tbody><tr><td><strong>Vref</strong></td><td>Vectorized reference signal containing the phase-to-ground voltages Va, Vb, and Vc.</td></tr><tr><td><strong>Fc</strong></td><td>Frequency signal used to compute the carrier (when Use signal as PWM carrier frequency is enabled).</td></tr></tbody></table>

## Outputs

<table><thead><tr><th width="180.4000244140625" valign="top">Output</th><th>Description</th></tr></thead><tbody><tr><td valign="top"><strong>P</strong></td><td>Vectorized signal containing six firing pulses to control the converter.<br><strong>Va</strong> Reference voltage signal from phase A (V).<br><strong>Vb</strong> Reference voltage signal from phase B (V).<br><strong>Vc</strong> Reference voltage signal from phase C (V).<br><strong>Fc</strong> Frequency signal used to compute the carrier (Hz).<br><strong>P1</strong> Firing pulse for Q1 (phase A upper arm of the converter).<br><strong>P2</strong> Firing pulse for Q2 (phase A lower arm of the converter).<br><strong>P3</strong> Firing pulse for Q3 (phase B upper arm of the converter).<br><strong>P4</strong> Firing pulse for Q4 (phase B lower arm of the converter).<br><strong>P5</strong> Firing pulse for Q5 (phase C upper arm of the converter).<br><strong>P6</strong> Firing pulse for Q6 (phase C lower arm of the converter).<br><strong>Carrier</strong> Triangular carrier signal.</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/hypersim/library-blocks-reference/control-sources/pwm-average-generator-for-2-level-converter-switching-function.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.
