Schedule Multiple Subsystems in a Single Step

The ladder logic scheduler design pattern allows you to specify the order in which multiple Simulink® subsystems execute in a single time step. The model sf_ladder_logic_scheduler illustrates this design pattern.

The Ladder Logic Scheduler chart contains the following logic:

Key Behaviors of Ladder Logic Scheduler

The key behaviors of the ladder logic scheduler are:

Function-Call Output Events Trigger Multiple Subsystems

In a given time step, the Stateflow® chart broadcasts a series of function-call output events to trigger the execution of three function-call subsystems — A1, A2, and A3 — in the Simulink model in an order determined by the ladder logic scheduler. Here is the sequence of activities during each time step:

  1. The Simulink model activates the Stateflow chart Edge to Function at a rising edge of the 1-millisecond pulse generator.

  2. The Edge to Function chart broadcasts the function-call output event call to activate the Stateflow chart Ladder Logic Scheduler.

  3. The Ladder Logic Scheduler chart broadcasts function-call output events to trigger the function-call subsystems A1, A2, and A3, based on the values of inputs u1 and u2 (see Flow Chart Determines Order of Execution).

Flow Chart Determines Order of Execution

The Ladder Logic Scheduler chart uses Stateflow flow charting capabilities to implement the logic that schedules the execution of the Simulink function-call subsystems. The chart contains a Stateflow flow chart that resembles a ladder diagram. Each rung in the ladder represents a rule or condition that determines whether to execute one of the Simulink function-call subsystems. The flow logic evaluates each condition sequentially, which has the effect of scheduling the execution of multiple subsystems within the same time step. The chart executes each subsystem by using the send action to broadcast a function-call output event (see Directed Local Event Broadcast Using send).

Here is the sequence of activities that occurs in the Ladder Logic Scheduler chart in each time step:

  1. Assign output y to input u1.

  2. If u1 is positive, send function-call output event A1 to the Simulink model.

    The subsystem connected to A1 executes. This subsystem multiplies its input by a gain of 2 and passes this value back to the Stateflow Ladder Logic Scheduler chart as input u2. Control returns to the next condition in the Ladder Logic Scheduler.

  3. If u2 is positive or zero, send function-call output event A2 to the Simulink model.

    The subsystem connected to A2 executes. This subsystem outputs its input value unchanged. Control returns to the next condition in the Ladder Logic Scheduler.

  4. If u1 and u2 are positive, send function-call output event A3 to the Simulink model.

    The subsystem connected to A3 executes. This subsystem multiplies its input by a gain of 1.

  5. The Ladder Logic Scheduler chart goes to sleep.

Run the Ladder Logic Scheduler

To run the sf_ladder_logic_scheduler model, follow these steps:

  1. Open the model by clicking sf_ladder_logic_schedulersf_ladder_logic_scheduler or typing sf_ladder_logic_scheduler at the MATLAB® command prompt.

  2. Open the Scope block.

  3. Start simulation.

    The scope shows how output y changes, depending on which subsystems the Ladder Logic Scheduler chart calls during each time step.

      Tip   If you keep the chart closed, the simulation runs much faster. For other tips, see Speed Up Simulation.

Was this topic helpful?