Categories
Categories

RSER200-4 PLC modular programming and structured programming analysis

In modular programming, OB1 plays the role of the main program, and FC or FB controls different process tasks, which is equivalent to the subroutine of the main loop program. In modular programming, the called block does not return data to the calling block.
Nov 27th,2023 189 Views
In modular programming, OB1 plays the role of the main program, and FC or FB controls different process tasks, which is equivalent to the subroutine of the main loop program. In modular programming, the called block does not return data to the calling block.

Modular program execution
In modular programming, OB1 plays the role of the main program, and FC or FB controls different process tasks, which is equivalent to the subroutine of the main loop program. In modular programming, the called block does not return data to the calling block.

Modular programming example
1. Modular programming example 1 - Liquid level monitoring
• Monitoring a slow change process does not require every scan. The program will be more efficient if the process is processed at regular intervals or as needed. • During the OB1 cycle scanning process, the level can be monitored according to a certain period.
Design method:
• Determine the components of level monitoring and their relationships;
• Design functions to complete the required control tasks;
• Plan program execution that calls block completion functions from OB
The process;
• Add a text comment and title to each segment of the block.
Solution:
• Establish a functional FC that can monitor and control tasks;
• Create an OB where blocks are called at regular intervals
(Function).
2. Modular programming example2
There are two motors, the control mode is the same, press the start button (motor 1 is I0.0, motor 2 is I1.0), the motor starts to run (motor 1 is Q4.0, motor 2 is Q4.1); Press the stop button (I0.1 for motor 1, I1.1 for motor 2) and the motor stops running.
Analysis:
This is a typical protection circuit, using the idea of modular programming, respectively in FC1 and FC2 to write the motor control program, in the main program OB1 FC1 and FC2 call.

Structured programming
The complex task is broken down into some small tasks that can reflect the process, function or can be used repeatedly, and these tasks are represented by the corresponding program blocks;
Some blocks can be used to achieve the same or similar functions;
Callers can be a variety of logical blocks, including user-written OB, FB, FC and system-provided SFB and SFC;
Ø The called block is a logical block other than OB;
Common data and code can be shared.

Structured programming
Advantages of structured programming:
1 The creation and testing of individual task blocks can be carried out independently of each other;
2 By using parameters, blocks can be designed to be very flexible;
3 blocks can be called in different places with different parameter data records according to needs;
4 In pre-designed libraries, it is possible to provide "reusable" blocks for special tasks.
Example of structured programming - Paint modulation
1 To select product additives, you need to decide which tank ingredients to add to the mixing tank.
2 On the basis of the selection of the selection switch, the organizational block calls the corresponding program block, allocates the current parameters, and controls the inflow of the mixing tank.
Design method:
1. Determine which components and operations can be applied to all tanks and associated controls;
2. Establish functions or functional blocks to complete the required control;
3. Establish the variable definition table of the block to facilitate the address allocation of the pot and control to be operated;
4. Design a program to call a function or function block according to the selection switch.
Solution:
1. Establish a function block or function control tank for outflow;
2. Create variable definition table for related blocks;
3. Create an OB block to invoke the function or function block according to the selection switch.