An Example of Large-Scale Siemens PLC Program Structure!

                                                                                                  PART 01


Program Blocks     


OB1: Main Program;

OB100: Initialization Program (invoked automatically, without the need for main program calling);

OB35: 100ms (modifiable) Interrupt (also invoked automatically, without the need for main program calling), capable of calling PID modules;

OB80, OB82, OB85, OB86, OB87, OB121, OB122: Fault Diagnosis Modules (automatically invoked, no programming required);

FC1: System Mode;

FC2: Input Processing;

FC3: Output Processing;

FC4: Run Processing;

FC5: Stop Processing;

FC6: Manual/Automatic Switchover;

FC100: Intended for subsequent creation of reusable subroutines that can be cyclically called;

FC105: Built-in system subroutine for analog input processing (can be cyclically called);

FC106: Built-in system subroutine for analog output processing (can be cyclically called);

Modbus Communication (CP341): FB7: P_RCV_RK, FB8: P_SND_RK;

Communication CP340: FB2: P_RCV, FB3: P_SND;

General PID Control: Utilize FB41;

Temperature and Humidity PID Control: Utilize FB58;

In case of overlap between program blocks and system blocks, please avoid conflict.

                                                                                             PART 02


Data Blocks


DB1: AI Data, Type: REAL, Interface with HMI (Human-Machine Interface);

DB2: AO Data, Type: REAL, Interface with HMI;

DB3: DI Data, Type: BOOL, Interface with HMI;

DB4: DO Data, Type: BOOL, Interface with HMI;

DB5: Equipment Runtime and Flow Accumulation, Type: REAL, Interface with HMI;

DB6: Alarm Messages, Type: BOOL, Interface with HMI;

DB7: Intermediate Registers, Type: REAL;

DB8: Intermediate Registers, Type: INT;

DB9: Intermediate Registers, Type: WORD;

DB10: Intermediate Registers, Type: BOOL;

DB11: Reserved for future use in device communication, such as MODBUS communication, etc.;

DB100: Reserved for use as a background data block when calling FB (Function Block) modules;

M Area: Also used as intermediate variables.

                                                                                                                PART 03


Fault Diagnosis for DP Slaves


It is necessary to implement fault diagnosis and fault alarming for DP slaves. This can be achieved by utilizing the FB125 function block.






PART 04

Control Modes
  1. System Setup with Remote/Local/Manual Buttons

1.1 Remote: The system can only be automatically started/stopped via the HMI (Human-Machine Interface). Local control of individual devices takes precedence. During programmed control, the HMI allows for soft manual operation/automatic switching and soft manual start/stop of devices.


1.2 Local: The system can only be automatically started/stopped via the touchscreen. Local control of individual devices takes precedence. During programmed control, the touchscreen allows for soft manual operation/automatic switching and soft manual start/stop of devices.

1.3 Manual: During manual control, the HMI/touchscreen becomes inactive, and the start/stop of devices can only be controlled manually.

  1. Individual Device Control

Each individual device must have the capability for soft manual operation/automatic switching, as well as the ability to start/stop during soft manual operation. When switching from automatic to soft manual operation, the device should not shut down. When switching from soft manual operation back to automatic, the start/stop of the device depends on the automatic program.

  1. Individual Devices (Pumps, Fans, and Other Large Equipment)


Individual devices must be rotated every 24 hours of operation, and there must be a cumulative record of operating time. However, if the start/stop sequence is set by the HMI, this rule does not apply, and operators may set their own sequences.



PART 05

Programing Techniques

  1. Break down program blocks as much as possible to enhance readability. Group control logic for the same type of equipment within a single program block.

  2. When faced with special circumstances requiring textual programming, opt for ladder diagram programming in most cases as it is more intuitive and easier for others to understand.

  3. Create subroutines or submodules for frequently called functions, such as calculating the average or maximum value of several numbers, to streamline code reuse.

  4. Include comments in your programs. Ensure that variables and intermediate variables are properly described to facilitate reading and future reference by others.

  5. Regularly back up your programs, preferably using a naming convention that includes the project name, system name, and the current date.

  6. Encrypt your programs to prevent unauthorized access and protect your intellectual property.