Generate square wave pulses at regular intervals
Simulink / Sources
The Pulse Generator block generates square wave pulses at regular intervals. The block waveform parameters, Amplitude, Pulse Width, Period, and Phase delay, determine the shape of the output waveform. The following diagram shows how each parameter affects the waveform.
The Pulse Generator block can emit scalar, vector, or matrix signals of any real data type. To emit a scalar signal, use scalars to specify the waveform parameters. To emit a vector or matrix signal, use vectors or matrices, respectively, to specify the waveform parameters. Each element of the waveform parameters affects the corresponding element of the output signal. For example, the first element of a vector amplitude parameter determines the amplitude of the first element of a vector output pulse. All the waveform parameters must have the same dimensions after scalar expansion. The data type of the output is the same as the data type of the Amplitude parameter.
The block output can be generated in timebased or samplebased modes, determined by the Pulse type parameter.
In timebased mode, Simulink^{®} computes the block output only at times when the output actually
changes. This approach results in fewer computations for the block output over the
simulation time period. Activate this mode by setting the Pulse
type parameter to Time based
.
The block does not support a timebased configuration that results in a constant output signal. Simulink returns an error if the parameters Pulse Width and Period satisfy either of these conditions:
$$\begin{array}{l}Period\text{}*\frac{PulseWidth}{100}=0\\ Period\text{}*\frac{PulseWidth}{100}=Period\end{array}$$
Depending on the pulse waveform characteristics, the intervals between changes in the block output can vary. For this reason, a timebased Pulse Generator block has a variable sample time. The sample time color of such blocks is brown (see View Sample Time Information for more information).
Simulink cannot use a fixedstep solver to compute the output of a timebased pulse generator. If you specify a fixedstep solver for models that contain timebased pulse generators, Simulink computes a fixed sample time for the timebased pulse generators. Then the timebased pulse generators simulate as sample based.
If you use a fixedstep solver and the Pulse type is Time based
, choose the step size such that the
period, phase delay, and pulse width (in seconds) are integer multiples of the
solver step size. For example, suppose that the period is 4
seconds, the pulse width is 75%
(that is, 3
s), and the phase delay is 1
s. In this case, the computed sample
time is 1
s. Therefore, choose a fixedstep size of
1
or a number that divides 1
exactly (for
example, 0.25
). To ensure this setting, select
auto
on the Solver pane of the
Configuration Parameters dialog box.
In samplebased mode, the block computes its outputs at fixed intervals that you
specify. Activate this mode by setting the Pulse type parameter
to Sample based
.
An important difference between the timebased and samplebased modes is that in timebased mode, the block output is based on simulation time, and in samplebased mode, the block output depends only on the simulation start, regardless of elapsed simulation time.
This block supports reset semantics in samplebased mode. For example, if a Pulse Generator block is in a resettable subsystem that hits a reset trigger, the block output resets to its initial condition.
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 
