Out of persistent memory

  • trevorb

    trevorb - 2021-03-03

    Hi All,

    I am looking for support for my Codesys application. I am using persistent variables however I am no longer able to add more due to an error when trying to upload changes. The error is below

    [ERROR]         Default: PersistentVars [PCT_Assem_Mach: PLC Logic: Application](Line 229): C0415:  Out of persistent memory: Variable 'R314TPEdges1', 1208 bytes (Largest contiguous memory gap 488). Editing persistant variable lists may produce fragmented memory. Perform "Declarations, Reorder list and clear gaps" to compact persistent variable lists. 
                    Build complete -- 1 errors, 103 warnings : no download possible!

    I have done as per the error recommendations. This did help initially however now I am out of space even with the 'gaps cleared'.

    How do I go about increasing the memory capacity for the persistent variables?

    Thanks in advance

  • TPTSys

    TPTSys - 2021-03-07

    I'm not sure how to increase the persistent memory, but a few tips to make maximum use of the memory you have:

    Use the attribute pragma {attribute 'pack_mode' := '0'} . This ensures that each byte in the memory is used without skipping or re-aligning to even numbered bytes with data larger than 1 byte.

    Boolean values use a full byte of memory. You can declare structures to use bit values for boolean values, or bitmap to words to save room.

    Make sure you aren't declaring any function blocks in persistent, it will save the entirety of the function block into the memory area.

    I think declaring all of the persistent memory together will ensure it ends up as a continuous memory area with as few gaps as possible. If different global variable lists use the persistent flag, it may split things up? I'm not 100% sure about this.

  • trevorb

    trevorb - 2021-03-10

    Hi Thanks for the response. Using the attribute you have suggested should indeed help utilising all the available data however, for this project it will still be inefficient.

  • dawidr

    dawidr - 2021-03-11

    I don't known what kind of project you are working and what is a structure of your code but take a look at my post here: https://forge.codesys.com/forge/talk/Engineering/thread/ed30e6d1a1/.
    I'm using Wago PFC200 in my home automation project and in order to save me from such kind of issues I'm not storing whole function blocks in persistent memory. Even though, my data is rather small (for now, who knows how it will grown...).
    I've extracted all variables which needs to be stored in persistent memory area into structures and I'm passing those structures to my function blocks from main program (as in/out parameters).

  • trevorb

    trevorb - 2021-03-11

    In concept I understand the approach you are taking to reduce the use of persistent to only that is required. That is a good approach to reduce the usage.
    The basis for the original question is because my experience is with asked Bradley PLC which by default all tags are non volitile and the smallest storage in the compactlogix range is 600kB program and data storage. I was running out of persistent memory at 2kB so it didn't make any sense that this could not be increased.

    After discussing further with the local SEW Eurodrive engineers we found that the Movi-C controller has 2kB of persistent memory and 32kB of retain storage. A long way from what U was expecting. However, being new to this platform I was not aware of the retain data area and fortunately it is large enough to store the 11kB of data I need.
    I still use the persistent data for variables I need to keep during a download but The majority of the retain variables are just proceed variables that need to be retained in the event of a power cycle.

    Thanks for taking the time to respond.

  • MadsKaizer

    MadsKaizer - 2021-03-12

    The hint lies in "(Largest contiguous memory gap 488). Editing persistant variable lists may produce fragmented memory."

    You have changed too many blocks, data structures or something else that fragmented the PVL. Go to "Build" menu and run a "Clean" to de-fragment your project, this will however require a new download in PLC.

  • trevorb

    trevorb - 2021-03-18

    Yes I indeed have done this on many occasions to defragment the memory. However, the issue lies in trying to assign 11kB of data into a 2kB memory area.

  • TPTSys

    TPTSys - 2021-03-20


    It sounds like you may have a solution to your issue by using the VAR RETAIN for the values that aren't necessary to hold on to through downloads. A few more tips in case you or someone else needs them:

    As of ~3.5.16 Ethernet/IP libraries have made their values retained by default within the libraries. This can burn up space quick on devices with limited memory area. The setting is tricky to find.... I'll let you know when I find it again...

    You can use a method to back up your settings and restore them after downloads using Recipes, or your own file read/write commands. Definitely not as convenient as throwing the persistent tag on, but not too bad once it is set up. You can even use a trigger of some sort in the program to write the values. Usually I think this is how persistent values work anyway, when power goes down, it is detected and it writes the values to a special part of memory that holds on to them. For example, instead of cutting power directly, you could put a switch with a timer relay that would give a moment to write all your critical values to a file before power goes down.
    Or just save them periodically (be careful of read/write cycles to flash storage!)

    Sometimes you may find you can take advantage of storage on networked components, maybe rather than storing all the settings for a networked component, just read the value and display it, then if the user changes the value write the change. That way, when you download a new program the remote device will hold on to the value.

  • trevorb

    trevorb - 2021-03-22

    Thanks for the reply. I wasn't aware of the Ethernet/IP using retains by default.
    Good idea with regard to using the recipes to store the retains in the event of download. It wouldn't be a big deal to detect the loss of power and trigger the save command.
    Thanks for the tips


Log in to post a comment.