This example shows how a Shared Variable block works in a Hierarchical State Machine.
The Shared Variable block gets executed when its containing Finite State is active. In order to show this behavior, the hierarchical state machine in Figure 1 is considered.

Figure 1 - Hierarchical State Machine
Each of these Finite State has a diagram as listed in Figures 2, 3 and 4.

Figure 2 - Diagram from Finite State 1

Figure 3 - Diagram from Finite State 2

Figure 4 - Diagram from Finite State 3
The transitions are triggered as follows:
As can be seen, both of the diagrams of Figure 2 and Figure 3 are using the same Shared Variable. Nevertheless, the shared variable value will be updated only by the first finite state until 5s.
The Figure 5 shows the behavior of the Shared Variable value.

Figure 5 - Shared Variable 0 in a 15s simulation
In Figure 5, it is also possible to observe the signal after the second transition being triggered. As the diagram from Finite State 3 doesn't update the Shared Variable 0, its values remains constant.
The Shared Variable 1 is in the Finite State 3, Figure 4. Its value is updated only after 10s. Note that, by default, zero is assigned to a Shared Variable during its initialization.

Figure 6 - Shared Variable 1 in a 15s simulation
About MWF
MWF is a traditional Brazilian company that provides a wide range of electronic and mechatronic products for industry sectors such as automotive, agricultural machinery and aerospace.
Contact Us
Rua Doutor Siqueira, 139 / Sala 804 Campos dos Goytacazes - RJ, Brasil
contact@mwf-technologies.com
© 2018-2026 MWF. All rights reserved.