You are on page 1of 32

Block Calls and the Multiple Instance Model

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

18.09.2009
PRO3_02E.1

SITRAIN Training for


Automation and Industrial Solutions

Contents
Page
Blocks for Structured Programming
................................................................................................
2
Block Overview in STEP 7 ...............................................................................................................
3
Instance Formation of Function Blocks ............................................................................................
4
Structure of the Multiple Instance Model .............................................................................................
5
Characteristics of the Multiple Instance Model .................................................................................
6
Basic Program of the Production Line .............................................................................................
7
Parameter Description: "FB_Main_Station" (FB 2) Block
...............................................................
9
Parameter Description: "FB_Station" (FB 3) Block ............................................................................. 10
Parameter Description: "FB_Belt" (FB 4) Block
............................................................................. 11
Interconnecting the Blocks (Initial Situation) .................................................................................... 12
Exercise 1: Creating a HW Station and Commissioning the Program
............................................ 13
Task Description: "FB_Sequence" (FB 30)
..................................................................................... 14
Sequential Control of Part Processing using "FB_Sequence" ....... 15
Sequence of Part Processing (According to IEC61131-3) ............................................................... 16
Static Variables of "FB_Sequence" (FB 30)
.. 17
Parameter Description: "FB_Sequence" (FB 30) Block ................................................................... 18
Exercise 2: Integrating the "FB_Sequence" (FB 30) Block
............................................................. 19
Object-Oriented Programming by Means of Multiple Instances............................................................ 20
Implementing a "Press Line" in STEP 7
..................................................................................... 21
Task Description: Multiple Instance Model ........................................................................................ 22
Exercise 3: Programming the Processing Time with SFB 4 "TON" ................................................. 23
Task Description: Multiple Instance "FB_Line" (FB 31)
.................................................................. 24
Exercise 4: Programming the "FB_Line" (FB 31)
.......................................................................... 25
If You Want to Know More ............................................................................................................... 26
Sequence of the Part Processing (According to IEC61131-3)
........................................................ 27
Sequencer: Conversion in STEP 7 (FBD) ....................................................................................... 28
Static Variables of "FB_Sequence" (FB 30)
... 30
Parameter Description: "FB_Sequence" (FB 30) Block ................................................................... 31
Structogram for "FB_Sequence" (FB 30)
....................................................................................... 32
SITRAIN Training for
Automation and Industrial Solutions

Page 1

ST-PRO3
FBs and the Multiple Instance Model

Blocks for Structured Programming


Modularization of the
Entire Task:

OB 1

Partial tasks are solved in


their own blocks
z Parameter assignment
enables flexible usage
Example: Drilling cycle
with parameterassignable depth

Controller
Controller

OB 1

CALL
FB1, DB2
Start
:=I 0.0
Stop
:=I 0.1
Motor_on :=Q12.0
Speed
:=QW14

.
.

18.09.2009
PRO3_02E.2

Copying

DB 2

Address
0.0
0.1
2.0
4.0
6.0
0.0
.
.
.
A
AN
=
.

. . .
SFC

FC 5
Limit
value

FB 1
.
.

Date:
File:

Siemens AG 2008. All rights reserved.

Motor 1
Motor 1

Valves
Valves

SIMATIC S7

FB10

FB2

Re-usability of Blocks:
Blocks can be called as
often as is required
z Restrictions:
no access to global
addresses
communication only via
the parameter list

FB1

Decl.
in
in
out
out
stat
temp

Name
Start
Stop
Motor_on
Speed
Speed_old
Calc_1

Type
BOOL
BOOL
BOOL
INT
INT
INT

#Start
#Stop
#Motor_on

SITRAIN Training for


Automation and Industrial Solutions

Modularization
of Tasks

Abstraction is the basis for solving complex problems, in which we concentrate


on the fundamental aspects of a program in every abstraction level and ignore
all the details that are not essential. Abstraction helps us to divide complex tasks
into partial tasks which can then be solved on their own.

Structured
Programming

STEP7 supports this concept of modularization with its block model. The partial
tasks that result from the division of the entire task are assigned blocks in which
the necessary algorithms and data for solving the partial problems are stored.
STEP7 blocks such as functions (FC) and function blocks (FB) can be assigned
parameters so that the concepts of structured programming can be implemented
with them. This means:
Blocks for solving partial tasks implement their own data management with
the help of local variables.
Blocks communicate with the "outside world", that is, with the sensors and
actuators of the process control or with other blocks of the user program,
exclusively through their block parameters. No access to global addresses
such as inputs, outputs, bit memories or variables in DBs can be made from
within the instruction section of blocks.

Advantages

Structured programming has the following advantages:


The blocks for the partial tasks can be created and tested independent of
one another.
With the help of parameters, blocks can be designed so that they are
flexible. That way, for example, a drilling cycle can be created that has the
coordinates and the depth of the drilling hole passed on to it by means of
parameters.
Blocks can be called as often as is required in different locations with
different parameter data records, that is, they can be reused.
"Re-usable" blocks for special tasks can be delivered in pre-designed
libraries.

SITRAIN Training for


Automation and Industrial Solutions

Page 2

ST-PRO3
FBs and the Multiple Instance Model

Block Overview in STEP 7


Type of Block

Properties

Organization
block (OB)

- user interface
- graduated priorities (0 to 27)
- specific start information in the local data stack

Function block (FB)

- parameter-assignable (parameters can be assigned in a call)


- with (recall) memory (static variables)

Function (FC)

- parameter-assignable (parameters must be assigned in the call)


- basically without memory (only temporary variables)

Data block (DB)

- structured local data storage (Instance DB)


- structured global data storage (valid throughout the entire program)

System function
block (SFB)

- FB (with memory) stored in the CPUs operating system and


callable by the user

System
function (SFC)

- function (without memory) stored in the CPUs operating system


and callable by the user

System data
block (SDB)

- data block for configuration data and parameters

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.3

SITRAIN Training for


Automation and Industrial Solutions

Blocks in STEP 7

Blocks are, by their function, their structure or their application, limited parts of
the user program. The blocks in STEP 7 can - in keeping with their contents - be
divided into two classes :
User Blocks: User blocks include Organization Blocks (OB), Function Blocks
(FB), Functions (FC) and Data Blocks (DB).
The programming person stores the program instructions for data
processing or process control in the blocks (OB, FB and FC).
In the data blocks (DB), the programming person can save data that occur
during program execution and then reuse them at a later time.
User blocks are created in a programming device and are downloaded from
there into the CPU.
System Blocks: System blocks include System Function Blocks (SFB),
System Functions (SFC) as well as the System Data Blocks (SDB).
SFBs and SFCs are used to solve frequently required PLC standard tasks.
They are integrated in the CPUs operating system.
SDBs contain parameter assignment data that are evaluated exclusively by
the CPU. SDBs are not created or written by the user program, but by tools
such as HW-CONFIG or NETPRO.
SDBs are created by these tools during saving of the parameter
assignment data - invisible to the user - and downloaded into the CPU.
Downloading is only possible in the STOP mode.

Downloading
Blocks Later On

In addition to the advantages of structured programming, the STEP 7 block


concept also provides the following advantage:
User blocks (OB, FB, FC and DB) in STEP 7 can be modified and
downloaded into the CPU during runtime.
That way, software parts of the system can be upgraded during running
operation or (software) errors that occur can be eliminated, for example.

