0% found this document useful (0 votes)
12 views32 pages

Lec 06 Siemens Programming Blocks

Uploaded by

waaw933050
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views32 pages

Lec 06 Siemens Programming Blocks

Uploaded by

waaw933050
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Taiz University

Siemens Programming
Blocks
October 2024

Eng: Mohammed AL-Hababy


Siemens PLCs
Lecture Objectives
❑ In this Lecture, you will get to know:
❖ The basic elements of a control program
➢ the organization blocks (OBs)
➢ functions (FCs)
➢ function blocks (FBs)
➢ data blocks (DBs).
Siemens PLCs
Operating system and application program
❑ Every controller (CPU) contains an operating system, which organizes all
functions and sequences of the CPU that are not associated with a specific
control task. The tasks of the operating system include the following:
1) Performing a warm restart
2) Updating the process image of the inputs and output
3) Cyclically calling the user program
4) Detecting interrupts and calling interrupt OBs
5) Detecting and handling errors by calling an error OB
6) Managing memory areas.
Siemens PLCs
Operating system and application program
❑ The operating system is an integral component of the CPU and comes pre-
installed.
❑ The user program contains all functions that are necessary for executing your
specific automation task.
❑ The tasks of the user program include the following:
1) Checking the basic requirements for a warm restart using start-up OBs
2) Processing of process data, i.e. activation of output signals as a function of
the input signal states.
3) Reaction to interrupts and interrupt inputs
4) Error handling during normal program execution
Siemens PLCs
Organization blocks (OBs)
❑ Organization blocks (OBs) form the interface between the operating system of
the controller (CPU) and the application program.
❑ They are called from the operating system and control the following
operations:
❖ Cyclic program processing (e.g. OB1)
❖ Start-up characteristics of the controller
❖ Interrupt-driven program processing
❖ Error handling
❑ A project must have, at a minimum, an organization block for cyclic program
processing.
Siemens PLCs
Organization blocks (OBs)
❑ An OB is called by a start
event as shown in Figure.
In addition, the individual
OBs have defined
priorities so that, for
example, an OB82 for
error handling can
interrupt the cyclic OB1.
Siemens PLCs
Organization blocks (OBs)
❑ When a start event occurs, the following reactions are possible:
❖ If an OB has been assigned to the event, this event triggers the execution of
the assigned OB. If the priority of the assigned OB is greater than the
priority of the OB that is currently being executed, it is executed
immediately (interrupt). If not, the assigned OB waits until the higher-
priority OB has been completely executed.
❖ If you have not assigned an OB to the event, the default system reaction is
performed.
Siemens PLCs
Organization blocks (OBs)

Types of Interrupt and Priority Classes


❑ Start events triggering an OB call are known as interrupts.
❑ The following table shows the types of interrupt in STEP 7 and the
priority of the organization blocks assigned to them.
❑ The following table of OB’s are applicable only to Siemens
CPU314C-2 PN/DP
Siemens PLCs
Organization blocks (OBs)
Siemens PLCs
Organization blocks (OBs)
Siemens PLCs
Functions FCs
❑ Functions (FCs) are logic blocks without memory. They have no data memory in
which values of block parameters can be stored. Therefore, all interface
parameters must be connected when a function is called.
❑ To store data permanently, global data blocks must be created beforehand.
❑ A function contains a program that is executed whenever the function is called
from another logic block.
❑ Functions can be used, for example, for the following purposes:
❖ Math functions – that return a result dependent on input values.
❖ Technological functions – such as individual controls with binary logic
operations.
❑ A function can also be called several times at different points within a program.
Siemens PLCs
Functions FCs
Siemens PLCs
Manual Mode Using FC
Siemens PLCs
Manual Mode Using FC
Siemens PLCs
Functions Blocks FBs
❑Function blocks are logic blocks that store their input, output and in-out tags as
well as static tags permanently in instance data blocks, so that they are available
after the block has been executed. For this reason, they are also referred to as
blocks with "memory".
❑Function blocks can also operate with temporary tags. Temporary tags are not
stored in the instance DB, however. Instead, they are only available for one cycle.
❑Function blocks are used for tasks that cannot be implemented with functions:
❖Whenever timers and counters are required in the blocks.
❖When information must be stored in the program, such as preselection of the
operating mode with a button.
Siemens PLCs
Functions Blocks FBs

❑ Function blocks are always executed when called from another logic block.
❑A function block can also be called several times at different points within a
program.
❑This facilitates the programming of frequently recurring complex functions.
❑The tags declared in the function block determine the structure of the
instance data block.
Siemens PLCs
Functions Blocks FBs

