Abstract: This paper details the FIFO function in Siemens S7-300/400 PLC and describes how to develop and implement a multi-byte FIFO function using Siemens S7 series PLC programming software SimaticSTEP7.
Abstract: This paper introducesFIFOfunctionbasedSiemensS7-300/400PLC, andachievesseveralbyteFIFOfunctionbymakinguseofSiemensPLCProgrammingsoftwareSimaticSTEP7development.
Keywords: Siemens S7-300/400 PLC; FIFO; SimaticSTEP7
Keywords: SiemensS7-300/400PLC; FIFO; SimaticSTEP7
Main content:
1. Introduction: This section explains why we need to introduce the FIFO function in Siemens PLCs.
2. First, we will introduce the dedicated function blocks provided by Siemens, FC84 and FC85, and provide examples for each.
3. Explain that in inter-device data communication, any data exceeding one byte needs to be buffered in a FIFO buffer simultaneously and then popped out in the next process. Describe the implementation of the multi-byte FIFO function.
4. Introduction to Siemens PLC programming development software SimaticSTEP7, including programming development of a 20-byte FIFO, explanation of related data block structures, and calling the FIFO function block in the program. Furthermore, simulation verification can be performed using SimaticSimulation.
5. Summary.
I. Introduction
FIFO (First Input First Output) is a widely used function. Previously, this technology was primarily applied in high-level computer language development and data structure design. However, with the rapid advancement of PLC technology, the need for data transmission and buffering via PLCs is increasing, especially in data caching, leading to a greater reliance on FIFO functionality. The Siemens S7-300/400 PLC is a medium-to-large-scale PLC from Siemens, Germany, and is a mainstream product in the global industrial control industry. In the Siemens S7 series PLC development software SimaticSTEP7, Siemens provides two dedicated functions, FC84ATT and FC85FIFO, for writing and exporting FIFO data. However, only one word (two bytes) of data is allowed at a time. To implement multi-byte FIFO functionality, users need to develop their own function blocks (FB). This article introduces the code for implementing a 20-byte FIFO function block (FB200) and provides practical application examples.
II. Introduction to the Siemens FC84ATT and FC85 FIFO Functions
1. FC84ATT
1.1 Introduction to the Functions and Structure of FC84ATT
The FC84ATT is the data storage area for adding data to the FIFO function. Each execution of this instruction adds one word of data to the FIFO data storage area. The FIFO storage area is organized in units of words, and its specific structure is as follows:
The first word in the storage area table is the maximum number of data entries allowed in the FIFO storage area, that is, the maximum number of words of data that can be stored.
The second word in the storage area table is the number of data items currently stored in the FIFO storage area, i.e., how many words of data have been stored.
The data actually stored in the FIFO storage area starts from the third character in the storage area table.
1.2 FC84ATT Functional Parameter Description
When developing a program using SimaticSTEP7, calling the FC84ATT function results in the following image:
As shown in Figure 2-1, the FC84ATT has four parameters: EN, DATA, TABLE, and ENO. These are described in Table 2-1 of the four main documentation.
parameter | statement | Data types | memory area | Function Description |
EN | enter | Boolean | I, Q, M, D, L | Enable activation signal |
ENO | Output | Boolean | I, Q, M, D, L | Enable output |
DATA | enter | Word | I, Q, M, D, L, P static storage areas | Data to be added to FIFO |
TABLE | enter | pointer | I, Q, M, D, | FIFO area pointer |
1.3. Examples
If signal M100.0 is in state 1 (i.e., activated), the FC84ATT function is executed. In the example below, the added data is written to the fifth row of the FIFO table, and the FIFO capacity, which is the second row of the FIFO table, changes from 4 to 5. If FC84ATT is executed and no error occurs, the enable output ENO is set to 1, as follows:
2. FC85FIFO
2.1 Introduction to FC85 FIFO Functions and Structure
The FC85FIFO reads data from the FIFO table sequentially according to the first-in, first-out (FIFO) principle for use. It works in conjunction with the FC84ATT to perform FIFO write and read functions. Each execution of this instruction reads one word of data from the FIFO's data storage area. The FIFO's storage area is organized in units of words, as follows:
The first word in the storage area table is the maximum number of data entries allowed in the FIFO storage area, that is, the maximum number of words of data that can be stored.
The second word in the storage area table is the number of data items currently stored in the FIFO storage area, i.e., how many words of data have been stored.
Starting from the third word in the FIFO storage area table, the data actually stored in the FIFO storage area is also the data pointed to by the FIFO pointer.
2.2 FC85FIFO Functional Parameter Description
When developing a program using SimaticSTEP7 and calling the FC85FIFO function, the following image appears:
Figure 2-2
As shown in Figure 2-1, the FC85FIFO has four parameters: EN, ENO, TABLE, and RET_VAL. These are described in Table 2-2 of the Siemens documentation.
parameter | statement | Data types | memory area | Function Description |
EN | enter | Boolean | I, Q, M, D, L | Enable activation signal |
ENO | Output | Boolean | I, Q, M, D, L | Enable output |
TABLE | enter | pointer | I, Q, M, D, | FIFO area pointer |
RET_VAL | Output | Character | I, Q, M, D, L, P | Read data |
2.3. Examples
If signal M100.0 is in state 1 (i.e., activated), the FC85FIFO function is executed. In the example below, data read from the FIFO storage area is written to the address specified by RET_VAL, and the FIFO capacity, i.e., the second row of the FIFO table, changes from 5 to 4. Simultaneously, the data stored in the entire FIFO shifts up one row sequentially. If the FC85FIFO is executed without errors, the enable output ENO is set to 1.
III. Implementation of Multi-Byte FIFO Function
1. As can be seen from the previous descriptions of FC84ATT and FC85FIFO, although Siemens provides support for S7...
The series PLC has a FIFO function module, but it can only write or read one byte of data at a time. In reality, in many cases, a group of data needs to be temporarily stored using the FIFO function. In such cases, the standard functions FC84 and FC85 provided by Siemens cannot be used. It is necessary to develop a FIFO instruction that can realize multi-byte read and write functions.
2. Introduction to Siemens Simatic STEP7
The Siemens Simatic S7300/400 series PLCs are Siemens' flagship medium-to-large-sized products and are currently mainstream products worldwide. The software development tool for these two PLC series is SimaticSTEP7. This software has multiple versions, currently at version V5.4, and can be used to implement development and monitoring functions.
3. Implementation of a multi-byte FIFO
Open the SimaticSTEP7 software, create a new FB block, such as FB200DB200, and then enter FB100.
This article uses a 20-byte example to illustrate how to develop and implement a FIFO function, as shown in the following screenshot:
Figure 3-1
The source code is as follows:
FUNCTION_BLOCKFB100
TITLE=
//This function block uses a 20-byte FIFO function.
AUTHOR:Hylotus
VERSION: 0.1
KNOW_HOW_PROTECT
VAR_INPUT
SOURCE_DB:BLOCK_DB;
INPUT:BOOL;
OUTPUT:BOOL;
SIZE:INT;
END_VAR
VAR_OUTPUT
DONE_IN:BOOL;
DONE_OUT:BOOL;
ERROR:BOOL;
FULL:BOOL;
EMPTY:BOOL;
END_VAR
VAR_IN_OUT
LOCATION:INT;
END_VAR
VAR
IN_START:BOOL;
IN_ACTIVE:BOOL;
OUT_START:BOOL;
OUT_ACTIVE:BOOL;
COUNT:INT;
RET_VAL1:INT;
END_VAR
BEGIN
NETWORK
TITLE=
A#INPUT;
AN#IN_ACTIVE;
=#IN_START;
A#INPUT;
=#IN_ACTIVE;
A#OUTPUT;
AN#OUT_ACTIVE;
=#OUT_START;
A#OUTPUT;
=#OUT_ACTIVE;
AN#INPUT;
AN#OUTPUT;
JCEND1;
NETWORK
TITLE=OUTPUTFIFO
//20 bytes of data read from the FIFO storage area
AN#OUTPUT;
O#DONE_OUT;
JCIN_1;
AN#OUT_START;
JCOP_1;
OPN#SOURCE_DB;
LDW#16#0;
TDBD40;
TDBD44;
TDBD48;
TDBD52;
TDBD56;
TDBD60;
TDBD64;
TDBD68;
TDBD72;
TDBD76;
L#LOCATION;
L0;
<=I;
S#EMPTY;
JCEROR;
OPN#SOURCE_DB;
CALL "BLKMOV" (
SRCBLK:=P#DBX80.0BYTE40,
RET_VAL:=#RET_VAL1,
DSTBLK:=P#DBX40.0BYTE40);
L#RET_VAL1;
L0;
<>I;
JCEROR;
L0;
T#COUNT;
OP_1:L#LOCATION;
L0;
<=I;
JCEROR;
L#LOCATION;
L#COUNT;
<=I;
JCOP_3;
L#COUNT;
L2;
+I;
ITD;
LP#40.0;
*D;
LAR1;
OPN#SOURCE_DB;
LDBD[AR1,P#40.0];
TDBD[AR1,P#0.0];
LDBD[AR1,P#44.0];
TDBD[AR1,P#4.0];
LDBD[AR1,P#48.0];
TDBD[AR1,P#8.0];
LDBD[AR1,P#52.0];
TDBD[AR1,P#12.0];
LDBD[AR1,P#56.0];
TDBD[AR1,P#16.0];
LDBD[AR1,P#60.0];
TDBD[AR1,P#20.0];
LDBD[AR1,P#64.0];
TDBD[AR1,P#24.0];
LDBD[AR1,P#68.0];
TDBD[AR1,P#28.0];
LDBD[AR1,P#72.0];
TDBD[AR1,P#32.0];
LDBD[AR1,P#76.0];
TDBD[AR1,P#36.0];
L#COUNT;
L1;
+I;
T#COUNT;
L#SIZE;
L-1;
+I;
L#COUNT;
<=I;
JCOP_2;
JUEND2;
OP_2:LW#16#0;
TDBD[AR1,P#40.0];
TDBD[AR1,P#44.0];
TDBD[AR1,P#48.0];
TDBD[AR1,P#52.0];
TDBD[AR1,P#56.0];
TDBD[AR1,P#60.0];
TDBD[AR1,P#64.0];
TDBD[AR1,P#68.0];
TDBD[AR1,P#72.0];
TDBD[AR1,P#76.0];
OP_3:SET;
S#DONE_OUT;
L#LOCATION;
L-1;
+I;
T#LOCATION;
JUEND2;
NETWORK
TITLE=INPUTFIFO
// Write 20 bytes of data to the FIFO memory table
IN_1:AN#IN_START;
JCEND2;
L#LOCATION;
L#SIZE;
>=I;
S#FULL;
JCEROR;
L#LOCATION;
L2;
+I;
ITD;
LP#40.0;
*D;
LAR1;
OPN#SOURCE_DB;
LDBD0;
TDBD[AR1,P#0.0];
LDBD4;
TDBD[AR1,P#4.0];
LDBD8;
TDBD[AR1,P#8.0];
LDBD12;
TDBD[AR1,P#12.0];
LDBD16;
TDBD[AR1,P#16.0];
LDBD20;
TDBD[AR1,P#20.0];
LDBD24;
TDBD[AR1,P#24.0];
LDBD28;
TDBD[AR1,P#28.0];
LDBD32;
TDBD[AR1,P#32.0];
LDBD36;
TDBD[AR1,P#36.0];
L#LOCATION;
L1;
+I;
T#LOCATION;
SET;
S#DONE_IN;
JUEND2;
NETWORK
TITLE=
EROR:SET;
=#ERROR;
JUEND2;
END1:CLR;
=#DONE_IN;
=#DONE_OUT;
=#ERROR;
=#EMPTY;
=#FULL;
END2:NOP0;
END_FUNCTION_BLOCK
4. Calling within the program
The programming development of the FB100FIFO function block has been completed above. The next step is to directly call and set it.
This function can be used with the relevant parameters, as shown in the following example:
Create a new FIFO data source database DB200 with the following structure:
Address | Name | Type | Initial value | Comment |
0.0 | STRUCT | |||
+0.0 | IN_Buffer | STRUCT | ||
+0.0 | Status_Word | INT | 0 | |
+2.0 | Data1 | INT | 0 | |
+4.0 | Data2 | INT | 0 | |
+6.0 | Data3 | INT | 0 | |
+8.0 | Data4 | INT | 0 | |
+10.0 | Data5 | INT | 0 | |
+12.0 | Data6 | INT | 0 | |
+14.0 | Data7 | INT | 0 | |
+16.0 | Data8 | INT | 0 | |
+18.0 | Data9 | INT | 0 | |
=20.0 | END_STRUCT | 0 | ||
+0.0 | Status_Word | INT | ||
+2.0 | Data1 | INT | ||
+4.0 | Data2 | INT | ||
+6.0 | Data3 | INT | ||
+8.0 | Data4 | INT | ||
+10.0 | Data5 | INT | ||
+12.0 | Data6 | INT | ||
+14.0 | Data7 | INT | ||
+16.0 | Data8 | INT | ||
+18.0 | Data9 | INT | ||
=20.0 | END_STRUCT | |||
+40 | Data | Array[0..20] | ||
*0.0 | STRUCT | |||
+0.0 | Status_Word | INT | 0 | |
+2.0 | Data1 | INT | 0 | |
+4.0 | Data2 | INT | 0 | |
+6.0 | Data3 | INT | 0 | |
+8.0 | Data4 | INT | 0 | |
+10.0 | Data5 | INT | 0 | |
+12.0 | Data6 | INT | 0 | |
+14.0 | Data7 | INT | 0 | |
+16.0 | Data8 | INT | 0 | |
+18.0 | Data9 | INT | 0 | |
=20.0 | END_STRUCT | 0 | ||
=440 | END_STRUCT |
5. All the FIFO program call function blocks and programs mentioned above can be verified by simulating the PLC using SiamticSimulation software provided by Siemens, and can run normally without any problems.
IV. Summary
By developing our own software to compensate for the deficiencies of the dedicated function modules provided by Siemens, we can maximize the advantages of Siemens' software development.