Documentation Center

  • Trial Software
  • Product Updates

Create an Enabled Subsystem

What Are Enabled Subsystems?

Enabled subsystems are subsystems that execute at each simulation step for which the control signal has a positive value.

An enabled subsystem has a single control input, which can be a scalar or a vector.

  • If the input is a scalar, the subsystem executes if the input value is greater than zero.

  • If the input is a vector, the subsystem executes if any one of the vector elements is greater than zero.

For example, if the control input signal is a sine wave, the subsystem is alternately enabled and disabled. This behavior is shown in the following figure, where an up arrow signifies enable and a down arrow disable.

The Simulink® software uses the zero-crossing slope method to determine whether an enable event is to occur. If the signal crosses zero and its slope is positive, then the subsystem becomes enabled. If the slope is negative at the zero crossing, then the subsystem becomes disabled. Note that a subsystem is only enabled or disabled at major time steps. Therefore, if zero-crossing detection is turned off and the signal crosses zero during a minor time step, then the subsystem will not become enabled (or disabled) until the next major time step.

Creating an Enabled Subsystem

You create an enabled subsystem by copying an Enable block from the Ports & Subsystems library into a Subsystem block. An enable symbol and an enable control input port is added to the Subsystem block.

Setting Initial Conditions for an Enabled Subsystem

You can set the initial output of an enabled subsystem using the subsystems Outport blocks. The initial output value can be either explicitly specified, or inherited from its input signal.

Specifying Initial Conditions.  To specify the initial output value of the subsystem:

  1. Double-click each Outport block in the subsystem to open its block parameters dialog box.

  2. In the Source of initial output value drop-down list, select Dialog.

  3. Specify a valid value for the Initial output parameter. Valid values include the empty matrix. But Inf and NaN are not valid values.

If you select Dialog, you can also specify what happens to the output when the subsystem is disabled. For more information, see the next section: Setting Output Values While the Subsystem Is Disabled.

Inheriting Initial Conditions.   The Outport block can inherit an initial output value for the subsystem from the following sources:

  • Output port of another conditionally executed subsystem

  • Merge block (with Initial output specified)

  • Function-Call Model Reference block

  • Constant block (simplified initialization mode only)

  • IC block (simplified initialization mode only)

The procedure you use to inherit the initial conditions of the subsystem differs depending on whether you are using classic initialization mode or simplified initialization mode.

To inherit initial conditions in classic initialization mode:

  1. Double-click each Outport block in the subsystem to open its block parameters dialog box.

  2. In the Source of initial output value drop-down list, select Dialog .

  3. Set the Initial output parameter to [] (empty matrix).

  4. Click OK.

    Note:   For all other driving blocks, specify an explicit initial output value.

To inherit initial conditions in simplified initialization mode:

  1. Double-click each Outport block in the subsystem to open its block parameters dialog box.

  2. In the Source of initial output value drop-down list, select Input signal.

  3. Click OK.

    The Initial output and Output when disabled parameters are disabled, and both values are inherited from the input signal.

For more information on classic and simplified initialization mode, see Underspecified initialization detection.

Setting Output Values While the Subsystem Is Disabled

Although an enabled subsystem does not execute while it is disabled, the output signal is still available to other blocks. While an enabled subsystem is disabled, you can choose to hold the subsystem outputs at their previous values or reset them to their initial conditions.

Open the block parameters dialog box for each Outport block and for the Output when disabled parameter, select one of the choices.

  • Choose held to maintain the most recent value.

  • Choose reset to revert to the initial condition. Set the Initial output to the initial value of the output.

    Note:   If you are connecting the output of a conditionally executed subsystem to a Merge block, set Output when disabled to held to ensure consistent simulation results.

    If you are using simplified initialization mode, you must select held when connecting a conditionally executed subsystem to a Merge block. For more information, see Underspecified initialization detection.

Setting States When the Subsystem Becomes Enabled

When an enabled subsystem executes, you can choose whether to hold the subsystem states at their previous values or reset them to their initial conditions.

