> 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/rt-events-library/rte-spwm.md).

# RTE SPWM

## Description

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

The **RTE SPWM** block, located in the **RT-EVENTS Source** library, generates square-wave pulses at regular time intervals. The frequency and duty cycle inputs determine the output waveform.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-47ca2d441532f01e73558d03a9508b91b36da088%2FRTE_SPWM_charac.png?alt=media" alt=""><figcaption><p>Main characteristics of the generated square wave pulses</p></figcaption></figure>

The block outputs a scalar or a vector signal depending on the selected number of phases. When multiple phases are selected, provide a duty cycle for each phase; the duty cycle input must be a vector whose width equals the number of phases. The frequency input applies to all phases.

### **Center alignment mode**

Select the pulse alignment using the Center alignment mode parameter. When disabled, the pulse starts at the beginning of the period. When enabled, the pulse is centered relative to the period.

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

### **Space Vector PWM**

The block can generate space vector PWM using the space vector representation of the carrier (d–q plane). This option is available only when the number of phases is three.

**Rise time delay**: The block can apply a delay to the rising edge of the PWM pulse. The delay must be smaller than half the minimum PWM period. This option is available only when the complementary mode is selected.

**Maximum number of events**

This parameter sets the maximum number of transitions allowed during one calculation step and thus limits the maximum output frequency: *Fmax* = *Num* / ( 2 \* *Ts* ), where *Num* is the maximum number of events and *Ts* is the block sample time.

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

{% hint style="info" %}
This option is only available when the complementary mode is selected.
{% endhint %}

## Mask parameters

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

<table><thead><tr><th width="259.60003662109375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Number of phases</strong></td><td>The number of phases to be output. The PWM block supports up to 6 phases.</td></tr><tr><td><strong>Center alignment mode</strong></td><td>When disabled, the pulse starts at the beginning of the period. When enabled, the pulse is centered relative to the current period.</td></tr><tr><td><strong>Maximum frequency</strong></td><td>The maximum frequency output by the PWM block (Hz).</td></tr><tr><td><strong>Minimum frequency</strong></td><td>The minimum frequency output by the PWM block (Hz).</td></tr><tr><td><strong>Show enabling port</strong></td><td>If selected, the PWM block adds a control input that determines when the block is executed. When the control signal has a value of one, the block executes at each simulation step. When the control signal has a value of zero (0), the block holds on the last output value.</td></tr><tr><td><strong>Complementary PWM</strong></td><td>If selected, the PWM block adds an output port that contains the complementary PWM signals of each phase.</td></tr><tr><td><strong>Space vector PWM</strong></td><td>If selected, the PWM outputs are generated from the space vector representation of carrier signals.</td></tr><tr><td><strong>Rise time delay</strong></td><td>The time delay, in seconds, that is inserted between the fall and rise events of the PWM signal and its complementary part. The rise time delay is also related to the dead time or the dead band parameters.</td></tr><tr><td><strong>Maximum Number of events</strong></td><td>The maximum number of events or transitions that can occur during a single step. Above that value, the next events are skipped.</td></tr><tr><td><strong>Sample time</strong></td><td>The time interval between samples, in seconds.</td></tr></tbody></table>

## Inputs

| Input                    | Description                                                                                                                                   |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| **Frequency (Double)**   | The pulse frequency, in Hz. This parameter applies to all phases.                                                                             |
| **Duty Cycle (Double)**  | The duty cycle of each phase specified as the percentage of the pulse period during which the signal is on. Valid values are between 0 and 1. |
| **Enable port (Double)** | The enable input controls when the block is executed. See the Show enabling port parameter above.                                             |

## Outputs

| Output                              | Description                                                  |
| ----------------------------------- | ------------------------------------------------------------ |
| **PWM (RTE Boolean)**               | RTE Boolean signal generated by the PWM block.               |
| **Complementary PWM (RTE Boolean)** | RTE Boolean complementary signal generated by the PWM block. |

## Characteristics and limitations

| Characteristic     | Value           |
| ------------------ | --------------- |
| Direct Feedthrough | No              |
| Sample Time        | Fixed discrete. |
| Work Offline       | Yes             |
| Dimensionalized    | No              |


---

# 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/rt-events-library/rte-spwm.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.
