Share this

PLC Program Structure and Characteristics

2026-04-06 06:30:20 · · #1

The following describes several common PLC program structures and their characteristics:

1. Program structure of some foreign small PLCs

These PLC user programs consist of a main program, subroutines, and interrupt routines. The CPU calls the main program once in each scan cycle. The main program can call subroutines; small control systems may only have a main program. Interrupt routines are used for quick response to interrupt events. When an interrupt event occurs, the CPU will stop executing the currently processed program or task and execute the user-written interrupt routine. After executing the interrupt routine, execution of the suspended program or task resumes. Their subroutines and interrupt routines have no local variables, and subroutines have no input or output parameters.

2. Siemens S7-200 Program Structure

Process image inputs/outputs (I/Q), variable memory V, internal memory bits M, timers T, counters C, etc., are global variables. The S7-200's Program Organizational Unit (POU) includes the main program, subroutines, and interrupt routines. Each POU has...

Each variable is a 64-byte local variable, which can only be used within its own Point of Use (POU). In contrast, global variables can be used in all POUs.

The following are the local variables that can be used by a subroutine:

1) TEMP (temporary variable) is a variable that is temporarily stored in the local data area. The temporary variable is only used when the POU is executed, and its value is no longer saved after the POU is completed.

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

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

4) IN_OUT is the input-output parameter. Its initial value is passed to the subroutine by the POU that calls it, and the execution result of the subroutine is returned to the POU that calls it using the same variable.

The main program and interrupt routines have only the temporary variable TEMP as their local variables.

Subroutines, with their input and output parameters and local variables, facilitate structured programming, making them particularly useful for manufacturers that have long produced similar equipment or production lines. These manufacturers' programmers have written numerous generic subroutines for various components or process functions of their equipment. Even without knowledge of subroutines...

By understanding the internal code of the program, as long as the function of the subroutines and the meaning of the input and output parameters are known, control programs that meet the requirements of different users can be quickly "assembled" through inter-program calls. This is similar to assembling complex digital circuits using digital integrated circuit chips.

If a subroutine has no input or output parameters, there is no clear interface between it and the program that calls it, making it difficult to implement structured programming.

If a subroutine lacks local variables, it and the calling program can only exchange data through global variables, and the subroutine itself can only use global variables. When porting subroutines and interrupt routines to other projects, it is necessary to reorganize the global variables they use to ensure that address conflicts do not occur. When the program is very complex and has many subroutines and interrupt routines, this workload of reallocating addresses is very large.

If subroutines and interrupt routines have local variables, and they only use local variables and not global variables, they can be ported to other projects without any modifications because there are no address conflicts with other POUs.

3. Siemens S7-300/400 Program Structure

S7-300/400 divides subroutines into functions and function blocks.

The functionality of S7-300/400 subroutines is essentially the same as that of S7-200 subroutines. They both have input and output parameters and temporary variables; the return value in the local data of a function is actually an output parameter. They do not have dedicated storage areas; after the function execution ends, the data in temporary variables is no longer saved. Global variables can be used to store data that needs to be saved after the function execution, but this will affect the portability of the function. Function blocks are user-written program blocks with their own dedicated storage areas (i.e., background data blocks). The input, output parameters, and static variables of a function block are stored in the specified background data.

Global variables can be used to store data that needs to be saved after the function finishes execution, but this will affect the portability of the function.

A function block is a user-written program block with its own dedicated storage area (i.e., a background data block). The function block's input and output parameters, as well as static variables, are stored in the designated background data block, while 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 finishes execution, the data in the background data block is not lost, but the data in the local data stack is not saved.

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

The shared data blocks of the S7-300/400 are available to all logical blocks.

4. The program structure of IEC 61131-3

IEC 61131-3 is the programming language standard for PLCs. It is the world's first and, to date, only programming language standard in the field of industrial control. IEC 61131-3 has three types of Programming Units (POUs): Program, Function Block, and Function.

A function is a Point-of-Use (POU) with multiple input parameters and one output parameter (return value). The return value has the same name as the function, and its data type needs to be defined. Calling a function with the same input values ​​will always return the same result. A function can call other functions, but it cannot call function blocks or programs. The local variables that can be defined for a function are `VAR` and `VAR_INPUT`.

A function block is a Point of Interest (POU) with multiple input/output parameters and internal storage units. The output parameter values ​​of a function block are related to the values ​​in its internal storage units. A function block can call other function blocks or functions, but it cannot call the program itself. Before calling a function block, an instance of the function block must be declared in the POU of the block to be called for each call. The operating system will allocate a dedicated storage area for the function block for each call.

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

Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964 ) . We apologize for any inconvenience.

Read next

CATDOLL Cici Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22