Usage of NOVRAM compatible with PLC power-down retention area

 Traditional PLCs have a power-down holding area, and as long as the variable address is set to this range, it can be maintained during power loss.How can I achieve this function on Beckhoff's controller?Use the controller with NOVRAM, call the FB provided in the supporting document in this article in the PLC program, set the size of the holding area and the stored offset as required, and then set the variable address within the specified interval.

 

IF NOT ( want_to_know_more) THEN

EXIT;

END_IF

***********************************

 

Power-down persistence for Beckhoff controllers is divided into software and hardware modes. Software mode refers to storing variable values in a file on the CF card or hard drive - persistent variables or XML files are both software modes. Hardware mode refers to directly storing data in a specified offset address in NOVRAM.

NOVRAM is a storage hardware independent of memory or CF card. Compared to memory, it has the feature of power-down retention. Compared to CF card, it is not affected by programs and operating systems.The data storage in NOVRAM only recognizes absolute addresses, regardless of names and types.Therefore, compared to file storage methods, NOVRAM is more low-level and more reliable.Regardless of how the operating system and programs change, as long as no data is written to NOVRAM, each byte will still maintain its original value.

The characteristics of NOVRAM are: small capacity, high price, and slow read and write speed.Not all controllers come with NOVRAM.In Beckhoff products, only the CX10xx, CX20xx, and CX90x0 series are equipped with built-in NOVRAM, with capacities less than 128kB.Due to the inclusion of UPS in the CX80xx and CX50/51 series, there is no NOVRAM. IPC determines whether to use UPS or NOVRAM through different options.

There are two ways to store data in NOVRAM: Mapping and Write. The former is unconditional Write every task cycle, while the latter is conditionally triggered Write.Regardless of the method, each write of data will consume PLC time, which is directly reflected in the lengthened execution time of the cycle.My own test results show that the time required for CX9020 to write data to NOVRAM is more than 30 times the time required to write a file, and writing 10kByte data takes 3.14ms. Therefore, it is important to place programs and variables that write to NOVRAM in low-priority tasks, otherwise it will affect normal logical operations and result output, especially applications with distributed clock functions, which are more sensitive to this impact.Real-world testing shows that after placing it in low priority, even if writing data or writing files takes a long time and cannot be completed within the specified task cycle, high-priority tasks will not be affected.

In my book "TwinCAT 2.0 from Beginner to Proficient", only the Mapping method is introduced. In the new version of Beckhoff Information System, the PLC function block FB_NovRamReadWriteEx that reads and writes NOVRAM data is also provided.The Mapping method does not require writing code, but when adding or removing variables, it is necessary to modify the configuration file. During debugging, if you click PLC Stop, all Output variables are cleared, and NOVRAM variables are also cleared, which is inconvenient.Using FB_NovRamReadWriteEx eliminates the need for variable mapping and avoids the above problems, but it requires writing code in the program.

To accommodate users of traditional PLCs, who use NOVRAM as a power-down data retention area, Beckhoff engineer Jacen in South China wrote a FB that periodically writes data from the specified M area to the NOVRAM area.For example, if the specified range is %MB0 to %MB9999, then the user has a 10kByte power-down retention area.As long as the variables to be retained are defined to any location in this range, whether it is a local variable or a global variable, power-down retention can be achieved.


The size and offset of the call write range are controlled by constants within FB:


It needs to be emphasized again that although the NOVRAM area of the controller has 128K, if you really write this 128K data at a time, even if it is placed at the lowest task priority, during the periods of writing data, the CPU utilization will rise to the limit value, such as 80%.Therefore, it is still necessary to determine the size of the power-down maintenance area based on the actual situation, and not to waste CPU resources.If the data to be maintained is really that much, it is recommended to divide it into several sections and call it according to the need.