Stateflow | ![]() ![]() |
Flow Diagram Notation with Connective Junctions
Flow diagram notation uses connective junctions to represent common code structures like for
loops and if-then-else
constructs without the use of states. And by reducing the number of states in your Stateflow diagrams, flow diagram notation produces more efficient generated code that helps optimize memory use.
Flow diagram notation employs combinations of the following:
Flow diagram notation, states, and state-to-state transitions seamlessly coexist in the same Stateflow diagram. The key to representing flow diagram notation is in the labeling of the transitions (specifically the use of action language) as shown by the following examples.
Connective Junction with All Conditions Specified Example
In the example on the left, if state A
is active when event e
occurs, the transition from state A
to any of states D
, E,
or F
takes place if one of the conditions [c1]
, [c2]
, or [c3]
is met.
In the equivalent representation on the right, a transition from the source state to a connective junction is labeled by the event. Transitions from the connective junction to the destination states are labeled by the conditions. If state A
is active when event e
occurs, the transition from A
to the connective junction occurs first. The transition from the connective junction to a destination state follows based on which of the conditions [c1]
, [c2]
, or [c3]
is true. If none of the conditions is true, no transition occurs and state A
remains active.
See If-Then-Else Decision Construct Example for more information on the semantics of this notation.
Connective Junction with One Unconditional Transition Example
The transition A
to B
is valid when A
is active, event E_one
occurs, and [C_one]
is true. The transition A
to C
is valid when A
is active, event E_one
occurs, and [C_two]
is true. Otherwise, given A
is active and event E_one
occurs, the transition A
to D
is valid. If you do not explicitly specify condition [C_three]
, it is implicit that the transition condition is not [C_one]
and not [C_two]
.
See If-Then-Else Decision Construct Example for information on the semantics of this notation.
Connective Junction--Self-Loop Example
In some situations, the transition event occurs but a condition is not met. No transition is taken, but an action is generated. You can represent this situation by using a connective junction or a self-loop transition (transition from state to itself).
In the example on the left, if State A
is active and event e
occurs and the condition [c1]
is met, the transition from A
to B
is taken, generating action a1
. The transition from state A
to state A
is valid if event e
occurs and [c1]
is not true. In this self-loop transition, the system exits and reenters state A
, and executes action a2
.
In the equivalent representation on the right, the use of a connective junction makes it unnecessary to specify the implied condition [~c1]
explicitly.
See Self-Loop Transition Example for more information on the semantics of this notation.
Connective Junction and For Loops Example
This example shows a combination of flow diagram notation and state transition notation. Self-loop transitions to connective junctions can be used to represent for
loop constructs.
In state A
, event E
occurs. The transition from state A
to state B
is valid if the conditions along the transition path are true. The first segment of the transition does not have a condition, but does have a condition action. The condition action, {i=0}
, is executed. The condition on the self-loop transition is evaluated as true and the condition actions {i++;func1()}
execute. The condition actions execute until the condition [i<10]
is false. The condition actions on both the first segment and the self-loop transition to the connective junction effectively execute a for
loop (for i
values 0 to 9 execute func1()
). The for
loop is executed outside the context of a state. The remainder of the path is evaluated. Because there are no conditions, the transition completes at the destination, state B
.
See For Loop Construct Example for information on the semantics of this notation.
Flow Diagram Notation Example
This example shows a real-world use of flow diagram notation and state transition notation. This Stateflow diagram models an 8-bit analog-to-digital converter (ADC).
Consider the case when state Sensor.Low
is active and event UPDATE
occurs. The inner transition from Sensor
to the connective junction is valid. The next transition segment has a condition action, {start_adc()}
, which initiates a reading from the ADC. The self-loop on the second connective junction repeatedly tests the condition [adc_busy()]
. This condition evaluates as true once the reading settles (stabilizes) and the loop completes. This self-loop transition is used to introduce the delay needed for the ADC reading to settle. The delay could have been represented by another state with some sort of counter. Using flow notation in this example avoids an unnecessary use of a state and produces more efficient code.
The next transition segment condition action, {sensorValue=read_adc()}
, puts the new value read from the ADC in the data object sensorValue
. The final transition segment is determined by the value of sensorValue
. If [sensorValue <100]
is true, the state Sensor.Low
is the destination. If [sensorValue >200]
is true, the state Sensor.High
is the destination. Otherwise, state Sensor.Normal
is the destination state.
See Flow Diagram Notation Example for information on the semantics of this notation.
Connective Junction from a Common Source to Multiple Destinations Example
Transitions A
to B
and A
to C
share a common source state A
. An alternative representation uses one arrow from A
to a connective junction, and multiple arrows labeled by events from the junction to the destination states B
and C
.
See Transitions from a Common Source to Multiple Destinations Example for information on the semantics of this notation.
Connective Junction Common Events Example
Suppose, for example, that when event e1
occurs, the system, whether it is in state A
or B
, transfers to state C
. Suppose that transitions A
to C
and B
to C
are triggered by the same event e1
, so that both destination state and trigger event are common to the transitions. There are three ways to represent this:
A
and B
to C
, each labeled with e1
A
and B
in one superstate S
, and drawing one transition from S
to C
, labeled with e1
A
and B
to a connective junction, then drawing one transition from the junction to C
, labeled with e1
This Stateflow diagram shows the simplification using a connective junction.
See Transitions from a Source to a Destination Based on a Common Event Example for information on the semantics of this notation.
![]() | Connective Junctions | History Junctions | ![]() |