❑A call of a function block is referred to as an instance.


❑ Each instance of a function block is assigned a memory area that contains
the data that the function block uses. This memory is made available by
data blocks created automatically by the software. It is also possible to
provide memory for multiple instances in one data block in the form of a
multi-instance.
❑The maximum size of instance data blocks varies depending on the CPU.
Siemens PLCs
Functions Blocks FBs
Siemens PLCs
Motor Automatic FBs
Siemens PLCs
Motor Automatic FBs
Siemens PLCs
Function (FC) and Function Block (FB) Similarities/Differences in Siemens PLC-
S7 programming:
Similarities:
❑ We can define TEMP variable in both FB and FC.
❑ In FBD/LAD, you will see an ENO as the result of the FB/FC execution. If
it is a logical one, it means that FB/FC has been run with no problem.
❑ You can activate EN as enable for the FC/FB in LAD or FBD to make a
conditional execution.
❑ The possibility of using all Formal Parameters, IN, OUT, IN_OUT.
❑ There is always a limitation for the number of Nesting Depth in FBs and
FCs, refer to the CPU data sheet. They are usually 16 for the new S7-
300 processors.
Siemens PLCs
Function (FC) and Function Block (FB) Similarities/Differences in Siemens PLC-
S7 programming:
Differences:
❑Memory: FC has no instance memory, while FB has an Instance
Data Block (IDB). This IDB saves all IN, OUT, IN_OUT and STAT
parameters.
❑ They are accessible even after execution of the relevant FB.
❑Programming Language: You can program FC or FB with FBD, LAD,
STL and SCL programing languages, while just FB has the capability
to be programed in GRAPH.
Siemens PLCs
Function (FC) and Function Block (FB) Similarities/Differences in Siemens PLC-
S7 programming:

Note:
In FC programming, if you do not want to use the results of the FC
subroutines outside of it, it is always a good idea to use TEMP
variables, instead of Memory Bits (M) or Data Blocks (DB). This is
because of the possibility to call those M or DB addresses outside of
the FC, results in an inaccurate execution for the FC. Overall,
programmers do their best not to use Global variables in FC’s.
Siemens PLCs
Global data blocks DBs
❑ In contrast to logic blocks, data blocks contain no instructions. Rather, they serve
as memory for user data.
❑ Data blocks thus contain variable data that is used by the user program.
❑ You can define the structure of global data blocks as required. Global data blocks
store data that can be used by all other blocks.
❑ Only the associated function block should access instance data blocks.
❑ The maximum size of data blocks varies depending on the CPU.
❑ Application examples for global data blocks are:
❖ Saving of information about a storage system. "Which product is located
where?“
❖ Saving of recipes for particular products.
Siemens PLCs
Global data blocks DBs
Siemens PLCs
Instances and multi-instances in SIMATIC S7-1200
❑ An instance is assigned to every call of a function block and serves as a data
memory.
❑ It stores the actual parameters and the static data of the function block.
❖ Call as a single instance:
➢ A separate instance data block for each instance of a function block
❖ Call as a multi-instance:
➢ One instance data block for several instances of one or more function
blocks
Siemens PLCs
Instance data blocks / Single instances
The figure shows the control of
two motors using one function
block FB10 and two different
data blocks:
The different data for the
individual motors, such as
speed, acceleration time and
total operating time, are saved
in the instance data blocks
DB10 and DB11.
Siemens PLCs
Multi-instances

You may want to limit the


number of data blocks used for
instances or this may be
necessary due to lack of
memory in the utilized CPU.
If other function blocks, timers, counters, etc. that already exist are to be called
in a function block in your user program, you can call these other function
blocks without separate (i.e. additional) instance DBs. Simply select ‘Multi-
instance’ for the call options
Siemens PLCs
Multi-instances
In this case, the calling block
must always be a function block.
This allows you to concentrate
the instance data in one instance
data block and thus make better
use of the number of DBs
available. Incidentally, this is
always required when the calling
block is to remain available for
reuse as a standard block.
Siemens PLCs
Components of a basic Structured PLC Program
Siemens PLCs
Components of a basic Structured PLC Program
Siemens PLCs
Components of a basic Structured PLC Program
In organizing a PLC program, there are two common types;
❖ Linear – You can write your entire user program in OB1. This is only
advisable with simple programs written for the S7-300 CPU and
requiring little memory.
❖ Structured – Complex automation tasks can be controlled more
easily by dividing them into smaller tasks reflecting the technological
functions of the process or that can be used more than once. These
tasks are represented by corresponding program sections, known as
the blocks.

You might also like