Model Synchronous Subsystems by Using Parallel Decomposition
To implement operating modes that run concurrently, use parallel states in your Stateflow® chart. For example, as part of a complex system design, you can employ parallel states to model independent components or subsystems that are active simultaneously.
The decomposition type of a chart or state specifies whether the chart or state contains exclusive states or parallel states:
Exclusive states represent mutually exclusive modes of operation. No two exclusive states at the same hierarchical level can be active or execute at the same time. Stateflow charts represent each exclusive state by a solid rectangle.
Parallel states represent independent modes of operation. Two or more parallel states can be active at the same time, although they execute in a serial fashion. Stateflow charts represent each parallel state by a dashed rectangle with a number that indicate the execution order.
You can combine exclusive and parallel states in your Stateflow chart by setting the state decomposition at different levels of your state hierarchy. The default state decomposition type is
Exclusive (OR). To change the decomposition type to
AND (Parallel), right-click the parent state and select Decomposition > AND (Parallel).
Model an Air Temperature Controller
This example uses parallel decomposition to model an air controller that maintains air temperature at 120 degrees in a physical plant.
At the top level, the air controller chart has two exclusive states,
PowerOn. The chart uses exclusive (OR) decomposition because controller cannot be on and off at the same time.
The controller operates two fans. The first fan turns on when the air temperature rises above 120 degrees. The second fan provides additional cooling when the air temperature rises above 150 degrees. The chart models these fans as parallel substates,
FAN2, of the top-level state
PowerOn. Because the fans operate as independent components that turn on or off depending on how much cooling is required,
PowerOn uses parallel (AND) decomposition to ensure that both substates are active when the controller is turned on.
Except for the operating thresholds, the fans are modeled by states with an identical configuration of substates and transitions that reflects the two modes of fan operation,
Off. Because neither fan can be on and off at the same time,
FAN2 have exclusive (OR) decomposition.
PowerOn, a third parallel state called
SpeedValue represents an independent subsystem that calculates the number of fans that have cycled on at each time step. The Boolean expression
in(FAN1.On) has a value of 1 when the
On state of
FAN1 is active. Otherwise,
in(FAN1.On) equals 0. Similarly, the value of
in(FAN2.On) represents whether
FAN2 has cycled on or off. The sum of these expressions indicates the number of fans that are turned on during each time step.
Specify Order of Execution for Parallel States
SpeedValue are active concurrently, these states execute in serial fashion during simulation. The numbers in the upper-right corners of the states specify the order of execution. The rationale for this order of execution is:
FAN1executes first because it cycles on at a lower temperature than
FAN2. It can turn on regardless of whether
FAN2is on or off.
FAN2executes second because it cycles on at a higher temperature than
FAN1. It can turn on only if
FAN1is already on.
SpeedValueexecutes last so it can observe the most up-to-date status of
By default, Stateflow assigns the execution order of parallel states based on the order you add them to the chart. To change the execution order of a parallel state, right-click the state and select a value from the Execution Order drop-down list.
Explore the Example
This example contains a Stateflow chart called
Air Controller and a Simulink® subsystem called
Based on the air temperature of the physical plant, the chart turns on the fans and outputs the number of running fans,
airflow, to the subsystem. This value determines the cooling activity factor, , according to these rules:
airflow= 0 — No fans are running. The air temperature does not decrease because .
airflow= 1 — One fan is running. The air temperature decreases according to the cooling activity factor .
airflow= 2 — Two fans are running. The air temperature decreases according to the cooling activity factor .
The Physical Plant subsystem updates the air temperature, , inside the plant based on the equations
is the initial temperature. The default value is 70°.
is the ambient temperature. The default value is 160°.
is the heat transfer factor for the plant. The default value is 0.01.
is the cooling activity factor that corresponds to
The new temperature determines the amount of cooling at the next time step of the simulation.