Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 36 ยท Signals and Subsystems

Simulink Subsystems: Atomic, Enabled, Triggered and Action Subsystems

Learn how to create Simulink subsystems, the difference between virtual and atomic subsystems, and how enabled, triggered, function-call and action subsystems run conditionally.

A model with three hundred blocks on one canvas is unreadable. Subsystems let you group blocks into one block with its own inputs and outputs, so the top level shows the architecture and each subsystem shows the detail. They have a second power too: some subsystems run only when a condition is met, which models things like "only when the engine is on" or "once on every rising edge".

Simulink is not available on this site. The steps below are for the real product; Python stand-ins imitate enabled and triggered behavior so you can see how outputs and states behave.

Creating a subsystem

  1. Select the blocks you want to group (drag a rectangle around them).
  2. Press Ctrl+G or right-click > Create Subsystem from Selection.
  3. Simulink replaces the blocks by a Subsystem block. Lines that crossed the boundary become Inport (In1) and Outport (Out1) blocks inside it. Rename them, because their names label the ports on the outside.
  4. Double-click the subsystem to look inside. The breadcrumb path at the top left shows where you are; use the Up arrow to go back.
  5. To create an empty one, add a Subsystem block from Ports & Subsystems and open it.

You can also expand a subsystem back into its blocks (Expand Subsystem from the right-click menu).

Virtual versus atomic

By default a subsystem is virtual: it only organizes the diagram. When Simulink compiles, the blocks inside are treated as if they were at the parent level, and execution order mixes them with their neighbors. A subsystem can be made atomic (Block Parameters > Treat as atomic unit). An atomic subsystem executes as one unit: all blocks inside run together, in order, before anything else continues. Why it matters:

  • Code generation: an atomic subsystem can become its own C function, with a chosen Function packaging option and file name. See the Code Generation chapter.
  • Sample time: an atomic subsystem can have its own sample time.
  • Reuse: with Reusable function packaging one function serves several instances.
  • Loops: it can remove false algebraic loops, but may also create a real one (the unit needs all its inputs before any output).

Kinds of subsystem

Virtual Only for drawing
Atomic Runs as one unit
Enabled Runs while signal > 0
Triggered Runs on an edge

Conditional subsystems add control inputs.

1 / 2

Enabled subsystems

Add an Enable block inside a subsystem and an extra control input appears on top. The subsystem runs only while that control signal is greater than zero (positive). Configure:

  • States when enabling: held (blocks with state remember their value) or reset (states return to initial conditions each time).
  • Outport parameters > Output when disabled: held (keeps the last value) or reset (to an initial output value).

Typical use: a heater controller that is only active while mode == 1, or a diagnostic that runs only when the engine speed is above a limit.

Triggered subsystems

A Trigger block inside makes the subsystem run once per trigger event, defined by Trigger type: rising, falling, either, or function-call. The subsystem runs only at the event, then holds its outputs. For example, sample and hold a measurement when a pulse goes high.

You can combine Enable and Trigger for a subsystem that runs on an edge only when enabled. A function-call subsystem is triggered by a Function-Call Generator (or a Stateflow chart or an S-function) and is the basis of scheduling in embedded software.

Action subsystems: If and Switch Case

The If block evaluates conditions such as u1 > 5 and outputs action signals that run connected If Action Subsystems (each has an Action Port). Only one branch runs each step. The Switch Case block does the same for integer values. Outputs of such subsystems combine in a Merge block. See Routing, Switches and Buses.

Compared with a Switch block, which evaluates every input each step, an action subsystem skips the inactive branch, saving time and reproducing if/else in generated code.

Iterator subsystems

For Iterator and While Iterator subsystems repeat their content within one time step (like a loop in code), and For Each subsystems apply the same operation to each element of a vector or each bus element. Use them when an operation depends on the number of items, such as filtering N channels.

Practice with stand-ins

Python Stand-in: an enabled subsystem (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: a rising-edge triggered subsystem (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the second example the output only changes at steps 1, 5 and 7 (the rising edges) and holds otherwise: a classic sample and hold.

Design tips

  • Group by function (sensor processing, control law, actuator limits), not by screen space.
  • Keep inports and outports named and ordered logically; their order is the port order on the block.
  • Use atomic subsystems when you plan to generate separate functions or to test a unit alone.
  • Prefer action subsystems over many Switch blocks for large branches, because they save computation.
  • Beware of hidden state: enabled subsystems that hold state behave differently after being disabled and re-enabled.
  • If you find yourself copy-pasting the same subsystem, turn it into a library block: see Masks, Libraries and Model Reference.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What shortcut creates a subsystem from selected blocks?

    Ctrl+G groups the selection into a subsystem.
  2. 2. When does an enabled subsystem run?

    The Enable block makes it run while its control signal is positive.
  3. 3. What is a main benefit of an atomic subsystem for embedded code?

    Atomic subsystems execute as a unit and can map to a separate function in generated code.
  4. 4. Which block creates action signals for conditional branches?

    The If block outputs action signals for If Action Subsystems.

Summary

  • Subsystems (Ctrl+G) hide detail and structure the model; virtual ones only organize, atomic ones execute as a unit.
  • Enabled subsystems run while the control signal is positive; triggered ones run on edges; function-call subsystems are called by other blocks.
  • If and Switch Case with action subsystems run only the chosen branch, joined with Merge.
  • Held versus reset states and outputs define what a conditional subsystem remembers.

Next: Masks, Libraries and Model Reference