Retain variables and persistent variables
Retain variables
The controller automatically saves retain variables in the event of voltage failure. In this way, they remain available when operation resumes. Retain variables are reinitialized when devices are reset or a new PLC program is downloaded. The values are preserved in the event of an online change.
Example
The values of a drive system which can no longer be read out from the machine due to a voltage failure should be persistent. These values should also be persistent if the corresponding value only changes through the influence of the PLC.
|
Variable
|
Use case
|
Storage
|
|
Thermal sensor
|
Changes, requires a sensor system.
|
Not required
|
|
Position value
|
Available via absolute value encoder.
|
Not required
|
|
Number of parts in buffer storage
|
Should be persistent so the value is not lost in the event of a reset or program change.
|
Persistent
|
|
Position of a conveyor line
|
Position should remain stored. Homing takes place.
|
Retain
|
|
VAR RETAIN
remvar1: INT; (* 1. Remanent variable*)
END_VAR
|
Persistent variables
Persistent variables also remain stored in the event of a stop, restart, online change, or PLC program download.
Persistent variables are saved when the device is switched off. Persistent variables are reinitialized by executing "RESET origin".
How to create persistent variables:
Precondition
✓
Access to
»
PLC Designer«
1.
Right-click on Application.
2.
Select New object.
3.
Click on Persistent variables.
|
VAR_GLOBAL PERSISTENT RETAIN
uiPerRetain : ARRAY[0..1000] OF UINT; (* Declaration of persistent variable*)
END_VAR
|