Welcome to our websites!

Program structure and characteristics of several common PLC of Siemens

1. Program structure of some foreign small PLCs

The user program of these PLCs consists of main program, subprogram and interrupt program. In each scan cycle, the CPU calls the main program once. The main program can call the subprogram, and the small control system can only have the main program. The interrupt program is used to quickly respond to interrupt events. When an interrupt event occurs, the CPU will stop executing the program or task being processed at that time and execute the interrupt program written by the user. After executing the interrupted program, continue to execute the suspended program or task. Their subroutines and interrupt programs have no local variables, and their subroutines have no input and output parameters.

2. Program structure of Siemens S7-200

Process image input/output (I/Q), variable memory V, internal memory bit M, timer T, counter C, etc. are global variables. The program organizational unit (POU) of S7-200 includes main program, subprogram and interrupt program. Each POU has its own 64-byte local variable, which can only be used in its POU. In contrast, global variables can be used in each POU.

The following are the local variables that the subroutine can use:

1) TEMP (temporary variable) is a variable temporarily stored in the local data area. The defined temporary variable is used only when the POU is executed. After the POU is executed, the value of the temporary variable will not be saved.

2) IN is the input parameter provided by the POU calling it.

3) OUT is the output parameter returned to the POU calling it (the execution result of the subroutine).

4)IN_ OUT is input_ The initial value of the output parameter is transferred to the subroutine by the POU calling it, and the execution result of the subroutine is returned to the POU calling it with the same variable.

There are only temporary variables TEMP in the local variables of the main program and the interrupt program.

The subprogram with input and output parameters and local variables is easy to realize structured programming, which is particularly useful for manufacturers that produce similar equipment or production lines for a long time. Programmers from these manufacturers have written a large number of general subroutines for each component or process function of the equipment. Even if you do not know the internal code of the subroutine, as long as you know the function of the subroutine and the meaning of the input and output parameters, you can quickly “assemble” the control program that meets the requirements of different users through the call between programs. It is like using digital integrated circuit chips to form complex digital circuits.

If the subroutine has no input and output parameters, there is no clear interface between it and the program calling it, so it is difficult to realize structured programming.

If a subroutine has no local variables, it can only exchange data with the program calling it through global variables, and only global variables can be used inside the subroutine. When migrating subprograms and interrupt programs to other projects, you need to rearrange the global variables they use to ensure that address conflicts do not occur. When the program is very complex and there are many subprograms and interrupt programs, the workload of this kind of address reassignment is very large.

If the subprogram and interrupt program have local variables, and they only use local variables instead of global variables, because there is no address conflict with other POUs, the subprogram can be transplanted to other projects without any changes.

3. Program structure of Siemens S7-300/400

S7-300/400 divides subprograms into function (or function) and function block.

The functions of S7-300/400 are basically the same as those of S7-200. They have input, output parameters and temporary variables. The return value in the local data of the function is actually an output parameter. They do not have a dedicated storage area. After the function is completed, the data in the temporary variables will not be saved.

You can use global variables to save the data that needs to be saved after the function execution, but it will affect the portability of the function.

The function block is a program block written by the user with its own dedicated storage area (i.e. background data block). The input and output parameters and static variables of the function block are stored in the specified background data block, and the temporary variables are stored in the local data stack. Each time a function block is called, a background data block must be specified. After the function block is executed, the data in the background data block will not be lost, but the data in the local data stack will not be saved.

The function block adopts the concept of encapsulation similar to C++, which encapsulates the program and data together and has good portability.

The shared data block of S7-300/400 can be used by all logical blocks.

4. Program structure of IEC61131-3

IEC61131-3 is the programming language standard of PLC. IEC61131-3 is the first and only programming language standard in the field of industrial control in the world. IEC

61131-3 has three types of POUs: program, function block and function.

The function is a POU with multiple input parameters and one output parameter (return value). The name of the return value is the same as the name of the function. The data type of the return value needs to be defined. Adjusting appliance

Functions with the same input value always return the same result. Functions can call other functions, but not function blocks or programs. The local variables that can be defined by functions include VAR and VAR_ INPUT。

A function block is a POU with multiple input/output parameters and internal storage units. The output parameter value of a function block is related to the value of its internal storage unit. Function block can call other functions

Block or function, but the program cannot be called.

Before calling a function block, you must declare the instance of the function block for each call in the POU where the function block is to be called. The operating system will allocate a storage area dedicated to the function block for each call

(Similar to the background data block of S7-300/400).

The function does not need to be instantiated when it is called because it has no internal storage area.

The behavior and purpose of the program is similar to the function block. The program has input and output parameters, and can have internal storage area. Programs usually contain calls to functions and function blocks.

IEC61131-3 defines several standard functions and function blocks.

5. Difference between S7-300/400 and IEC61131-3 program structure

1) The function of S7-300/400 can have multiple output parameters, and the return value is also an output parameter. The function of IEC61131-3 has only one return value.

2) The special storage area for storing local variables in IEC61131-3 function block is allocated when declaring the instance of function block. It is opaque to users, and other POUs cannot directly access the storage area.

The local variables (excluding temporary variables) of the function block of S7-300/400 are stored in its background data block. Other POUs can access variables in the background data block. If you need to call the same function block several times to control the same type of controlled object, you need to specify a background data block for each call, but there are few variables in these background data blocks, so there are a large number of background data blocks in the project. Multiple background data blocks can be used to reduce the number of background data blocks. However, a function block for managing multiple backgrounds needs to be added.

3) The local variables of S7-300/400 function block include temporary variables and static variables. The internal variable Var of IEC61131-3 function block is equivalent to the static variable of S7-300/400.

4) S7-300/400 divides the data area into data blocks for use. The size of the data block is related to the data type and number of variables defined in the data block. IEC61131-3 has no concept of data block.


Post time: Mar-03-2023