Adding an Internal Variable to an ST Program
To add an internal variable to an ST program, you need to define the internal variable in a VAR list. You can then use the internal variable throughout the ST program.
You have to define internal variables in the following format:
VAR
<Value Name> : <Value Type>;
END_VAR
Where <Value Name> is the name you allocate to the internal variable, and <Value Type> is the data type of the internal variable (see Built-In Data Types and see Derived Data Types).
You can then refer to the internal variable by name in your ST program.
Example:
VAR
TimeCount:TIME;
END_VAR
VAR
TimedStart AT %M(.Power.StartMotor.CurrentState):BOOL;
END_VAR
IF TimeCount > T#60s THEN
TimedStart := TRUE;
ELSE
TimedStart := FALSE;
END_IF;
This program uses an internal variable to act as a timer. When the timer exceeds 60, the state of a direct variable (TimedStart) changes from FALSE to TRUE.
The internal variable is defined in a separate VAR list to the direct variable. This is because internal variables and direct variables cannot be listed in the same variables list. To overcome this, you need to create multiple VAR lists. Each VAR list needs to be structured in the same way as any other VAR list except that the END_VAR only has a semi-colon at the end of the final VAR list.
For more information on data types such as BOOL, please refer to Built-In Data Types. You can also create custom data types that allow you to group internal variables and define meaningful names for value types (see Derived Data Types).
For information on Logic keywords that you can use to control the behavior of the program, such as IF and THEN see Controlling the Flow of the Program.