Local variables and phases, Discrete semantics – National Instruments AutoCode NI MATRIX User Manual

Page 135

Advertising
background image

Chapter 5

Generated Code Architecture

© National Instruments Corporation

5-27

AutoCode Reference

Local Variables and Phases

A local variable cannot be used to pass data between phases, because the
different phases occur at different locations in the execution order of the
whole subsystem or procedure. That is, local variables can be reused for
other BlockScript block.

Only inputs, outputs, parameters, and states are guaranteed to be correct
between phases. This is shown in Example 5-7 where, within the STATE
update, the output is used to pass data between the phases.

Discrete Semantics

SystemBuild has two types of state categories for a BlockScript block in a
discrete subsystem: States and Next States. You can specify more than one
variable and different data types for the state variables, as with inputs and
outputs. The State variable(s) are intended to represent state data from the
previous time point. The State variable(s) should only be used for read-only
purposes. The Next State variables are intended to represent the state data
to be used in the next time point. The Next States variables can be both read
and written. The very last thing that a subsystem does is to swap the data
from the Next State variables into State variables for the next time point.
You can view state data as a way to provide double-buffered persistent
data.

Example 5-7 shows how to keep a running total of the input values.

Example 5-7

Discrete BlockScript Block Example (Keeping a Running Total)

Inputs: u;

Outputs: y;

Environment: (INIT, OUTPUT, STATE);

States: current_total;

Next_States: new_total;

float u,y,current_total, new_total;

if OUTPUT then

if INIT then

current_total = 0.0;

endif;

y = u + current_total;

endif;

if STATE then

Advertising