Variable Operators
The Variable operator stores a signal value that can change during schema execution. For instance, it may store a system set-point or a tuning parameter that a plant operator or design engineer may wish to modify at runtime (while the controller is executing).
As indicated in the previous section, what makes Variable operators particularly useful is that more than one of them can reference the very same signal, and thereby serve to bind separate program segments. Multiple Variable operators will reference the same signal value if they have the same name and scope. In the sample schema pictured in Figure 5.1, an error signal is computed and stored in a Variable named fError_l. Another Variable operator elsewhere in the schema has the same name, fError_l, and is used to source a Numeric Display operator. While the two Variable operators are distinct objects in the schema, they reference the very same error signal---namely the difference between process (PV) and setpoint (SP) signals, so that the value computed by the Subtraction operator is shown on the Numeric Display.
(a)
(b)
Figure 5.1. (a) Sample use of Variable operator referencing the same signal. (b) Equivalent schema circuit.
In other words, the two instances of the fError_l variable are akin to explicitly connecting a signal wire between the output of the Subtraction operator and the input of the Numeric Display operator as shown in Figure 5.1b.
The use of Variable operators as virtual signal connections is a good technique for making schemas more readable. It offers an alternative to direct connections, thereby avoiding situations where signals must cross over each other or where long connections must be used to zigzag around other objects. But Variable operators not only serve to bind signals within the same schema, they can also bind signals across schemas and/or across modules in a node. In other words, they allow a signal computed in one schema or module, to be referenced in another schema or module. Variable operators have a scope attribute that determines their access range---Local, Module, or Global. A variable with Local scope may only be referenced within the same schema document. A variable with Module scope may be referenced within any schema executing in the same module (i.e., the parent schema linked to the module, any of its sub-schemas, or any of its sub-schemas' sub-schemas.). A variable with Global scope may be referenced within any schema executing within any module in the same node.
The signal name that a Variable operator references is specified in its property window (i.e., set the Signal Name property to the desired text string). These names may not contain periods, as the period is used to add schema names when variables are used across certain schema boundaries. Other special characters are also forbidden. Avoid slashes (\ and /), greater-than and less-than signs (< >) double-quotes ("), single-quotes ('), commas (,) and colons and semicolons (:,;) . Design Pad G4 automatically appends the characters "l", "_m", or "_g" to the _Variable signal name according to its scope, Local, Module, or Global, respectively.
Variable operators for three data-types are available: Float Variables (red signals) store analog IEEE floating point values, Boolean Variables (blue signals) store digital values, Structure Variables (green signals) store packaged data signals. In addition to binding signals from disparate schemas, Boolean Variable operators also serve as the triggering mechanism to initiate a transition in a state-transition diagram (see section 5.3 for more information).
The sample schema of Figure 5.1 includes one instance of Float Variable fError_l where the input pin is visible and the output pin is not; and one instance where the reverse it true. In the first instance, the variable is said to be of type Input-Only and in the second instance Output-Only. (A Variable operator may also be of type Input-Output where both pins are visible, or None where neither pin is visible.) An Input-Only (or Input-Output) Variable operator, sets the signal value that it references equal to the value of its input pin. Great care must be taken when two or more distinct Input type Variable operators represent the same signal. Consider the schema of Figure 5.2 in which two distinct Variable operators representing the same signal--fSignal_m--are fed by different constant values.
Figure 5.2. Two input Variables represent the same
signal. What value will the signal be set to?
If a device were to execute the schema of Figure 5.2, what value (3 or 5) would fSignal_m assume? The answer is not definitive---it depends on which operator executes last. In fact, if the schema contained several other operators, the result would be even more unpredictable as it is possible that the execution order could have one Variable compute first, then other operators, then the second Variable, then other operators. So the signal value could be 3 during part of the computation cycle (for some operators) and 5 during another part of the cycle (for other operators).
Design Pad G4 explicitly disallows the same variable signal from being set in multiple locations within the same schema. That is, an error is issued at compile-time when the schema above is processed. However, the ability to set the same signal from different sub-schemas is very much desirable so Design Pad G4 allows it. For example, it may be desirable to set the same signal to a different value depending on which state sub-schema is currently active.
Right click on a variable operator to reveal two important options – Reference and Edit\View Notes. Selecting Reference displays the places a variable is used in the current and other schemas, if applicable. Note in the reference list in Figure 5.3 that the variable is used in multiple schemas, as listed in the Schema Path field. Each schema path separates the levels of calling schemas with a period. Each reference includes its Type - Input, Output or Input-Output, and the Filename containing the referencing schema. The Reference List would contain only those uses of a local variable in the current schema.
Figure 5.3. Variable Reference List
Use Variable Notes to document what variables represent in a schema or across the scope of a module or node. Select Edit\View Notes to enter or review the notes for a variable operator. Instance notes describe the variable's use in the current schema. Scope notes describe what the variable represents throughout the schemas in the module or node. Figure 5.4 shows the dialog used to enter the notes for a variable operator. A variable's fully qualified name, including its scope indication, and any notes are displayed when you hover over the operator. The instance note appears first, followed by any scope note (Figure 5.5).
Figure 5.4. Variable Notes
Figure 5.5. Hover to Display Variable Notes