Persistent variables - declaration

Question:
How can you create PERSISTENT variables?

Answer:
The Servo PLC (as of V6.3) and the ECS axis module (as of V6.5) are equipped with a PERSISTENT memory (see article Implementation of the VAR Persistent memory class; Doc-ID 20034021). This is a fail-safe memory which, unlike the RETAIN memory, is not initialised even when downloading a project. The PERSISTENT memory can only be deleted in online mode by using the menu command Online>Reset (original).

RETAIN variables must be declared between the keywords VAR RETAIN and END_VAR. Example:

VAR RETAIN
  dnVarRetain  : DINT;
END_VAR

Access to the persistent memory is effected via the system block VAR_Persistent. For this, the system block must be added to the PLC configuration (Ressources tab) (select menu command Add>Add subelement, VAR_Persistent).
As persistent variable you can then either use one of the system variables contained in the system block VAR_Persistent or you can declare a variable with the absolute address of the system block. Example:

VAR
  dnVarPersistent AT %QD171.0 : DINT;
END_VAR

Note:
When declaring variables with an absolute address, it must be avoided that several variables accidentally use the same absolute memory area.

URL for linking this AKB article: https://www.lenze.com/en-de/go/akb/200801805/1/
Contact form