SITRAIN Training for


Automation and Industrial Solutions

Page 3

ST-PRO3
FBs and the Multiple Instance Model

Instance Formation of Function Blocks


OB, FB or FC

DBy

FBx
z FB call with
Instance DB

Algorithms
for control
logic

Call FBx, DBy

Status
data
of
conveyor

Conveyor
FB Instance
DBy

FBx

z Declaration
CALL FBx, DBy
within FBs
(Multi-instances)

...
stat Guard
stat Punch
CALL #Guard
CALL #Punch

FBa
FBc

Status
data
of guard

Guard

Status
data
of punch

Punch

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.4

SITRAIN Training for


Automation and Industrial Solutions

What is an
Instance?

The concept of instantiating function blocks has great importance and makes up
the essential distinctive criterion to the FCs. The setting up of variables within a
high level language such as "C" under declaration of variable name and data
type in the declaration is called "instantiate" or "instance forming".
Just like variables, function blocks are also "instantiated". Only through this
own data area, in which the block parameter values as well as the static
variables are stored, does an FB become an executable unit (FB-instance).
The control of a physical process unit, such as a drive or a boiler then takes
place with the help of an FB instance, that is, a function block with an assigned
data area. The relevant data for this process unit are then stored in this data
area.

Instantiating

You can create an FB instance, that is, the assignment of its own memory area
in an FB call, in two ways in STEP 7:
through the explicit declaration of an instance data block when a function
block is called.
through the explicit declaration of instances of a function block within a
higher-level function block (multiple instance model).
STEP 7 then makes sure that the data area required for the instance is set
up within the data area of the higher-level FB.

Advantages

The instance concept of STEP 7 has the following advantages:


In the call of FBs, no measures for saving and administrating local data are
necessary except for the assignment of instance DBs.
A function block can be used several times due to the instance concept. If,
for example, several drives of the same type are to be controlled, then this
takes place using several instances of an FB. The status data of the
individual drives are stored in the static variables of the FB.

SITRAIN Training for


Automation and Industrial Solutions

Page 4

ST-PRO3
FBs and the Multiple Instance Model

Structure of the Multiple Instance Model

FB4

FB10
...
stat Guard
stat Punch
stat Conv.

Such as OB1

FB4
FB5
FB2

Control
logic
for a
guard

DB10
Data
for guard

FB5

CALL FB10,DB10
CALL Guard

Control
logic
for a
punch

.
CALL Punch

Data
for punch

.
CALL Conv.
FB2

The figure shows a possible technological


structure when only a press and a
conveyor exist.

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

Control
logic
for a
conveyor

18.09.2009
PRO3_02E.5

Data
for
conveyor

Instance DB of FB10

SITRAIN Training for


Automation and Industrial Solutions

Multiple Instance
Model

In addition to instantiation of function blocks, when you specify an instance


DB in an FB call, STEP 7 also supports the explicit declaration of FB instances
within a higher-level function block.
For this purpose, instances of the called function blocks are declared with data
type FB4, FB5 or FB2 using symbolic identifiers (Guard, Punch and Conveyor).
This takes place in the declaration section of the calling FB 10 function block in
the "static variable" section, as illustrated above. Within the higher-level function
block, the individual instances are then called using their symbolic identifier. The
higher-level FB10 function block must, however, be called with its own instance
DB (DB10).
In the creation of the higher-level instance DB, STEP 7 makes sure that the data
areas required for the individual instances are set up in the data area of the
higher-level FB10.
In the call of the individual instances using the symbolic names, the CALL macro
makes sure that the AR2 register is set to the beginning of the data area
assigned to the instance so that the parameters and local variables of the
instance are also accessed during the processing of the called function block.

Benefits

The use of the multiple instance model has the following benefits:
The individual instances do not require their own data block every time.
Within a call hierarchy of function blocks, only one instance DB is used in
the call of the "outer" function block.
The multiple instance model "welds" a function block and an instance data
area into one object (FB instance), that can also be handled as one unit. The
programming person does not have to take care of the management
(creation, addressing) of the individual instance data areas. He must simply
provide an instance DB for the "outer" FB.
The multiple instance model supports an object-oriented programming style.

SITRAIN Training for


Automation and Industrial Solutions

Page 5

ST-PRO3
FBs and the Multiple Instance Model

Characteristics of the Multiple Instance Model


Benefits of the multiple instance model:
z

Only one DB is required for several instances

No additional management is necessary in the setting up of "private"


data areas for the respective instances

The multiple instance model makes an "object-oriented programming


style" possible (re-usability by means of "aggregation")

Maximum nesting depth of eight

Prerequisites for the FBs:


z

Direct access to the process signals (I, Q) within the FB is not possible

Access to process signals or communication with other process units


can only take place using FB parameters

The FB can only remember process states in its static variables, and
not in global DBs or bit memories

Note:
z

Instance data can also be accessed from "outside" of the instance FB.
For example, in OB1: L "Pressline".Press_2.Punch.<Varname>

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.6

SITRAIN Training for


Automation and Industrial Solutions

Benefits of the
Multiple Instance
Model

With the multiple instance model you can store the respective data sections of
several instances of one and the same call hierarchy in one single DB.
That way only one DB is required for several instances.
With the multiple instance model no measures for the administration of local FB
data are necessary except for the assignment of a mutual instance DB.
The multiple instance model supports the concept of object-oriented
programming. Code and data that are needed for the controlling of process units
are summed up in FBs.
If a process unit consists of hierarchical sub units then exactly this structure can
be reflected in the user program by means of the multiple instance model.
The control program can be designed with FB instances the same way as the
machine may consist of components.
STEP7 supports a nesting depth of eight with the multiple instance model.

Prerequisites for
Multiple Instances

To use an FB as a multiple instance without problems, you must adhere to the


following:
For the purpose of process control, no direct access to global addresses of
the CPU (such as inputs and outputs) is allowed. Each access to global
inputs and outputs violates the re-usability.
Communication with the process or with other program sections (FBs)
must be done only using FB parameters.
Only after integration of the FB into a higher-level unit, is the "assignment" of
the FB through the parameter list carried out with the FB call.
In its own static variables, the FB must "remember" states or other
information about the unit.

SITRAIN Training for


Automation and Industrial Solutions

Page 6

ST-PRO3
FBs and the Multiple Instance Model

Basic Program of the Production Line


I 0.0

T_System_ON

I 0.1

I 0.4

T_System_OFF L_SYSTEM
L_MAN
T_Jog_RIGHT
L_AUTO
T_Jog_LEFT
S_M/A_ModeSelect

I 0.5

T_M/A_Accept

I 0.2
I 0.3

Q 4.0
Q 4.1
Q 4.2
Q 4.3

I 0.6

Station 1 Station 2 Station 3

I 0.7

"BAY1"

"BAY2"

Raw
Material

"BAY3"

"L_Bay2"
"T_Bay2"

"L_Bay3"
"T_Bay3"

Main
(Load/Unload)
Station
"LB"

"T_Bay-LB"
"L_Bay-LB"

"L_Bay1"
"T_Bay1"

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.7

SITRAIN Training for


Automation and Industrial Solutions

How the Production


Line Works

The production line consists of the processing stations 1 to 3, a main station


and a conveyor belt. Raw material that is placed on the light barrier of the main
station is processed at the stations in the sequence 3-2-1 (in other words, from
right to left). It is then returned to the main station as a completed part.

