Step7 program execution principle and programming method - Database & Sql Blog Articles

Programmable Package SG-8018CA(SG7050C) 0.67M~170M
Photocoupler

How does a PLC execute its loop program? (This is a crucial concept to understand.)

1. Execution of the Loop Program

The execution process of a PLC loop program is fundamental to understanding how automation systems function. Here's a breakdown of the steps involved:

1.1 After the CPU is powered on, the startup block (OB100/101/102) runs once. Which specific OB block is executed depends on the system’s configuration for startup mode.

1.2 Once the startup block completes, the system initiates a cycle monitoring time. This duration can be set in the hardware configuration within STEP7. If the cycle time exceeds the set limit, the PLC will stop.

1.3 After that, the CPU reads all input states from the input modules and other process image devices.

1.4 Then, the main loop program is executed. The main loop follows a sequential order, as shown in the diagram. For example, when OB1 starts, it may call an FB (Function Block), which then executes its own instructions sequentially.

1.4.1 If during the execution of the FB, another FC or FB is called, the program moves into the next level of blocks, executing them one by one.

1.4.2 When the lower-level FC finishes execution, the program returns to the point where the FC was called and continues with the next instruction.

1.4.3 Once the FB is fully executed, the program returns to the original call point in OB1 and proceeds with the remaining instructions.

1.4.4 This continues until the entire OB1 program is completed, marking the end of the main loop.

1.4.5 During the execution of OB1, cyclic interrupts (like OB35) and fault interrupts (such as OB86) can be triggered and executed. After their completion, the program resumes from the interrupted point.

1.5 After the main loop finishes, the PLC writes the updated output values from the process image back to the output modules.

1.6 Once this is done, the entire cycle is complete. The system then goes back to step 1.2, restarting the cycle timer for the next iteration.

2. Types of Blocks in STEP7

Now that you understand how the PLC loop program works, let's explore the different types of blocks used in STEP7 programming.

2.1 User Blocks

User blocks contain both program code and user data. In structured programs, some blocks are called cyclically, while others are invoked only when needed.



2.1.1 Organization Block (OB)

OB blocks serve as the interface between the S7CPU and the user program. While OB1 is commonly used for continuous looping, other OBs can be called based on specific events, such as:

- Time-date interrupts
- Cyclic time interrupts
- Diagnostic interrupts
- Hardware interrupts
- Error handling (e.g., OB86)
- Startup routines (e.g., OB100)

2.1.2 Function Block (FB)

An FB is a logical unit that contains functions and variables. It requires an instance data block (DB) to store parameters and local variables. Data in the DB persists even after the FB is closed, but local stack variables are temporary and not saved.

2.1.3 Function (FC)

A function (FC) is similar to an FB but doesn’t have its own memory area. It uses the local stack for temporary variables, which are lost once the function ends.

2.1.4 Data Block (DB)

A DB is a predefined memory area used to store data that can be accessed by multiple parts of the program. It is essential for storing shared data or configurations.

2.2 System Blocks

System blocks are pre-defined functions and blocks provided by the CPU’s operating system. These do not take up user program space and are used for standard operations like communication, diagnostics, and configuration.



2.2.1 System Function (SFC)

SFCs are pre-programmed functions that handle tasks like setting module parameters or data transfer. They don’t require an instance DB and can be called directly.

2.2.2 System Function Block (SFB)

SFBs are integrated into the CPU’s OS and can be called directly. Unlike SFCs, they require an instance DB, which must be downloaded with the program.

2.2.3 System Data Block (SDB)

SDBs are generated by STEP7 tools and contain system-specific data such as configuration settings and communication parameters.

3. Programming Methods

Now that you understand how the PLC loop works and the different block types, it’s time to look at the various programming methods available in STEP7.

Every Siemens programmer has their own style, but STEP7 offers three main approaches:

3.1 Linear Programming

All instructions are written in a single, continuous block. This method is straightforward and resembles traditional relay logic, making it ideal for small applications.

3.2 Modular Programming

The program is divided into separate blocks, each responsible for a specific task or device. The organization block determines which modules to call. This approach improves readability and maintainability.

3.3 Structured Programming

This method uses user-defined blocks with parameters, allowing for reusable code. Parameters are assigned dynamically during calls, making it highly flexible and efficient for complex systems.

HP Elitebook 840 845 G8

HP Elitebook 840 G8,HP Elitebook 840 G8 Keyboard,HP Elitebook 840 G8 LCD,HP Elitebook 840 G8 replacement parts

S-yuan Electronic Technology Limited , https://www.syuanelectronic.com