Main Content

PWM

Generate ideal pulse width modulated signal corresponding to input duty cycle

Since R2020b

  • PWM block icon

Libraries:
Simulink / Discontinuities

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:

y¯=Dymax+(1D)ymin

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.

Examples

expand all

This example shows you how to control a boost converter using the PWM block in Simulink. the boost converter in this model uses the Boost Converter (Simscape Electrical) block from the Simscape™ Electrical™ library.

A PWM signal is used to control the switching device, or gate, of the boost converter. The PID controller generates the command signal, or the duty cycle, to track the desired step-up voltage (Vref) of 18V

This is a relatively high frequency application; the switching gate operates at around 200kHz. Therefore, a pulse period of 1/200,000 or 5e-6s is chosen for the PWM signal.

Given the small time steps, the boostconverter_pwm model provided with the example is loaded from a steady state at 0.069s.

A visualization of the boost converter operation around the 0.1s mark is shown below.

For alternate physical modeling implementations of PWM control, see Pulse Width Modulation (Simscape Electrical).

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

Algorithms

expand all

Extended Capabilities

Version History

Introduced in R2020b

See Also

Topics