Generate ideal pulse width modulated signal corresponding to input duty cycle
Simulink / Discontinuities
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:
where ymax and ymin are the upper and lower bounds of the duty cycle, respectively. For the PWM block, the duty cycle is constrained to [0,1]. Thus the idealized PWM signal is proportional to the duty cycle D.
D— Duty Cycle
Desired duty cycle of the pulse P, specified as scalar within the range [0,1].
Port 1— Output pulse
PWM signal corresponding to the input duty cycle.
Period (s)— Pulse width
Time between rising edges of consecutive pulses of the output signal. A smaller value represents a higher frequency pulse.
Run at fixed step intervals— Choose continuous or discrete-time behavior
Select whether the block should operate in continuous or discrete sampling modes.
By default, the block uses
continuous sampling mode as it
improves simulation performance with variable step solvers.
discrete sampling mode if you need to:
use a fixed-step solver
sample the block output
Sampling rate— Set pulse resolution
Specify the rate at which the block samples input duty cycle signal. This sampling rate becomes the resolution of the output pulse signal.
This parameter requires that Sampling mode is set to
Disallow zero duty cycle— Avoid algebraic loops
Enable this parameter to break algebraic loops containing the PWM block.
Enabling this parameter casues a signal value of 0 or below for the Duty Cycle input to throw an error.
For a pulse starting at time tk
where pw is the pulse width. For a given period P, pw is proportional to the duty cycle D
In Discrete sampling mode, the input duty cycle signal is sampled at the rate specified by the Sampling rate parameter.
For a specified sampling rate tS , the number of samples needed for a pulse of width pw can be expressed as follows
where nP is the number of samples needed to simulate a pulse of period P.
Consider a nominal pulse of period P with the sampling rate of the block set to be tS= 0.25 P. The number of samples needed for one period of the pulse, nP= 4. Thus, for the input duty cycle D= 0.47 , the number of samples n pw is floored to = 1. Therefore, the pulse is high for 1 of the 4 samples in the period.