How to create persistent and constant variables with CODESYS v3 internal PLC ?
June 9, 2017 by Will Blackwell

What to know

In CODESYS V3 internal PLC it is possibile to define:

  • Persistent Retain variables: maintain the value aftert a Reset warm , Reset cold, Download and Online
    Change. Refer to CODESYS V3 manual for more details.
  • Constant variables: if declared and initialized, these variables will assume the initialization value
    anytime during the project execution.

The target of this FAQ is to explain how to create Persistent Retain and Constant variables in CODESYS V3 Workbench.


What to do to create Persisten Retain variables

Execute a right click on Application item from project tree,
then expand Add Object and select Persistent Variables from the object list.

Give a name to the Persistent Variables object, or let the default PersistentVars.

By double clicking on PersistentVars in project tree, it is possible to define Retain Persistent variables.

If these variables have to be exported into the xml file, select them from Symbol Configuration (that has to be added to the Application).

Execute Generate code from Build menu.


What to do to create Constant variables

In the project POU, create VAR CONSTANT section and define Constant variables.

Open Project Settings from Project menu.

From Compile option uncheck Replace constants checkbox

Execute Rebuild from Build menu.

If these variables have to be exported into the xml file, select them from Symbol Configuration (that has to be added to the Application).

Execute Generate code from Build menu.


Applies to

CODESYS V3 internal PLC

Share this Post: