Skip to main content

2.3 Retained Variable

warning
  • Single variable T3 should not exceed 32KB, single variable T4 should not exceed 128KB, otherwise the system may fail to download
  • Retained variables must be global variables defined in the VAR area of ​​GVS or PRG

2.3.1 Definition and characteristics

  • Definition:
    • Retentive variables refer to variables that can keep their value unchanged after the PLC is powered off or shut down and restarted. This is typically accomplished by storing the variable in an area of ​​memory with non-volatile storage properties
  • Features:
    • Power-off retention: Retentive variables can retain their value after the PLC is powered off until the next power-on
    • Data protection: In situations where critical data or status needs to be saved for a long time, retained variables can provide effective data protection
    • Flexibility: Users can choose which variables to define as retained variables as needed to achieve specific control logic and data protection requirements
warning
  • ×=reserved value
  • Blank = initial value
Online commandVARVAR RETAIN
Warm start (power-off restart or CPU from STOP to RUN)×
Incremental download without downtime download in RUN××
Download incremental download in STOP×
Reset and download (rebuild all)
User program reset
Hardware CPU reset Factory reset (the SD card user program and updated firmware are not reset)

2.3.2 Application Scenario

  • Critical state preservation: In situations where the key state of equipment needs to be saved, such as the start and stop state of equipment on the production line, the triggering state of safety protection devices, etc., retained variables can provide effective data support
  • Counting and timing: In situations where long-term counting or timing is required, such as cumulative output statistics in the production process, equipment running time records, etc., retained variables can ensure the continuity and accuracy of the data
  • System configuration and parameters: In terms of system configuration and parameter settings, retained variables can save the user's configuration information and parameter settings so that they can quickly return to the previous state after the system is restarted
warning
  • Storage capacity limitation: The capacity of the non-volatile storage area is limited, and users need to reasonably allocate storage resources according to actual needs
  • Read and write speed: Compared with volatile storage areas, the read and write speeds of non-volatile storage areas may be slower. Users need to pay attention to the performance impact when using them
  • Data security: The data stored in retained variables may involve key information and status of the system. Users need to take corresponding security measures to protect the integrity and security of the data