Operating Modes

You switch the system on (simulator output Q 4.1) through the simulator
input I 0.0. It is switched off through the N.C. simulator pushbutton I 0.1.
You can preselect the MANUAL mode (simulator output Q4.2) through the
simulator switch I 0.4 ( = 0) and the AUTO mode (simulator output Q4.3)
through the simulator switch I 0.4 ( = 1).
The operating mode that is preselected through the simulator switch I 0.4 is
accepted or switched on through the simulator pushbutton I 0.5.
When you change the operating mode selection (I 0.4) or switch off the
system (Q 4.1), the operating modes are switched off.

MANUAL Mode

In the MANUAL mode (Q 4.2 = 1), you can have the conveyor motor jog to the
right using the simulator pushbutton I 0.2 or to the left using I 0.3.

AUTOMATIC Mode

After raw material has been loaded onto the conveyor (at LB) at the main
station and the pushbutton "T_Bay-LB" has been pressed, movement to Station
3 begins. When the raw material arrives at Station 3, the stations LED begins to
flash to signal the operator that processing has begun. When processing of the
part is finished at Station 3, the operator acknowledges the completion by
pressing the stations pushbutton, "T_Bay3". This starts the movement to
Station 2. Processing at Station 2 and then Station 1 works the same as in
Station 3. After completion at Station 1 has been acknowledged, the finished
part is transported back to the main station for unloading. The flashing LED here
indicates that the completed part can be removed. When the part has been
removed from the light barrier, the LED switches to a steady light thus signaling
that a new piece of raw material can be placed on the conveyor.

SITRAIN Training for


Automation and Industrial Solutions

Page 7

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Modes" (FB 1) Block

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

SITRAIN Training for

18.09.2009
PRO3_02E.8

Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

T_ON

BOOL

Switch on #System_ON when Status '1'

T_OFF

BOOL

Switch off #System_OFF when Status '1'

Mode_Select

BOOL

Mode preselection:
0 = MAN mode preselected
1 = AUTO mode preselected

Mode_Accept

BOOL

Accept or activate preselected mode

System_ON

BOOL

Operating status of system

Auto_Mode

BOOL

Operating status of AUTO mode

Manual_Mode

BOOL

Operating status of MAN mode

out Parameters

SITRAIN Training for


Automation and Industrial Solutions

Page 8

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Main_Station" (FB 2) Block

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

SITRAIN Training for

18.09.2009
PRO3_02E.9

Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

Enable

BOOL

Enable Main Station

Photo_Eye

BOOL

Light barrier of Main Station

Pushbutton

BOOL

Pushbutton of Main Station: Start production


sequence

Flash_Freq

BOOL

2-Hz frequency for optical status indication

Conv_Stopped

BOOL

Status of conveyor motor: 1 = conveyor stopped

Line_Ready

BOOL

Status of the 3 processing stations

Transp_Req

BOOL

Start part processing / request transport

Transp_Stop

BOOL

End of part processing / request stop

Indicator_Light

BOOL

Status indication:
Continuous light: new part can be loaded
Flashing:
start / end part processing

out Parameters

SITRAIN Training for


Automation and Industrial Solutions

Page 9

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Station" (FB 3) Block

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

SITRAIN Training for

18.09.2009
PRO3_02E.10

Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

Enable

BOOL

Enable processing station

Sta_activate

BOOL

Activate station for new part processing

Prox_Sw

BOOL

Stations proximity sensor

Pushbutton

BOOL

Pushbutton: Acknowledgement of part processing

Flash_Freq

BOOL

2-Hz frequency for station LED

Sta_ready

BOOL

Station is enabled and ready for part processing


(is in initial state)

Stop_busy

BOOL

Request conveyor stop / part is being processed


(only when station activated and proximity sensor
detects part)

Transp_Ready

BOOL

Request transport / part processing complete

Indicator_Light

BOOL

Status indication:
Continuous light: Station activated
Flashing:
Part is being processed

out Parameters

SITRAIN Training for


Automation and Industrial Solutions

Page 10

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Belt" (FB 4) Block

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

SITRAIN Training for

18.09.2009
PRO3_02E.11

Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

Manual_Mode

BOOL

MANUAL mode (signal from FB_Modes)

Auto_Mode

BOOL

AUTO mode (signal from FB_Modes)

Jog_Right

BOOL

Jog conveyor motor right

Jog_Left

BOOL

Jog conveyor motor left

Auto_Stop

BOOL

Request stop
(from stations or main station)

Auto_Start_Left

BOOL

Request transport left


(signal from stations or main station)

out Parameters

Auto_Start_Right BOOL

Request transport right of the stations


(signal from stations )

Conv_Belt_Right BOOL

Control conveyor motor right

Conv_Belt_Left

Control conveyor motor left

SITRAIN Training for


Automation and Industrial Solutions

BOOL

Page 11

ST-PRO3
FBs and the Multiple Instance Model

Interconnection of Blocks (Initial Situation)


"DB_Stat1"

"DB_Stat2"

"DB_Stat3"

"FB_Station"

"FB_Station"

"FB_Station"

Enable

Enable

Enable

Sta_activate

Sta_ready

Sta_activate

Sta_ready

Sta_activate

Sta_ready

Prox_Sw

Stop_Busy

Prox_Sw

Stop_Busy

Prox_Sw

Stop_Busy

Pushbutton

Pushbutton

Transp_Ready

Pushbutton

Indicator_Light

Transp_ready

Flash_Freq

Indicator_Light

Flash_Freq

Indicator_Light

Transp_Ready

Flash_Freq

"DB_Belt"

"DB_Main_Station"

"FB_Belt"

"FB_Main_Station"

Manual_Mode

Enable

Auto_Mode

Jog_Right

Photo_Eye

Jog_Left

Pushbutton

Auto_Stop

Flash_Freq

Conv_Belt
Auto_Start_Right
Right
Auto_Start_left

SIMATIC S7

Conv_Belt
Left

Line_Ready

Date:
File:

Siemens AG 2008. All rights reserved.

Conv_Stopped

18.09.2009
PRO3_02E.12

Transp_Req
Transp_Stop
Indicator_Light

SITRAIN Training for


Automation and Industrial Solutions

Initial Situation

The slide above shows the initial situation for processing raw materials:
On the simulator (PLCSIM), the AUTO mode is activated resulting in a 1-signal at
the #Enable inputs of the stations and at the #Auto_Mode input of the "FB_Belt".
As well, in this first program version, all processing stations are simultaneously
switched active through their input #Sta_Activate.
Through the parameter #Sta_Avail, the stations signal their availability (no
operation in progress and proximity switch empty) to the #Line_Ready parameter
of "FB_Main_Station". All stations indication lights signal their availability with a
steady light.

Production Process

