# PWM Generator

Generate pulse width modulated signal or waveform

• Library:
• Simscape / Electrical / Control / Pulse Width Modulation

## Description

The PWM Generator block implements a PWM generator. The pulse width modulation technique controls power transfer from one electrical component to another by quickly switching between full power transfer and no power transfer.

### Working Principle

The PWM generator block outputs either 1 when the duty cycle is greater than the carrier counter value, or 0 otherwise. You can set the period of each cycle by specifying the timer period Tper. You can change the initial output, or phase, of the PWM output by specifying one of three types of carrier counters:

• Up counter — The PWM output signal initializes at the start of the on cycle. This graphic shows the carrier counter signal and the corresponding PWM output.

• Down counter — The PWM output signal initializes at the start of the off cycle. This graphic shows the carrier counter signal and the corresponding PWM output.

• Up-down counter — The PWM output signal initializes halfway through the on cycle. This graphic shows the carrier counter signal and the corresponding PWM output.

## Ports

### Input

expand all

Duty cycle in the range [0,1].

Data Types: single | double

### Output

expand all

Pulse width modulation signal.

Data Types: single | double

## Parameters

expand all

Use the carrier counter strategy to change the initial behavior of the PWM output:

• Up counter — PWM output begins at the start of the on state.

• Down counter — PWM output begins at the start of the off state.

• Up-down counter — PWM output begins in the middle of the on state.

PWM timer period.

If you set Carrier counter to Up counter or Down counter, the Timer period (s) parameter is specified as $\frac{1}{{f}_{sw}}$, where ${f}_{sw}$ is the switching frequency. If you set Carrier counter to Up-down counter, the Timer period (s) parameter is specified as $\frac{1}{2{f}_{sw}}$.

Phase delay, in seconds. Add a phase delay to change the initial state of the counter.

Sample time for the block. For continuous-time simulation, set to zero. For discrete-time simulation, to ensure adequate resolution in the generated signal, specify a positive value that is less than or equal to Tper/10, where Tper is the Timer period (s).

## Version History

Introduced in R2017b