/
Compax3 Software - Remnant Variables - VAR Retain

Compax3 Software - Remnant Variables - VAR Retain

Applications will often require variables that retain their value between power cycles. The programmable Compax3 (T30, T40) offers this functionality through the use of RETAIN variables in the Codesys program.

 

Retain variables are declared as follows:

 

In the variable declaration window type "VAR RETAIN" and then close by typing "END_VAR", as shown below:

pastedimage1623949409757v1_4163-20240521-000905.png

 

Any variable placed in this section of the declaration editor will have the same value upon power up that it did when powered down.

Retain variables can be placed in any program or Global Variable list. The declaration for Global variables is slightly different and is shown below. In the Global variable declaration window type "VAR_GLOBAL RETAIN" and then close by typing "END_VAR", as shown below:

pastedimage1623949663033v2_4164-20240521-000905.png

 

Initialization of retain variables only applies to the download of a project to a factory drive.  After an initial download, variables will always retain the last value they were assigned.

 

The initialization syntax is identical to that of a standard variable. Shown below the variable iVarRetain1 will be initialized to 1 after the first download to a factory drive .

 

 

 

The Compax3 has a limited amount of memory available for retain variables. The limits are shown in the chart below:

 

These limits apply to the TOTAL number of retain variables in the project. For example, having two retain INTs in a POU and one retain INT in a GVL is acceptable. Having two retain INTs in a POU and two retain INTs in a GVL is NOT acceptable. If the number of retain variables is exceeded an error will appear during compile.

 

VL Created: 20210617

 

Related content

Compax3 Troubleshooting - CODESYS Error 5827 #1027 Unknown Command
Compax3 Troubleshooting - CODESYS Error 5827 #1027 Unknown Command
Read with this
Remanent Variables: Retain VS Persistent Retain
Remanent Variables: Retain VS Persistent Retain
More like this
Compax3 Training - C3Servomanager - How to Create Customary Rotary Motor File (Video)
Compax3 Training - C3Servomanager - How to Create Customary Rotary Motor File (Video)
Read with this
Compax3 Training - Analogue Velocity / Joystick Program for Compax3 (Video)
Compax3 Training - Analogue Velocity / Joystick Program for Compax3 (Video)
Read with this
6K Troubleshooting - Memory Errors in Stand-Alone Products
6K Troubleshooting - Memory Errors in Stand-Alone Products
More like this