How does STEP7 & TIA Portal (Totally Integrated Automation Portal) achieve modular program design?

 Siemens STEP7 & TIA Portal programming software series boasts powerful features, and its modular programming philosophy enables clear system logic, ease of maintenance, and modification—critical for the design of large and complex projects. In today's article, we will discuss how STEP7 & TIA Portal achieve modular program design.











For a complex automation control task, we often divide it into subtasks based on its internal logic relationships. This simplifies the overall project, making it easier to implement.

As an analogy: Suppose we want to travel to Europe and need to consider transportation, accommodation, shopping, and sightseeing. The task "Travel to Europe" is then broken down into four subtasks: "Transportation," "Accommodation," "Shopping," and "Sightseeing." Each subtask is completed separately (e.g., booking a flight for "Transportation," reserving a hotel for "Accommodation," and so on). When all subtasks are completed, the entire task is accomplished.

Siemens STEP7 & TIA Portal introduce this simplification approach to program design. The entire project program can be divided into small subprograms, programmed separately as "blocks," and these blocks can be interconnected through logical relationships. This programming method of breaking down complex programs into small "blocks" is called "modular program design."

Modular program design enhances logical clarity, provides transparent organizational structure, and increases program comprehensibility and maintainability. It is easy to modify, debug, and check for errors. Created blocks can be reused, reducing programming workload and improving efficiency.

In the previous article "PLC Basics: Birth and Working Principles of PLC," we discussed that PLC's internal programs include operating system programs and user programs. The design of the operating system itself is not within the scope of today's discussion. Here, we primarily focus on the interface between the operating system and user programs, along with the modular design of user programs.

Organization Blocks (OB) serve as the interface between the operating system and user programs. The operating system calls specific organization blocks to perform particular functions. User programs must be written into organization blocks to be callable.

Organization Blocks (OB) can be categorized into startup organization block, cyclically called organization block, and interrupt organization block.

  • Startup Organization Block: When the CPU switches from stop mode to start mode, the operating system calls the startup organization block once (note: only called once). The main purpose of the startup organization block is to initialize some variables.

  • Cyclically Called Organization Block: Also known as the main program block, usually designated as OB1. The cyclically called organization block serves as the entry point for user programs, similar to the "Main function" in the C language.

  • Interrupt Organization Block: When an interrupt occurs, the operating system calls the interrupt organization block. STEP7 specifies the numbering of interrupt organization blocks, each associated with a specific interrupt. The interrupt organization block contains the user-written interrupt handling program (refer to "How Does the Interrupt Mechanism Make PLC Efficient?").

The above-mentioned structures form the organizational framework for the interface between the operating system and user programs. Now, let's discuss the modular design of user programs.

In user programs, we can save the code that accomplishes a specific function as a "block," referred to as a "Function Block (FB)" or "Function (FC)." Both "Function Block (FB)" and "Function (FC)" are collections of code that can achieve a particular function, constituting a subroutine. The key difference lies in that "Function Block (FB)" requires a specific data block (Data Block, DB) to store static variables, while "Function (FC)" doesn't have static variables and therefore does not require a specific data block.
















The specific data block (DB) required by a "Function Block (FB)" is called an Instance Data Block (IDB). The Instance Data Block's properties are private, accessible only by the "Function Block (FB)" to which it belongs.

In contrast, another type of data block is the Global Data Block (GDB). The Global Data Block is public and can be accessed by all "Function Blocks (FB)" or "Functions (FC)."

When designing complex projects, subtasks can be organized into "Function Blocks (FB)" or "Functions (FC)." These "Function Blocks (FB)" or "Functions (FC)" can call each other, and when a called function block internally invokes another function block, this type of call is termed "nested call," and the number of levels of invocation is referred to as "nesting depth." Different CPUs support different nesting depths, and this information can be found in the respective manuals. For example, the nesting depth for CPU 1215C is illustrated in the following diagram: