Remanent variables can either be reinitialized or retain their values in the event of power outages, reboots, resets, and application program downloads. There are multiple types of remanent variables, declared individually as retain or persistent, or in combination as retain-persistent.
NOTE: For this controller, variables declared as persistent behave in the same way as variables declared as retain-persistent.
Remanent variables are retained only if the battery charge is sufficient.
This table describes the behavior of remanent variables in each case:
Action |
VAR |
VAR RETAIN |
VAR GLOBAL RETAIN PERSISTENT |
---|---|---|---|
Online change to application program |
X |
X |
X |
Online change modifying the boot application (1) |
– |
X |
X |
Stop |
X |
X |
X |
Power cycle |
– |
X |
X |
Reset warm |
– |
X(2) |
X |
Reset cold |
– |
– |
X |
Reset origin |
– |
– |
– |
Download of application program(3) |
– |
– |
X |
X The value is maintained. – The value is reinitialized. (1) Retain variable values are maintained if an online change modifies only the code part of the boot application (for example, a:=a+1; => a:=a+2;). In all other cases, retain variables are reinitialized. (2) For more details on VAR RETAIN, refer to Effects of the Reset warm Command. |
NOTE: The first 500 %MW are automatically retained and persistent if no variable is associated to them (their values are kept after a reboot / Reset warm / Reset cold). The other %MW are managed as VAR.
For example, if you have in your program:
VAR myVariable AT %MW0 : WORD; END_VAR
%MW0 behaves like myVariable (not retained and not persistent).
Adding Retain-Persistent Variables
Step |
Action |
---|---|
1 |
In the Applications tree, select the Application node. |
2 |
Click the right mouse button. |
3 |
Choose Add Objects > Persistent variables |
4 |
Click Add. Result: The PersistentVars window is displayed. |
Retain and Persistent Variables: Performance Impact
Retain or retain-persistent variables are located in a dedicated non-volatile memory. Each time these variables are accessed during Programming Organization Unit (POU) execution, the non-volatile memory is accessed. The access time of these variables is slower than the access time of regular variables, which can impact performance. This is an important fact to take into account when writing performance-sensitive POUs.