Documentation

Pulse Generator

Generate square wave pulses at regular intervals

Library

Sources

Description

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 can emit scalar, vector, or matrix signals of any real data type. To cause the block to emit a scalar signal, use scalars to specify the waveform parameters. To cause the block 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.

This block output can be generated in time-based on sample-based modes, determined by the Pulse type parameter.

Time-Based Mode

In time-based 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 atime-based configuration that results in a constant output signal. Simulink returns an error if the parameters Pulse Width and Period satisfy either of these conditions:

Period*PulseWidth100=0Period*PulseWidth100=Period

Depending on the pulse waveform characteristics, the intervals between changes in the block output can vary. For this reason, a time-based 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 fixed-step solver to compute the output of a time-based pulse generator. If you specify a fixed-step solver for models that contain time-based pulse generators, Simulink computes a fixed sample time for the time-based pulse generators. Then the time-based pulse generators simulate as sample based.

If you use a fixed-step 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 fixed-step size of 1 or a number that divides 1 exactly (e.g., 0.25). You can guarantee this by setting the fixed-step solver step size to auto on the Solver pane of the Configuration Parameters dialog box.

Sample-Based Mode

In sample-based 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 time-based and sample-based modes is that in time-based mode, the block output is based on simulation time, and in sample-based mode, the block output depends only on the simulation start, regardless of elapsed simulation time. For more information, see the example Difference Between Time-Based and Sample-Based Pulse Generation Modes.

This block supports reset semantics in sample-based mode. For example, if a Pulse Generator is in a resettable subsystem that hits a reset trigger, the block output resets to its initial condition.

Data Type Support

The Pulse Generator block outputs real signals of any numeric data type that Simulink supports, including fixed-point data types. The data type of the output signal is the same as that of the Amplitude parameter.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

Pulse type

The pulse type for this block: Time based or Sample based. The default is Time based.

Time (t)

Specifies whether to use simulation time or an external signal as the source of values for the output pulse's time variable. If you specify an external source, the block displays an input port for connecting the source. The output pulse differs as follows:

  • Use simulation time: The block generates an output pulse where the time variable equals the simulation time.

  • Use external signal: The block generates an output pulse where the time variable equals the value from the input port, which can differ from the simulation time.

Amplitude

The pulse amplitude. The default is 1.

Period

The pulse period specified in seconds if the pulse type is time-based or as number of sample times if the pulse type is sample-based. The default is 10 seconds.

Pulse Width

The duty cycle specified as the percentage of the pulse period that the signal is on if time-based or as number of sample times if sample-based. The default is 5 percent.

Phase delay

The delay before the pulse is generated specified in seconds if the pulse type is time-based or as number of sample times if the pulse type is sample-based. The default is 0 seconds.

Sample time

The length of the sample time for this block in seconds. This parameter appears only if the block's pulse type is sample-based. See Specify Sample Time in the Simulink User's Guide for more information.

Interpret vector parameters as 1-D

If you select this check box and the other parameters are one-row or one-column matrices, after scalar expansion, the block outputs a 1-D signal (vector). Otherwise the output dimensionality is the same as that of the other parameters. See Determining the Output Dimensions of Source Blocks.

Examples

The following Simulink examples show how to use the Pulse Generator block:

Difference Between Time-Based and Sample-Based Pulse Generation Modes

This example shows the difference in the behavior of the Pulse Generator block in time-based and sample-based modes.

Consider a model with two Pulse Generator blocks. In one block, the Pulse type parameter is set to Time based. In the other block, it is set to Sample based. Both blocks are set up to output a Boolean pulse of 10 seconds: 5 seconds on followed by 5 seconds off. The simulation runs for 15 seconds from a start time of 3 seconds to a stop time of 18 seconds, specified in the Model Configuration Parameters dialog box. The figure shows the block diagram for this model and the simulation output in the Scope block.

You can see that simulation output starts at 3 seconds, as expected. Notice that the time-based Pulse Generator produces a logical on for only 2 seconds, after which its output changes to off at t = 5 seconds. This is because this block starts computing its output from t = 0 seconds, even though it doesn't output it until the simulation starts at t = 3 seconds. The time-based block depends on simulation time for its output.

The sample-based block outputs a pulse of 5 seconds on followed by 5 seconds off. In this case, the blocks output does not depend on simulation time, and starts only when the simulation starts.

Characteristics

Sample Time

Inherited

Scalar Expansion

Yes, of parameters

Dimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?