Working With Shared Variables

Shared variables work exactly as they were physical I/O's. However they are meant to be used as virtual I/Os in the following scopes:

  • Inside signal flow diagrams.
  • Amongst Finite States in Hierarchical State Machines.
  • Amongst Tasks.

At the beginning of a task, values of shared variables are sampled from a memory table. The sampled values remain unchanged during the whole task execution. At the end of a task computation, the current values of the shared variables are updated into their memory table.

The diagram below can be used to illustrate the general process:

Figure 1 - Diagram using Shared Variable Input and Output blocks

Figure 2 - Simulation Information

In Figure 2, it is possible to see how long each block takes to be executed and complete the computation cycle:

  • Sampling gets executed at first. This corresponds to the Shared Variable Input.
  • It is followed by intermediate computation operations, when all the math blocks in Figure 1 get executed.
  • Finally, the results get assignment to the Shared Variable Output block.

Three additional examples illustrate the most common principles applicable when using shared variables:

  1. In signal flow diagrams: Shared Variable I/Os are not Goto and From blocks!
  2. In Hierarchical State Machines: Conditional execution implies conditional memory table update.
  3. Between tasks: priority-based execution assures predictable memory update.

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.