How to save a variable value after controller power off inquiry

Hello,

I need to save a variable after power off or any other reset of the controller.

I configured the variable as RETAIN (global var, INT type) using the checkbox, but it does not work (no error, the value is being reset after any shutdown/reset).

I tried to test the same controller(5APC2100_BY01_000) in the lab and it does not work as well: once I turn OFF and ON the controller the value is reset to 0.

Can someone advice a solution ?

image

What is the setting in CPU configuration Reboot mode after powerfail:

image

It should be on warm start.

Are there any errors like 26263 in the logbook?

If so, try hardening measures, see following link:

Hardening measures

Do you already use the latest AR 4.83 version I4.83?

thanks for answering.

No errors in the logbook.

The configuration of the reboot is correct, as below.

image

regarding the AR version, please advise where shall I check what AR is being used?

One other thing to check - is it possible that the variables you’ve retained are getting a new value before you check them? For example, if you assign a variable a value in the INIT routine, that will overwrite whatever retained value it had on boot.

Also, you can check your AR version in Project → Change Runtime Versions in Automation Studio.

1 Like

thanks for replying.

it works properly in case of a power shut down: The value is being saved if we power off and then power on the PLC.

the problem that we face is that the value is not saved after cold reset.

Does the value shall be saved after cold reset or the PLC HW is designed to set the default value after cold reset?

In this case @evgeni.kecher you need permanent variables:


I see 3 useful pages in the help under “Nonvolatile variables“ section:

Last note: “Permanent variables are not supported on all target systems.“

Ciao
Valerio

I did not find a list on what HW is supported.

“Permanent variables” are supported in 5APC2100?

I declared it in the globles variables but it does not compile. I do not see an example of how to implement it, can you provide ?

Hello,

In order to configure a permanent Variable it has first to be selected as retain Variable.

Then you can go to the Hardware Configuration of the PLC and check if the menĂĽ shows you the Editor for Permanent Variables (for APC2100 this is available)
Here you an add the Variable to the list and set up the fixed Offsets in Memory.

There is also an Button to calculate the Offsets automaticaly.

It is also important to set up the memory configuration.

Please not that the system of permanent Variables has been discontinued and all new B&R PLCs will only support Retain Variables.

Greetings
Michael

1 Like

If your controller doesn’t support permanent variables, another option is to save the variables to the hard disk (CFast card). In my opinion, this is a good thing to do anyway because it ensures that the data persists on the memory card even if there is a cold start or the controller ever stops working.

The easiest way to do this is with mapp Recipe, which saves the variables you choose to a CSV or XML file. If you didn’t want to pay for the mapp Services license, you could also make your own solution by creating the CSV or XML file manually. You would then write the data to a file whenever it changes (or just before a cold start if you can predict that) and then read it again at startup. As a bonus, this file can be transferred to a different controller if you wanted to easily transfer the saved data to another machine. This is the method I use to save machine settings and configuration options in my projects and it works well. The only caveat is that these settings don’t change very often. If your variables are actively changing every cycle, you won’t want to write to the memory card that often.

1 Like