> 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/rt-lab/simulink-blocks-reference/mmc-library/pwm-gen.md).

# PWM Gen

## Description <a href="#pwmgenerationblock-description" id="pwmgenerationblock-description"></a>

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-0b6fc266ef0e468c8d8973a014cff4816b890615%2FMMC_PWM_gen_block.png?alt=media" alt=""><figcaption></figcaption></figure>

The **PWM Gen** block, located in the **MMC/Control blocks** library, compares reference signals with carrier signals to generate gating signals for converter switching devices. The block includes advanced algorithms that account for intra–time‑step switching events, improving accuracy when the simulation sampling frequency is not significantly higher than the carrier frequency. The output of this block is intended to connect to the gating-signal input of the [**Conf\_sf**](https://www.opal-rt.com/docs/rt-lab/simulink-blocks-reference/mmc-library/conf_sf.md) block.

TOM and ATOM modes interpolate switching events that occur **between simulation steps**. This prevents missed pulses when the sampling frequency is not high enough to resolve all carrier crossings. For example, when the ratio of the sampling frequency to the carrier frequency is less than 100, Static mode may miss intermediate carrier peaks (e.g., Sc1 and Sc2 in figure below), resulting in incorrect pulse generation. TOM or ATOM modes detect these events through interpolation, producing a more accurate gating signal.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-edf0aee2fe5d4110cd48688060db6defb4234a67%2FMMC_PWM_gen_curves.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Mask and Parameters <a href="#maskandparameters" id="maskandparameters"></a>

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-3edc10ab29869f43fed634460b40fd3e36abe31a%2FMMC_PWM_gen_mask.png?alt=media" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="123.09088134765625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Relational operator</strong></td><td>Defines the comparison operator applied to the reference (<code>s</code>) and carrier (<code>car</code>) inputs. Supported operators: <code>&#x3C;</code>, <code>></code>, <code>&#x3C;=</code>, <code>>=</code>, <code>=</code>, <code>~=</code>.</td></tr><tr><td><strong>Mode</strong></td><td><p>Determines how the block handles switching events that occur between simulation time steps.<br><strong>Static Mode:</strong> Used when the sampling frequency is at least <strong>100× higher</strong> than the carrier frequency. The output toggles strictly at simulation time steps, producing values of <strong>0 or 1</strong>.</p><p><strong>TOM Mode (Time‑On‑Mean):</strong> Used when the sampling frequency is <strong>20× to 100×</strong> the carrier frequency. Output values vary <strong>between 0 and 1</strong>, using interpolation techniques to estimate switching instants that occur between time steps.</p><p><strong>ATOM Mode (Advanced TOM):</strong> Used when the sampling frequency is <strong>4× to 20×</strong> the carrier frequency. Also produces <strong>continuous values between 0 and 1</strong>, with improved interpolation for low‑sampling‑rate conditions.</p></td></tr></tbody></table>

## Inputs <a href="#inputs" id="inputs"></a>

<table><thead><tr><th width="155.81817626953125">Input</th><th>Description</th></tr></thead><tbody><tr><td><strong>enable</strong></td><td>Enables the pulse‑generation process. Use <strong>1</strong> to enable and <strong>0</strong> to disable.</td></tr><tr><td><strong>s</strong></td><td>Reference signal. Expected range: <strong>[-1, 1]</strong>.</td></tr><tr><td><strong>car</strong></td><td>Carrier signal, typically generated by the <strong>Carrier Signal Generation</strong> block from the same library.</td></tr></tbody></table>

## Outputs <a href="#outputs" id="outputs"></a>

<table><thead><tr><th width="374">Output</th><th>Description</th></tr></thead><tbody><tr><td><strong>y</strong></td><td>Comparison output (gating signal).</td></tr><tr><td><strong>!y</strong></td><td>Complementary of the comparison output.</td></tr></tbody></table>

## Characteristics and limitations <a href="#characteristicsandlimitations" id="characteristicsandlimitations"></a>

<table><thead><tr><th width="221.272705078125">Characteristic</th><th>Value</th></tr></thead><tbody><tr><td><strong>Supported operators</strong></td><td>TOM and ATOM modes support all operators except <code>=</code> and <code>~=</code>.</td></tr><tr><td><strong>Supported solvers</strong></td><td>TOM and ATOM modes support fixed‑step solvers only.</td></tr></tbody></table>

## References <a href="#references" id="references"></a>

Li and F. Zhang, *"A General Interpolated Model of Voltage Source Converters for Real-time Simulation and HIL Test Applications,"* 2020 IEEE Energy Conversion Congress and Exposition (ECCE), Detroit, MI, USA, 2020, pp. 6155–6161. doi: 10.1109/ECCE44975.2020.9235715.


---

# 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/rt-lab/simulink-blocks-reference/mmc-library/pwm-gen.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.
