4/19/2024
ADVANCED PLC
Dr. Tamer Fetouh
User Program Structure
• According to the application, you can create the user program in two
different structures:
1
4/19/2024
User Program Structure
1. Linear structure
• A linear program executes all instructions in sequence, one after the
other.
• All instructions are put into the Organization Block (OB) for the cyclic
execution of the program (OB 1).
User Program Structure
2. Modular structure
• A modular program calls specific code blocks that perform specific
tasks.
• In this structure, the complex automation task is divided into smaller
subordinate tasks.
• Each code block provides the program segment for each subordinate
task.
• You structure your program by calling one of the code blocks from
another block.
4
2
4/19/2024
Program Blocks
Different BLOCK types are available to perform tasks within an automation system.
The following table shows the available block types:
Program Blocks
1. Organization Blocks (OB)
• Organization blocks (OBs) form the interface between the operating system
and the user program.
• They are called by the operating system and control, for example, the
following operations:
1. Startup characteristics of the automation system
2. Cyclic program processing
3. Interrupt-driven program execution
4. Error handling
3
4/19/2024
Organization Blocks
• You can program the organization
blocks and at the same time
determine the behavior of the
CPU.
• Various organization blocks are
available to you depending on the
CPU used.
Organization Blocks
1. Program cycle OB
• It is executed cyclically and is the main block of the program.
• This is where you place the instructions that control your application
and call additional user blocks.
2. Startup OB
• A "Startup" OB will execute one time when the operating mode of the
PLC changes from STOP to RUN.
• After completion, the main "Program cycle" OB will begin executing.
4
4/19/2024
Program Structure
Functions
• You can add a new Function from
Program Blocks menu under the project
tree as shown in Fig.
• You can name the
Function and select
the programming
language as shown
in Fig.
10
5
4/19/2024
Functions
• The block has different types of
parameters given as in Fig.
• These are the variable names or
local Tags used inside the block
only.
• These parameters have different
types with different data types.
• You can assign a default value for
any parameter as an initial value.
11
Block Parameters
• The block parameters are defined in the interface of the called block.
• These parameters are referred to as formal parameters.
• They are placeholders for the parameters that are transferred to the
block when it is called.
• The parameters transferred to the block when it is called are referred
to as actual parameters.
• The data types of actual and formal parameters must be identical or
convertible according to the rules of data type conversion.
12
6
4/19/2024
Block Parameters
• Block parameters form the interface between the calling and the called
block.
• The following rules apply to the use of block parameters within the block:
1. Input parameters: used when you want to only read values.
2. Output parameters: used when you want to set or write values.
3. In/out parameters: used when you want to read and write values.
13