To do this, open the Block Parameters: Enable dialog box and select one of the choices for the States when enabling parameter:

  • Choose held to cause the states to maintain their most recent values.

  • Choose reset to cause the states to revert to their initial conditions.

    Note:   If you are using simplified initialization mode, the subsystem elapsed time is always reset during the first execution after becoming enabled, whether or not the subsystem is configured to reset on enable.

    For more information on simplified initialization mode, see Underspecified initialization detection.

    Note:   For nested subsystems whose Enable blocks have different parameter settings, the settings on the child subsystem's dialog box override those inherited from the parent subsystem.

Outputting the Enable Control Signal

An option on the Enable block dialog box lets you output the enable control signal. To output the control signal, select the Show output port check box.

This feature allows you to pass the control signal down into the enabled subsystem, which can be useful where logic within the enabled subsystem is dependent on the value or values contained in the control signal.

Blocks that an Enabled Subsystem Can Contain

An enabled subsystem can contain any block, whether continuous or discrete. Discrete blocks in an enabled subsystem execute only when the subsystem executes, and only when their sample times are synchronized with the simulation sample time. Enabled subsystems and the model use a common clock.

    Note   Enabled subsystems can contain Goto blocks. However, only state ports can connect to Goto blocks in an enabled subsystem. In the sldemo_clutch model, see the Locked subsystem for an example of how to use Goto blocks in an enabled subsystem.

For example, this systemsystem contains four discrete blocks and a control signal. The discrete blocks are:

  • Block A, which has a sample time of 0.25 second

  • Block B, which has a sample time of 0.5 second

  • Block C, within the enabled subsystem, which has a sample time of 0.125 second

  • Block D, also within the enabled subsystem, which has a sample time of 0.25 second

The enable control signal is generated by a Pulse Generator block, labeled Signal E, which changes from 0 to 1 at 0.375 second and returns to 0 at 0.875 second.

The chart below indicates when the discrete blocks execute.

Blocks A and B execute independently of the enable control signal because they are not part of the enabled subsystem. When the enable control signal becomes positive, blocks C and D execute at their assigned sample rates until the enable control signal becomes zero again. Note that block C does not execute at 0.875 second when the enable control signal changes to zero.

Using Blocks with Constant Sample Times in Enabled Subsystems

Certain restrictions apply when you connect blocks with constant sample times (see Constant Sample Time) to the output port of a conditional subsystem.

  • An error appears when you connect a Model or S-Function block with constant sample time to the output port of a conditional subsystem.

  • The sample time of any built-in block with a constant sample time is converted to a different sample time, such as the fastest discrete rate in the conditional subsystem.

To avoid the error or conversion, either manually change the sample time of the block to a non-constant sample time or use a Signal Conversion block. The example below shows how to use the Signal Conversion block to avoid these errors.

Consider the following model ex_enabled_subsys_2.mdlex_enabled_subsys_2.mdl.

The two Constant blocks in this model have constant sample times. When you simulate the model, the Simulink software converts the sample time of the Constant block inside the enabled subsystem to the rate of the Pulse Generator. If you simulate the model with sample time colors displayed (see View Sample Time Information), the Pulse Generator and Enabled Subsystem blocks are colored red. However, the Constant and Outport blocks outside of the enabled subsystem are colored magenta, indicating that these blocks still have a constant sample time.

Suppose the model above is referenced from a Model block inside an enabled subsystem, as shown below. (See Model Reference.)

An error appears when you try to simulate the top model, indicating that the second output of the Model block may not be wired directly to the enabled subsystem output port because it has a constant sample time. (See Model Reference.)

To avoid this error, insert a Signal Conversion block between the second output of the Model block and the Outport block of the enabled subsystem.

This model simulates with no errors. With sample time colors displayed, the Model and Enabled Subsystem blocks are colored yellow, indicating that these are hybrid systems. In this case, the systems are hybrid because they contain multiple sample times.

Was this topic helpful?