Overview
The TI A instruction set includes several move instructions that can clear data within DB blocks. For S7-1500 CPUs or ET200SP CPUs, BLKMOV, FILL, and the SCL POKE_BLK instruction can be used. These instructions require the DB block to be a non-optimized DB when clearing a DB block.
For optimized DB blocks, FILL_BLK can be used, or create a DB block with the same UDT structure and use MOVE to clear the DB block data. FILL_BLK imposes data-type requirements and typically requires an array type, so it has more data-type restrictions compared with handling non-optimized DBs.
There are multiple ways to clear DB block data depending on the DB block data types. This article describes several methods using TIA integrated instructions as a reference for Programming.
Test Environment
Software: TIA V17 Professional
Hardware: CPU1512C-1 PN V2.9
Clearing Data in Non-Optimized DB Blocks
Add a non-optimized DB block named "DST_Data" DB1 (target DB) in the S7-1500 CPU. The data type can be any type.
Method 1: BLKMOV
- The BLK_MOV instruction moves data from one memory area (source) to another (destination).
- When using this instruction, create a source DB with the same data length as the destination DB. The source DB only needs to match the data length of the destination DB. Create a non-optimized DB named "SRC_Data" DB2 (source DB).
In OB1, call the BLKMOV instruction under Instruction > Basic Instructions > Move Operations > Original.
Instruction pins Parameters explanation:
Pin | Value | Notes |
---|---|---|
SRCBLK | =P#DB2.DBX0.0 BYTE 58 | // source DB block |
RET_VAL | %MW2 | // return value |
DSTBLK | =P#DB1.DBX0.0 BYTE 58 | // destination DB block |
After execution, the DST_Data DB1 (destination DB) is fully cleared.
Method 2: POKE_BLK in SCL
Add an SCL block in OB1, then call the POKE_BLK instruction under Instruction > Basic Instructions > Move Operations > Read/Write Memory.
Method 2 works on the same principle as Method 1; the difference is that it uses an SCL instruction. Both methods require creating a source DB to overwrite the destination DB to achieve clearing.
Method 3: FILL
In OB1, call FILL under Instruction > Basic Instructions > Move Operations > Original.
Instruction pins explanation:
Pin | Value | Notes |
---|---|---|
BVAL | MB1 | // source data |
RET_VAL | %MW4 | // return value |
BLK | =P#DB1.DBX0.0 BYTE 58 | // destination DB block |
Compared with the previous two methods, Method 3 does not require creating an entire source DB to overwrite the destination DB; at minimum, only a single Byte data is needed, such as %MB1 mentioned above.
Clearing Data in Optimized DB Blocks
Method 1: FILL_BLK
FILL_BLK requires specific DB block data types. The DB should be created as an ARRAY type, or as a UDT or STRUCT with the same basic data type.
Add an optimized DB block named "DST_Data2" DB3 (destination DB) in the S7-1500 CPU.
In OB1, call FILL_BLK under Instruction > Basic Instructions > Move Operations.
Instruction pins explanation:
Pin | Value | Notes |
---|---|---|
IN | MB1 | // source data; data length must match the array element base type |
COUNT | - | // length to overwrite |
OUT | "DST_Data2".Stat ic_1[0] | // start address of the target structure |
After execution, the specified length of array or STRUCT data within DST_Data2 DB3 is cleared.
Method 2: Create Matching UDT and Use MOVE
Create source and destination optimized DB blocks using the same UDT data type.
In OB1, call MOVE under Instruction > Basic Instructions > Move Operations, as shown below.
Execution result is shown below.