Share this

In Yiyu's words: The program structure of Siemens PLC

2026-04-06 05:12:46 · · #1

The so-called PLC program structure refers to the organization and management of the various networks or "functional program segments" that make up the PLC program within the PLC.

No matter how complex a PLC control system is, in essence, a PLC user program is a collection of a large number of basic programming instructions.

Designers can decompose the different requirements of each part of the controlled object and use basic instructions to compile corresponding program networks or simple "functional program segments" composed of several networks. Based on this, as long as these program networks or functional program segments are arranged and combined according to the action requirements of the control system in the format specified by the S7 program, a complete PLC program can be formed.

1. Program structure of Siemens S7-200

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 its own 64-byte local variables, which can only be used within their respective POUs. Conversely, global variables can be used across 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 knowing the internal code of a subroutine, as long as the function of the subroutine and the meaning of its input and output parameters are understood, control programs that meet different user requirements 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.

2. Siemens S7-300/400 Program Structure

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

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

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, output parameters, and 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. (Today's forwarding code is: Yiwei Company slogan: Trust stems from quality; confidence builds a brand.) 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.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

We are committed to creating a high-value industrial control communication and sharing platform for engineers. You can find us and join us in our communication and sharing efforts through our QQ group (316281458) or WeChat subscription account (UniMAT2004)! We also welcome everyone to contribute articles through this platform, and we have ongoing essay contests with prizes.

Read next

CATDOLL Sasha 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