# PWM

Generate ideal pulse width modulated signal corresponding to input duty cycle

Since R2020b

Libraries:

## Description

Use the PWM block to generate an ideal pulse width modulated signal.

Pulse-width modulation (PWM) is a technique for encoding an analog signal using square pulses. This encoding is achieved by controlling the fraction of one period of the square wave that is set to high. This fraction is the duty cycle of the signal. The relationship between the modulated signal and the input duty cycle can be simply described as:

`$\overline{y}=D{y}_{max}+\text{​}\left(1-D\right){y}_{min}$`

where ymax and ymin are the upper and lower bounds of the output signal, respectively. For the PWM block, the duty cycle is constrained to `[0,1]`. The ideal PWM signal is proportional to the duty cycle D.

## Ports

### Input

expand all

Desired duty cycle of the pulse P, specified as scalar within the range [0,1].

Data Types: `double`

### Output

expand all

PWM signal corresponding to the input duty cycle.

Data Types: `double`

## Parameters

expand all

Time between rising edges of consecutive pulses of the output signal. A small value represents a high-frequency pulse.

#### Programmatic Use

 Block Parameter: `Period` Type: string | character vector Values: real scalar Default: `'1'`

Specify an initial delay or phase delay for the generated PWM signal, in seconds.

#### Programmatic Use

 Block Parameter: `InitialDelay` Type: string | character vector Values: numeric scalar Default: `0`

Enable this parameter to break algebraic loops containing the PWM block.

Note

Enabling this parameter causes a signal value of 0 or below, which causes the duty cycle input to throw an error.

#### Programmatic Use

 Block Parameter: `DisallowZeroDutyCycle` Type: string | character vector Values: `'on'` | `'off'` Default: `'off'`

Specify when the block executes and the sample time for the output signal.

• `off` — Block executes each time the delay for an input sample elapses. Output signal has fixed-in-minor sample time.

• `on` — Block executes at a fixed rate you specify using the Sample time parameter. Output signal has the sample time you specify using the Sample time parameter.

When you select Run at fixed time intervals:

• The delay signal values must be greater than the value you specify for the Sample time parameter.

• Delay signal values that are not integer multiples of the specified sample time are rounded down to the nearest integer multiple of the sample time. For example, if the sample time is `0.1` and the delay signal value is `0.68`, the software rounds the delay to `0.6`.

#### Programmatic Use

 Block Parameter: `RunAtFixedTimeIntervals` Type: string | character vector Values: `'on'` | `'off'` Default: `'off'`

Block execution rate and output signal sample time. The delay signal values must be greater than the specified sample time.

When the delay signal value is not an integer multiple of the specified sample time, the software rounds the delay value down to the closest value that is an integer multiple of the sample time. For example, if the sample time is `0.1` and the delay value is `0.68`, the software rounds the delay to `0.6`.

#### Dependencies

To enable this parameter, select Run at fixed time intervals.

#### Programmatic Use

 Block Parameter: `SampleTime` Type: string | character vector Values: numeric scalar Default: `0.1`

## Block Characteristics

 Data Types `double` Direct Feedthrough `no` Multidimensional Signals `no` Variable-Size Signals `no` Zero-Crossing Detection `no`

expand all

## Version History

Introduced in R2020b