The default initialization value is 0 for all declarations, but you can add user-defined initialization values in the declaration of each variable and data type.
The user-defined initialization is brought about by the assignment operator :=
and can be any valid ST expression. Thus, constant values as well as other variables or functions can be used to define the initialization value. Verify that a variable used for the initialization of another variable is already initialized itself.
Example of valid variable initializations:
VAR
var1:INT := 12; * Integer variable with initial value of 12. *
x : INT := 13 + 8; * Integer value defined an expression with literal values.*
y : INT := x + fun(4); * Integer value defined by an expression containing a function call. NOTE: Be sure that any variables used in the variable initialization have already been defined. *
z : POINTER TO INT := ADR(y); * POINTER is not described by the IEC61131-3: Integer value defined by an address function; NOTE: The pointer will not be initialized if the declaration is modified online. *
END_VAR
For further information, refer to the following descriptions:
initializing arrays
initialization of structures
initialization of a variable with a subrange type
For further information regarding initialization order, refer to the Attribute global_init_slot.