Tech Note : CODESYS Persistent Variables

This is short note for new users to CODESYS on how to use local, retain, and persistent retain variables.

Local or Global Vars - Values that will be re-initialized when the PLC is rebooted or turned on and off. An example could be speed feedback from a VFD, or variable for the current temperature.

Retain Vars - Used for variables where only a cold reset will re-initialize these values. This might be a user configured setpoint where a maintenance tech could perform a cold reset to return a value to a factory state.

Persistent Retain Vars - Used for variables like system configuration, that should not re-initialize. The user could use a persistent variable for the number of run hours since the machine was last serviced.

4 Likes

One additional gotcha to watch out for, Retain does not survive a download and requires Persistent Vars. Wish there were a better way to handle this.

1 Like

Then what is the meaning of download? When should it be used?

Download mean put a new program which don’t support online changes.

Hi, how do retain and persistent variables behave when power is lost?

Both are preserved on power loss. They behave the exact same in this regard.

1 Like