Retain values in S7 1200 when power off

 So how to set up the power-off data retention function for S7-1200?

 S7-1200 module  (Photo: siemens.com/global)

During operation, an unexpected power outage may occur, and the equipment operators hope that certain key data can be preserved in such cases to ensure the normal operation of subsequent production. The S7-1200 series PLC features a retained storage area that can be used to set power-off retained data. In this article, we will discuss how to set up the power-off data retention function for S7-1200.

First, let's understand the composition of the internal storage area of the S7-1200 series PLC: The internal storage area of the S7-1200 includes the Load Memory, Work Memory, and Retain Memory.

Load Memory: This is a non-volatile storage area, similar to a computer's hard disk. The Load Memory is used to store user project files (user programs, data, and configurations). When no memory card is inserted, users use STEP 7 software to download projects directly into the Load Memory. In addition to user programs and data, symbol names and comments in the project are also downloaded into the Load Memory, greatly facilitating users' later debugging and maintenance.

Work Memory: This is a volatile storage area, similar to a computer's RAM. When the CPU executes a user program, it copies some project contents from the Load Memory to the Work Memory. The contents of the Work Memory are lost after a power outage and cannot be extended.

Retain Memory: This is a non-volatile storage area. When the CPU detects that the voltage drops to a certain level, it saves the data set as power-off retained from the Work Memory to the Retain Memory.

The S7-1200 series PLC supports setting data from bit memory, instance DB (Instance Data Block), and global DB (Global Data Block) as retentive.

Setting the bit memory always starts from the 0th byte, as follows:

In the PLC tags, click on the "battery" icon, as shown below: 


The following dialog box pops up:


In this example, we set 100 bytes starting from MB0 to be retained in case of power loss, as shown below:


Then we will notice that the retention property of the variables "Tag_2", "Tag_3", and "Tag_4" that we previously created has been checked, as shown below:


At this point, the bit memory from MB0 to MB99 already possesses the property of power-off retention.

For the global data block, you can choose certain data within it and set their properties to "retentive," thus enabling power-off retention functionality. As shown below:


The retention setting for background data blocks is selected within the parameter input of the function block (FB), as shown below:

The retained storage area size for the S7-1200 series PLC is 10 KB. The total size of all configured areas (bit memory, background data blocks, and global data blocks) with retention properties cannot exceed 10 KB.

How to view the usage of the retained storage area?

In offline mode, you can check the current usage of the storage area through the "Program info" in the project tree within the TIA Portal environment, as shown below:

In online mode, you can view the current CPU retained storage area usage by accessing "Diagnostic - Memory," as shown below:


Alright, that's all for the introduction to the retained storage area settings for the S7-1200 series PLC for now.