When raw material is placed on the light barrier of the main station #Photo_Eye,
the flashing #Indicator_Light signals that processing may be started. After pressing
the start #Pushbutton, "FB_Main_Station" requests transport to the left using
#Transp_Req to #Move_Left_Auto of "FB_Belt".
As soon as the raw material reaches the first activated station - and since all
stations are already activated, this is Station 3 (#Prox_Sw) because of the physical
design of the conveyor model - Station 3 requests "FB_Belt" (#Auto_Stop) to stop
the conveyor motor using #Stop_Busy. Simultaneously, the station begins to
process the raw material, which is indicated by a flashing #Indicator_Light. When
the operator acknowledges processing of the raw material using #Pushbutton,
"FB_Station" signals the end of processing using #Transp_Ready and thus
requests "FB_Belt" (#Move_Left_Auto) to transport the finished part to the next
station. Since the #Transp_Ready of the station is connected to #Move_Left_Auto
of "FB_Belt", the raw material automatically reaches Station 2, which is already
activated, with the next transport.
The production process at station 2 and then 1 works the same as at station 3.
After the completed part has reached the main station, the main station requests
"FB_Belt" to stop the conveyor motor using #Transp_Stop. As well,
#Indicator_Light signals the operator with a flashing light that the part can be
removed from the belt. After the part has been removed, the production line is
once again in the initial situation and new raw material can be processed.

Documentation of the
Production Process

SITRAIN Training for


Automation and Industrial Solutions

Page 12

ST-PRO3
FBs and the Multiple Instance Model

Exercise 1: Creating a HW Station and Commissioning the Program

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

18.09.2009
PRO3_02E.13

SITRAIN Training for


Automation and Industrial Solutions

Task

First of all, you are to create your own exercise project with the name "My_Project".
Then, copy the S7 program "C2_E1_Start" from the "PRO3_Par" project that is
given into your own project on the CPU of your hardware station.
Become familiar with the previously described initial program for the production line
by checking the described functions.

What to Do

1. Create an exercise project with the name "My_Project". It is to contain a


hardware station that is equal to your exercise controller. In the CPU
properties, parameterize the MB10 as clock memory byte.
2. From the "PRO3_Par" project, copy the S7 program "C2_E1_Start" into your
own project "My_Project".
3. Using the HW Config tool, regenerate the system data of your hardware station
since these were lost or overwritten when you copied the "C2_E1_Start".
3. Check the described functionality of the conveyor model as production line.

Notes

At this stage, the "FB_Sequence" (FB30) block is not yet integrated into the entire
program and therefore does not fulfill any function as yet. It still has to be
commissioned by you in the following exercise.
In addition to the initial program for the production line, the project "PRO3_Sol" also
contains other S7 programs that contain the sample solutions for the following
configuration exercises.
You can use the sample solutions as help in solving the following configuration
exercises, among other things.

SITRAIN Training for


Automation and Industrial Solutions

Page 13

ST-PRO3
FBs and the Multiple Instance Model

Task Description: "FB_Sequence" (FB 30)


Conveyor
Control

Station 1

Station 2

Station 3

"FB_Belt"

FB_Station

FB_Station

FB_Station

L_Bay1

L_Bay2

L_Bay3

L_Bay-LB

T_Bay1

T_Bay2

T_Bay3

T_Bay-LB

Main_Station
"FB_Main_Station"

Left
Right

Possible work sequences:


"IW_BCD_Sequence", IW2
(thumbwheel on the simulator)

0
0
0
0
0
0

1
1
2
2
3
3

2
3
1
3
1
2

3
2
3
1
2
1

"F B _ S e q u e n c e"

to Station 2

to Station 3
to Station 1
Back to Main Station

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.14

SITRAIN Training for


Automation and Industrial Solutions

The Function
Up Until Now

The station sequence 3->2->1 for the processing of parts in the production
line is defined by the program.

Task

The station or work sequence in which a raw material is processed in the


production line is to be freely definable for each raw material using
"IW_BCD_Sequence" (BCD thumbwheel IW2 on the simulator). Each piece must
be processed exactly once at every station. This makes exactly 6 different
processing sequences possible (see slide).
The new FB to make the processing sequence flexible must activate the stations
individually according to a predefined sequence because up until now when
all stations were activated simultaneously at the beginning of part processing,
Station 3 was always the first processing station.
As well, "FB_Sequence" must now give "FB_Belt" the request for transport left or
right instead of the Station FBs. This is because the "FB_Station" does not
evaluate the predefined work sequence and thus cannot decide whether it is to
request a transport to the left or the right from "FB_Belt". The stations themselves
continue to request the conveyor to stop as soon as they are activated and a
production part reaches the appropriate proximity switch.

Re-usability

The newly created "FB_Sequence" (FB 30) function block is to be re-usable.


That is, only local (temp or stat) variables and parameters may be used inside the
FB no global addresses such as inputs, outputs or bit memories .

SITRAIN Training for


Automation and Industrial Solutions

Page 14

ST-PRO3
FBs and the Multiple Instance Model

Sequential Control of Part Processing using "FB_Sequence"


#Work_Sequence

Station
Station 11

#Work_Sequence_123 = true

Station
Station 22

#Second_Sta_Activate

Station
Station 33

Main
Main Station
Station

#First_Sta_Activate
#Go_To_Unload

#Third_Sta_Activate

#First_Sta_Activate

#Work_Sequence_132 = true

#Second_Sta_Activate
#Third_Sta_Activate
#Go_To_Unload
#Second_Sta_Activate

#Work_Sequence_213 = true

#First_Sta_Activate
#Go_To_Unload

#Third_Sta_Activate

#First_Sta_Activate

#Work_Sequence_231 = true

#Second_Sta_Activate
#Third_Sta_Activate

#First_Sta_Activate

#Second_Sta_Activate

#Work_Sequence_312 = true
#Work_Sequence_321 = true
#Work_Sequence
1-2-3
1-3-2
2-1-3
2-3-1
3-1-2
3-2-1

Actions

SIMATIC S7
Siemens AG 2008. All rights reserved.

#Go_To_Unload

#Third_Sta_Activate
#Third_Sta_Activate

Steps
#Go_To_Unload

#Second_Sta_Activate

#First_Sta_Activate
#Go_To_Unload

#Transp_Req_LFT
#First_Sta_Activate
#First / #Third_Sta_Activate
#First / #Second_Sta_Activate
#First / #Third_Sta_Activate
#First / #Second_Sta_Activate
#First / #Second / #Third_Sta_Activate
Date:
File:

18.09.2009
PRO3_02E.15

#Transp_Req_RT
#Second / #Third_Sta_Activate, #Go_To_Unload
#Second_Sta_Activate, #Go_To_Unload
#Third_Sta_Activate, #Go_To_Unload
#Second_Sta_Activate, #Go_To_Unload
#Third_sta_Activate, #Go_To_Unload
#Go_To_Unload
SITRAIN Training for
Automation and Industrial Solutions

Sequential
Control System

The slide shows that the production line part processing follows a strict step
sequence and that it can be divided into steps that are always carried out in the
same sequence.

Steps

In the first step (#First_Sta_Activate) the station is always activated - according to


the specified #Work_Sequence - where part processing begins (for example, this
would be Station 2 when #Work_Sequence 2 - 3 - 1 is specified) and transport to
the station is started.
Processing advances to the next step as soon as the station signals the end of
processing or requests a transport.
In the following step (#Second_Sta_Activate) the next station is always activated according to the specified #Work_Sequence - (for example, this would be Station 3
when #Work_Sequence 2 - 3 - 1 is specified) and transport to the station is started,
etc.

Actions

In every step, actions must be carried out such that a station must be activated and
a transport to the left or right has to be initiated.
The table (at the bottom of the slide) shows, for each #Work_Sequence, in which
step a transport to the left or the right has to be initiated.

SITRAIN Training for


Automation and Industrial Solutions

Page 15

ST-PRO3
FBs and the Multiple Instance Model

Sequence of Part Processing (According to IEC 61131-3)


Transitions

Steps

Actions
T5

S0
#Initial_Step
#Main_Station_Transp_Req

Initialization

T1
S1
#First_Sta_Activate

N
L

#Sta_X_Activate
#Transp_Req_L / R

T2

#Sta_X_Transp_Req

S2
#Second_Sta_Activate
#Sta_Y_Transp_Req

N
L

#Sta_Y_Activate
#Transp_Req_L / R

T3
S3
#Third_Sta_Activate

#Sta_Z_Transp_Req

#Sta_Z_Activate

#Transp_Req_L / R

#Transp_Req_R

T4
S4
#Go_To_Unload

#Main_Station_Transp_Stop

T5
S0

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.16

SITRAIN Training for


Automation and Industrial Solutions

Sequencers

A sequence of operations, or general steps, can be represented as a


sequencer, as shown in the slide, according to the IEC 61131-3 (IEC =
International Electrotechnical Commission). The structure of the sequencer
emulates the exact step-by-step execution, from top to bottom, of the actual
physical process.
The individual steps of the production process are displayed in the middle
column, in the right column the actions that have to be executed in each step of
the process, and in the left column the conditions (transitions) as to when
advancement takes place from one step to the next.

Steps

The production process is divided into a time-ordered sequence of steps. In the


sequencer program, a step variable of the BOOL data type is declared within the
program for every physical step. That way, every step variable represents a
phase of part processing. In "FB_Sequence" these step variables are named
#Initial_Step, #First_/#Second_/#Third_Sta_Activate, and #Go_To_Unload.
In our example of part processing, the step sequence is strictly linear so that at
any particular time only one step can be active.
In more complex production processes, parallel branches, jumps, and loops are
also possible so that several step variables can also be set simultaneously.

Initial Step

The initial step defines the starting point of the sequencer. With #Reset = 1, the
initial step is first of all set without querying for additional conditions.
When the initial step is activated, all other step variables are deactivated or
reset. That is, the sequencer is initialized (action of the initial step). The active
initial step thus supplies the information that no other step is active.

Note

You will find the sequencer program in the FBD language at the end of the
chapter.

SITRAIN Training for


Automation and Industrial Solutions

Page 16

ST-PRO3
FBs and the Multiple Instance Model

Static Variables of "FB_Sequence" (FB 30)


"FB_Sequence"
w#16#231

Work_Sequence

Checking the work sequence


Sorting the parameters / stat Var
Example: #Work_Sequence_231 = true

Work_Seq_Error

Main_Station_Transp_Req
Station_1_Transp_Req

First_Sta_Transp

Station_2_Transp_Req
Second_Sta_Transp
Station_3_Transp_Req
Third_Sta_Transp
Transp_Req_R
Transp_Req_L

Sequencer
First_Sta_Activate
Second_Sta_Activate
Third_Sta_Activate

Sta_1_Activate
Sta_2_Activate
Sta_3_Activate

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

18.09.2009
PRO3_02E.17

SITRAIN Training for


Automation and Industrial Solutions

Static
In addition to the IN and OUT parameters, the declaration of the following static
Variables (BOOL) variables makes sense:
#Work_Sequence_123
Operation sequence or station sequence 1-2-3
#Work_Sequence_132
Operation sequence or station sequence 1-3-2
#Work_Sequence_213
Operation sequence or station sequence 2-1-3
#Work_Sequence_231
Operation sequence or station sequence 2-3-1
#Work_Sequence_312
Operation sequence or station sequence 3-1-2
#Work_Sequence_321
Operation sequence or station sequence 3-2-1
#First_Sta_Transp
Transport request of first station
#Second_Sta_Transp
Transport request of second station
#Third_Sta_Transp
Transport request of third station
Assignment of
Static Variables

The internal static variables are used to "sort" FB input parameters and FB output
parameters. Depending on the operation sequence passed, the FB input
parameters #Sta_1/_2/_3_Transp_Req are assigned to the internal, static variables
#First_/Second_/Third_Sta_Transp (transitions), and the internal static variables
(steps) #First_/#Second_/#Third_Sta_Activate are assigned to the FB output
parameters #Sta_1/_2/_3_Activate (actions). Even the control of the FB outputs
#Transp_Req_L/R (actions) depends on the #Work_Sequence passed and must be
implemented with the appropriate logic.
The slide shows an example of how the "sorting" for the operation sequence 2 - 3 1 is to be made. The checking of the specified #Work_Sequence can be
programmed using comparison. Their results can be assigned to the static variables
#Work_Sequence_XYZ (BOOL) and be further gated.
In the program section "Sequencer", in which the already "sorted" static variables
are exclusively gated, only one single step series has to be programmed.

SITRAIN Training for


Automation and Industrial Solutions

Page 17

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Sequence" (FB 30) Block

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

SITRAIN Training for

18.09.2009
PRO3_02E.18

Automation and Industrial Solutions

Declaration

Name

Type

in Parameters

Enable

BOOL

Description

Work_Sequence

WORD Processing sequence at the 3 stations

Main_Sta_Transp_Req

BOOL

Transport request from Main Station

Main_Sta_Transp_Stop

BOOL

Request stop from Main Station

Sta_1_Transp_Req

BOOL

Transport request from Station 1

Sta_2_Transp_Req

BOOL

Transport request from Station 2

Sta_3_Transp_Req

BOOL

Transport request from Station 3

Enable block

Note
When a station requests transport using Station_x_Transp_Req, it is also a signal that it has
completed its part processing.

out Parameters

Work_Seq_Error

BOOL

Message 'invalid work sequence specified'

Process_active

BOOL

A part processing is active from Start by the


Main Station until Stop by the Main Station

Sta_1_activate

BOOL

Activate Station 1 for part processing

Sta_2_activate

BOOL

Activate Station 2 for part processing

Sta_3_activate

BOOL

Activate Station 3 for part processing

Transp_Req_R

BOOL

Request transport to the RIGHT

Transp_Req_L

BOOL

Request transport to the LEFT

SITRAIN Training for


Automation and Industrial Solutions

Page 18

ST-PRO3
FBs and the Multiple Instance Model

Exercise 2: Integrating the "FB_Sequence" (FB 30) Block

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.19

SITRAIN Training for


Automation and Industrial Solutions

Task

The "FB_Sequence" (FB30) block already exists and all you have to do is
integrate it in the complete program.

What to Do

1. Integrate the FB30 in the complete program. For this, declare temporary
variables in OB 1 to interconnect the FB 30 with the other blocks (see slide).
2. Give the Instance DB 30 the symbolic name "DB_Sequence".
3. Check the functioning of the newly integrated FB 30 by entering various
processing sequences on the BCD thumbwheel "IW_BCD-Sequence" (IW2)
on the simulator (see slide).

Test

Follow the control of the processing sequence by monitoring the program


sections of the "sequencer" within FB30 with the test function "Monitor Block".

SITRAIN Training for


Automation and Industrial Solutions

Page 19

ST-PRO3
FBs and the Multiple Instance Model

Object-Oriented Programming by Means of Multiple Instances


Example: Pressline

FB: "Pressline"

Press_1

Press_2

FB: #Press_1
FB: #Punch
FB: #Guard

Punch
Guard
FB: #Press_2
FB: #Punch
FB: #Guard

Transport
FB: #Transport

Machine Structure

SIMATIC S7

Logical division of the


program with the help of
FB instances

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.20

SITRAIN Training for


Automation and Industrial Solutions

Process Units

Process units are physical objects in the process, such as units of a production
line (transport belt, processing stations) or a complete machine or parts of a
machine (such as the complete press or the punch or the guard of a press).
Process units are used as logical identification criteria. They are, as a rule, of a
hierarchical design. In this way, process units can contain sub-units (for
example, the unit "Press" contains the units "Punch" and "Guard") and may be
configured from smaller sub-units (aggregation).

Object-oriented
Programming Style

You can implement an object-oriented programming style with the help of


function blocks. The function of a process unit or process sub-unit program is
handled within an FB instance. The division of the user program into units is
achieved by declaring lower-level FB instances within a higher-level FB.
In this way, the same division into process units is achieved in the user program
as in the existing system or machine. This is the concept of object-oriented
programming using aggregation.

Re-usability of
Software

This hierarchical concept offers a high measure of re-usability of one-time


generated software and thus offers a great savings potential in the creation,
modification and upkeep of user programs:
Whenever a manufacturer creates a process sub-unit (such as valve or
motor), he also delivers an FB for controlling this process sub-unit.
Whenever such a physical process unit is built into the next larger unit, an
FB instance of the unit is also declared in the FB of the higher-level unit.
FBs are the basic components of a control program. In the planning stages of a
program, they have the same task as the integrated circuits (ICs) in printed
circuit board manufacturing. The structure of user programs consists of prefabricated FBs, which must simply be interconnected.

SITRAIN Training for


Automation and Industrial Solutions

Page 20

ST-PRO3
FBs and the Multiple Instance Model

Implementing the "Press Line" in STEP 7


FB4:"Punch"
FB1:"Press"

Data of FB10

...
FB10:"Pressline"

OB1

stat Punch
stat Guard
...

...
stat Press_1
FB1
stat Press_2
FB1
stat Transport FB2
...

CALL #Punch
.
CALL #Guard

CALL #Press_1

...

FB4
FB5

Data for Press_1


FB5:"Guard"

.
CALL #Press_2
.
CALL #Transport

stat Punch
stat Guard
...

Press_1. Punch

Press_1. Guard

FB1: "Press"
CALL FB10, DB10

DB10

FB4
FB5

CALL #Punch
.
CALL #Guard

Data for Press_2


FB4:"Punch"

Press_2. Punch

Press_2. Guard
FB5:"Guard"
Data for Transport

FB2: "Transport"

...

Instance-DB of FB10

...

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.21

SITRAIN Training for


Automation and Industrial Solutions

Multiple Instance
Model

When a multiple instance model is used, the instance DB contains the data for
several function blocks of a call hierarchy. The instances of the called function
blocks are declared using symbolic identifiers in the static variable section of
the declaration section of the calling FB.
The FB instance for the highest-level process unit (in this example, FB10
"Pressline") must be called absolutely or symbolically, along with the
specification of its own instance DB (DB10 here).

Declarations

In the static variable section of the declaration part of FB10 ("Pressline"), two
instances (variables) of the data type FB1 ("Press") with the names #Press_1
and #Press_2 are declared, as well as an instance of the data type FB2
("Transport") with the name #Transport.
In the declaration part of FB1 both an instance of FB4 ("Punch") with the name
#Punch and an instance of FB5 ("Guard") with the name #Guard are declared.
In the instruction section of FB1 ("Press"), the respective FB instances are then
called using the symbolic names #Punch and #Guard that were declared in the
declaration section.

Note

The declaration of an instance in the declaration part of a function block works


only if the FB being used in the declaration already exists.
When designing such a call hierarchy, you must first create those FBs that are
to be called last in the chain.

Multiple Instance DB The multiple instance DB has the same structure as the declaration parts of the
function blocks concerned. If an instance is called in the instruction section, then
it automatically accesses the data in the corresponding section of the instance
DB (see DB10 above).

SITRAIN Training for


Automation and Industrial Solutions

Page 21

ST-PRO3
FBs and the Multiple Instance Model

Task Description: Multiple Instance Model

Conveyor
Control

Station 1

"FB_Belt"

"FB_Station"

Station 2

Station 3

"FB_Station"

"FB_Station"

Main
(Load/Unload)
Station
"FB_Main_Station"

Multi - Instances
Left
Right
#TON_Delay
_Proc
TON

#TON_Delay
_Proc

#TON_Delay
_Proc

TON

TON

L_Bay-LB
T_Bay-LB

Work sequence

"FB_Sequence"

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.22

SITRAIN Training for


Automation and Industrial Solutions

The Function
Up Until Now

When a piece reaches an activated station, "FB_Station" (FB 3) initiates


"FB_Belt" (FB 4) to stop the conveyor motor and begin processing the part.
Processing is indicated by a flashing station LED and is acknowledged or ended
by the operator by pressing the stations pushbutton.
Then "FB_Station" signals the end of processing using the parameter
#Transp_Ready and simultaneously signals a request for transport to
"FB_Sequence".

Task

The three processing stations are to process the part automatically so that a
processing acknowledgement by the operator is no longer necessary.
A #Proc_Time (format Time) is passed to "FB_Station" for this. After this
processing time has run out, "FB_Station" is to signal the end of processing
and/or request transport using the above mentioned parameters.
The "FB_Station" (FB 3) function block that is to be changed is to continue to be
re-usable. That is, the processing time must be implemented inside the FB using
an instance or a static variable of the system function block type (SFB 4,
symbolic name "TON", on-delay timer).

Note

If instances of existing FBs or SFBS are called in a function block, then the
instance data required for these are found in the instance data block (multiple
instance) of the calling FB. No additional instance data blocks have to be
created for the called instances (FBs or SFBs). That is, the call is made without
specifying an instance DB.

SITRAIN Training for


Automation and Industrial Solutions

Page 22

ST-PRO3
FBs and the Multiple Instance Model

Exercise 3: Programming the Processing Time with SFB 4 "TON"

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

What to Do

18.09.2009
PRO3_02E.23

SITRAIN Training for


Automation and Industrial Solutions

When you do the exercise, please proceed as follows:


1. In FB 3 replace the original input parameter #Pushbutton of the BOOL type
with the new input parameter #Proc_Time of the TIME type.
2. Declare the static variable #TON_Delay_Proc of the SFB 4 type ("TON", ondelay timer) and the temporary variable #TON_Proc_Done of the BOOL
type. These will be used later when querying whether the specified
#Proc_Time has run out.
3. Program the call of #TON_Delay_Proc and assign the binary result of this
time function to the variable #TON_Proc_Done..
4. Gate the temporary variable #TON_Proc_Done with those locations in the
program where the input parameter #Pushbutton was queried up until now.
5. Due to the changes made in "FB_Station" (FB 3), the calls of the FB in OB1
must be updated and the associated instance data blocks must be
regenerated as follows:
Open OB 1 and, one after the other, select the FB 3 calls Edit Call
Update...
6. Check how of the modified "FB_Station" (FB 3) functions by passing, in
OB 1, different time values in the form of a constant (e.g. T#2s) for the
respective calls for the individual stations.

SITRAIN Training for


Automation and Industrial Solutions

Page 23

ST-PRO3
FBs and the Multiple Instance Model

Task Description: Multiple Instance "FB_Line" (FB 31)

"FB_Belt"

Main
(Load/Unload)
Station

Production Line

Conveyor
Control

"F B _ L I n e"
#Station_1

#Station_2

#Station_3

#TON_Delay
_Proc.

#TON_Delay
_Proc.

#TON_Delay
_Proc.

"FB_Main_Station"

Left
Right

TON

TON

TON

L_Bay-LB
T_Bay-LB

Work sequence

"F B _ S e q u e n c e"

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.24

SITRAIN Training for


Automation and Industrial Solutions

Task

Since the Stations 1 to 3 physically represent one production line entity in which
parts can be processed in any operation sequence, the functionality of the
production line is now to be summarized within the program in one function
block (FB 31).
Just as in the last exercise where an instance or a static variable of the type
SFB 4 ("TON") was declared in "FB_Station" (FB 3), you must now create an
"FB_Line" (FB 31) and in it declare the instances or static variables #Station_1,
#Station_2, #Station_3 of the type FB 3 and the static variable #Sequence of the
type FB 30.
In OB1 it is then no longer necessary to call the FB 3 once for every station and
FB 30 for controlling the sequence. Instead, "FB_Line" (FB 31) only has to be
called once. It controls the functioning of the production line. Accordingly, the
instance data blocks of the stations and the control of the sequence (DB 30 - DB
33) are also no longer required. Instead, only one multiple instance DB will be
used.
The resulting "FB_Line" (FB 31) thus represents the functionality and the
(multiple) instance DB represents the states of the production line (without the
feed station and without the conveyor control).

Re-usability

The new "FB_Line" (FB 31) function block is to be re-usable. That is, no
absolute addresses may be directly used inside the FB - not even to supply
blocks called internally with actual parameters (SFC, SFB, FC, FB).
This makes it necessary to declare input parameters and output parameters in
FB 31 for all the input and output parameters of the three stations as well as the
control of the sequence (see the prevailing calls in OB 1: three calls of FB 3 for
the stations 1 to 3 and one call of FB 30 for the control of the sequence). These
input and output parameters of the higher-level FB 31 then have to be internally
interconnected with the input and output parameters of the called instances
(FBs).

SITRAIN Training for


Automation and Industrial Solutions

Page 24

ST-PRO3
FBs and the Multiple Instance Model

Exercise 4: Programming the "FB_Line" (FB 31)

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

What to Do

18.09.2009
PRO3_02E.25

SITRAIN Training for


Automation and Industrial Solutions

When you do the exercise, please proceed as follows:


1. In FB 31, declare input and output parameters (see slide) for all input and
output information of the three station instances (FB 3 calls) as well as the
sequence instance (FB 30).
2. In FB 31, declare temporary and static variables so that you can connect the
called instances with one another (see existing interconnections in OB 1).
Note:
You can use temporary variables to pass (interconnect) information or
signals that run in the program processing direction (in other words, from one
instance to another, later called instance, from "top to bottom" as it were). If
information needs to be passed "from bottom to top" within an FB, static
variables must be used because the cyclic program processing causes
temporary variables to get overwritten between program scans.
3. In OB 1, delete the three calls of FB 3 (Station 1 to 3) and that of FB 30
("FB_Sequence"). In their place, program the call of "FB_Line" (FB 31). Use
DB 123 as the (multiple) instance DB.
4. In OB 1, interconnect "FB_Line" (FB 31) with the rest of the blocks in the
program. Use the existing already declared variables to accomplish this.
5. Delete the current instance DBs of the stations and that of the sequence
control (DB 30 to DB 33) in your project as well as in the CPU. These DBs
are no longer required since the associated data is now stored in the multiple
instance DB 123.
6. Download all blocks to the CPU and test the program for proper operation.

SITRAIN Training for


Automation and Industrial Solutions

Page 25

ST-PRO3
FBs and the Multiple Instance Model

If You Want to Know More

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

Note

18.09.2009
PRO3_02E.26

SITRAIN Training for


Automation and Industrial Solutions

The following pages contain either further information or are for reference to
complete a topic.
For more indepth study we offer advanced courses and self-learning mediums.

SITRAIN Training for


Automation and Industrial Solutions

Page 26

ST-PRO3
FBs and the Multiple Instance Model

Sequence of Part Processing (According to IEC 61131-3)


Transitions

Steps

Actions
T5

S0
#Initial_Step
#Main_Station_Transp_Req

Initialization

T1
S1
#First_Sta_Activate

N
L

#Sta_X_Activate
#Transp_Req_L / R

T2

#Sta_X_Transp_Req

S2
#Second_Sta_Activate
#Sta_Y_Transp_Req

N
L

#Sta_Y_Activate
#Transp_Req_L / R

T3
S3
#Third_Sta_Activate

#Sta_Z_Transp_Req

#Sta_Z_Activate

#Transp_Req_L / R

#Transp_Req_R

T4
S4
#Go_To_Unload

#Main_Station_Transp_Stop

T5
S0

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.27

SITRAIN Training for


Automation and Industrial Solutions

Sequencers

A sequence of operations, or general steps, can be represented as a


sequencer, as shown in the slide, according to the IEC 61131-3 (IEC =
International Electrotechnical Commission). The structure of the sequencer
emulates the exact step-by-step execution, from top to bottom, of the actual
physical process.
The individual steps of the production process are displayed in the middle
column, in the right column the actions that have to be executed in each step of
the process, and in the left column the conditions (transitions) as to when
advancement takes place from one step to the next.

Steps

The production process is divided into a time-ordered sequence of steps. In the


sequencer program, a step variable of the BOOL data type is declared within the
program for every physical step. That way, every step variable represents a
phase of part processing. In "FB_Sequence" these step variables are named
#Initial_Step, #First_/#Second_/#Third_Sta_Activate, and #Go_To_Unload.
In our example of part processing, the step sequence is strictly linear so that at
any particular time only one step can be active.
In more complex production processes, parallel branches, jumps, and loops are
also possible so that several step variables can also be set simultaneously.

Initial Step

The initial step defines the starting point of the sequencer. With #Reset = 1, the
initial step is first of all set without querying for additional conditions.
When the initial step is activated, all other step variables are deactivated or
reset. That is, the sequencer is initialized (action of the initial step). The active
initial step thus supplies the information that no other step is active.

SITRAIN Training for


Automation and Industrial Solutions

Page 27

ST-PRO3
FBs and the Multiple Instance Model

Sequencer: According to IEC61131-3


S1
#First_Sta_Activate
T2

#First_Sta_Transp_Req

S2
#Second_Sta_Activate

#Sta_Y_Activate
#Transp_Req_L / R

Sequencer: Conversion to STEP 7 Ladder Logic


Sequencer:
#First_Sta
_Activate

Command Output (Actions):


#First_Sta
_Transp_Req

#First_Sta
_Activate

#Work_
Sequence_XYZ

#Second_Sta
_Activate

#First_Sta
_Activate

#Second_Sta
_Activate

#Transp
_Req_L/R
(other conditions)

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.28

SITRAIN Training for


Automation and Industrial Solutions

Transitions

Transitions are step-enabling conditions in which the transition from one step to
the next takes place. Step-enabling conditions can be process signals (for
example, signals from sensors, limit switches etc.) and/or they can result from
logical relationships.
In our example, the step-enabling conditions result from the signals of other FBs
that are passed to the "FB_Sequence" using the IN parameter
(#Stations_Ready, #Main_Sta_Transp_Req, #Main_Sta_Transp_Stop, #Stat_1/
2 / 3_Transp_Req). In the slide, the step-enabling conditions
#First/Second/Third_Sta_Transp_Req are given instead of the
Stat_1/_2/_3_Transp_Req since the sequence of the step-enabling conditions
depends on the operation sequence specified.

Sequencer

In the Sequencer program section, the step variables are managed and the user
determines the sequence of the production process. As a rule, a separate
network is created for every step variable.
A step variable is set when the previous step is active AND the transition
associated with this step is fulfilled. At the same time, the previous step is reset
under the same conditions. The querying of the two conditions Previous Step
AND Transition prevents the unwanted activation of a step at the wrong time.
The Sequencer program section is responsible exclusively for the setting and
resetting of step variables, not for the control of process actuators or the
execution of actions.

Command Output

In the Command Output program section, the user determines what is to happen
in which step. One or more actions are assigned to each step. The actions can
be given the following properties:
D = delayed (time-delayed after activating the step)
N = not stored (the action is only executed as long as the step remains active)
L = limited (limited to a specific time period even if step is active longer)

SITRAIN Training for


Automation and Industrial Solutions

Page 28

ST-PRO3
FBs and the Multiple Instance Model

Sequencer: Conversion to STEP 7 (Ladder)


Initial Step :

First Step :

#Main_Sta_Transp_Stop

#Initial_Step

#Initial_Step

#Main_Sta_
Transp_Req

#Initial_Step
R

#First_Sta
_Activate

#First_Sta
_Activate

#Second_Sta
_Activate
R

Last Step:

#Third_Sta
_Activate

#Third_Sta
_Activate

#Go_To_Unload

#Third_Sta
_Transp

#Third_Sta
_Activate
R

#Go_To_Unload
S

SIMATIC S7

Date:
File:

Siemens AG 2008. All rights reserved.

18.09.2009
PRO3_02E.29

SITRAIN Training for


Automation and Industrial Solutions

Significance of the
Initial Step

With the initial step, the starting point of the sequencer is defined in the program
- in other words, the "step" before Step 1" (here #First_Sta_Activate)
In our example, the parameter #Main_Sta_Transp_Stop corresponds to the
transition to the initial step. This parameter is passed the state 1, when a
completed part has been returned to the main station (signal from
"FB_Main_Station").
When the initial step is set, the sequencer is initialized in the program. That is all
other step bits are reset. The active initial step thus supplies the information that
no other step is active, which is an essential condition for the activation of the
first "real" step. The query #initial_step AND #Main_Sta_Transp_Req thus
supplies the exact condition for setting the first "real" step #First_Sta_Activate.

Last Step

The last step (#Go_To_Unload) is set when the next to the last step
(#Third_Sta_Activate) is active AND the transition (#Third_Sta_Transp) is
fulfilled.
The last step is reset when the initial step is set with the appropriate transition
(#Main_Sta_Transp_Stop) (see slide, Initial Step)

SITRAIN Training for


Automation and Industrial Solutions

Page 29

ST-PRO3
FBs and the Multiple Instance Model

Static Variables of "FB_Sequence" (FB 30)


"FB_Sequence"
w#16#231

Work_Sequence

Checking the work sequence


Sorting the parameters / stat Var
Example: #Work_Sequence_231 = true

Work_Seq_Error

Main_Station_Transp_Req
Station_1_Transp_Req

First_Sta_Transp

Station_2_Transp_Req
Second_Sta_Transp
Station_3_Transp_Req
Third_Sta_Transp
Transp_Req_R
Transp_Req_L

Sequencer
First_Sta_Activate
Second_Sta_Activate
Third_Sta_Activate

Sta_1_Activate
Sta_2_Activate
Sta_3_Activate

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

18.09.2009
PRO3_02E.30

SITRAIN Training for


Automation and Industrial Solutions

Static
In addition to the IN and OUT parameters, the declaration of the following static
Variables (BOOL) variables makes sense:
#Work_Sequence_123
Operation sequence or station sequence 1-2-3
#Work_Sequence_132
Operation sequence or station sequence 1-3-2
#Work_Sequence_213
Operation sequence or station sequence 2-1-3
#Work_Sequence_231
Operation sequence or station sequence 2-3-1
#Work_Sequence_312
Operation sequence or station sequence 3-1-2
#Work_Sequence_321
Operation sequence or station sequence 3-2-1
#First_Sta_Transp
Transport request of first station
#Second_Sta_Transp
Transport request of second station
#Third_Sta_Transp
Transport request of third station
Assignment of
Static Variables

The internal static variables are used to "sort" FB input parameters and FB output
parameters. Depending on the operation sequence passed, the FB input
parameters #Sta_1/_2/_3_Transp_Req are assigned to the internal, static variables
#First_/Second_/Third_Sta_Transp (transitions), and the internal static variables
(steps) #First_/#Second_/#Third_Sta_Activate are assigned to the FB output
parameters #Sta_1/_2/_3_Activate (actions). Even the control of the FB outputs
#Transp_Req_L/R (actions) depends on the #Work_Sequence passed and must be
implemented with the appropriate logic.
The slide shows an example of how the "sorting" for the operation sequence 2 - 3 1 is to be made. The checking of the specified #Work_Sequence can be
programmed using comparison. Their results can be assigned to the static variables
#Work_Sequence_XYZ (BOOL) and be further gated.
In the program section "Sequencer", in which the already "sorted" static variables
are exclusively gated, only one single step series has to be programmed.

SITRAIN Training for


Automation and Industrial Solutions

Page 30

ST-PRO3
FBs and the Multiple Instance Model

Parameter Description: "FB_Sequence" (FB 30) Block

SIMATIC S7
Siemens AG 2008. All rights reserved.

Date:
File:

SITRAIN Training for

18.09.2009
PRO3_02E.31

Automation and Industrial Solutions

Declaration

Name

Type

in Parameters

Enable

BOOL

Description

Work_Sequence

WORD Processing sequence at the 3 stations

Stations_ready

BOOL

Main_Sta_Transp_Req

BOOL

Transport request from Main Station

Main_Sta_Transp_Stop

BOOL

Request stop from Main Station

Sta_1_Transp_Req

BOOL

Transport request from Station 1

Sta_2_Transp_Req

BOOL

Transport request from Station 2

Sta_3_Transp_Req

BOOL

Transport request from Station 3

Enable block
Status of the 3 processing stations

Note
When a station requests transport using Station_x_Transp_Req, it is also a signal that it has
completed its part processing.

out Parameters

Work_Seq_Error

BOOL

Message 'invalid work sequence specified'

Process_active

BOOL

A part processing is active from Start by the


Main Station until Stop by the Main Station

Sta_1_activate

BOOL

Activate Station 1 for part processing

Sta_2_activate

BOOL

Activate Station 2 for part processing

Sta_3_activate

BOOL

Activate Station 3 for part processing

Transp_Req_R

BOOL

Request transport to the RIGHT

Transp_Req_L

BOOL

Request transport to the LEFT

SITRAIN Training for


Automation and Industrial Solutions

Page 31

ST-PRO3
FBs and the Multiple Instance Model

Structogram for "FB_Sequence" (FB30)

SITRAIN Training for


Automation and Industrial Solutions

Page 32

ST-PRO3
FBs and the Multiple Instance Model

You might also like