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:
Â
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:
Â
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
Â