Sie sind auf Seite 1von 32
Block Calls and the Mu ltiple Instance Model Date: 18.09.2009 File: PRO3_02E.1 SIMATIC S7 Siemens

Block Calls and the Multiple Instance Model

Date: 18.09.2009 File: PRO3_02E.1
Date:
18.09.2009
File:
PRO3_02E.1

SIMATIC S7

SIMATIC S7

Siemens AG 2008. All rights reserved.

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 OB 1 FB10 Modularization of the Entire Task: FB1 Controller Controller
Blocks for Structured Programming OB 1 FB10 Modularization of the Entire Task: FB1 Controller Controller
Blocks for Structured Programming
OB 1
FB10
Modularization of the
Entire Task:
FB1
Controller
Controller
Motor Motor 1 1
.
.
.
Partial tasks are solved in
their own blocks
Parameter assignment
enables flexible usage
FB2
FC 5
SFC
Limit
Copying
Valves Valves
value
Example: Drilling cycle
with parameter-
assignable depth
DB 2
OB 1
FB 1
Address
Decl. Name
Type
0.0
in
Start
BOOL
Re-usability of Blocks:
.
0.1
in
Stop
BOOL
2.0
out
Motor_on
BOOL
.
Blocks can be called as
often as is required
Restrictions:
4.0
out
Speed
INT
6.0
stat
Speed_old
INT
CALL
FB1, DB2
0.0
temp Calc_1
INT
Start
:=I 0.0
.
Stop
:=I 0.1
.
no access to global
addresses
Motor_on :=Q12.0
.
Speed
:=QW14
A
#Start
.
AN
#Stop
=
#Motor_on
communication only via
the parameter list
.
.

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.2

SITRAIN Training for Automation and Industrial Solutions

Modularization

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

of Tasks

on the fundamental aspects of a program in every abstraction level and ignore

Structured

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.

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

• Blocks for solving partial tasks implement their own data management with

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:

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 - user interface Organization - graduated

Block Overview in STEP 7

Type of Block Properties - user interface Organization - graduated priorities (0 to 27) block
Type of Block
Properties
- user interface
Organization
- graduated priorities (0 to 27)
block (OB)
- specific start information in the local data stack
- parameter-assignable (parameters can be assigned in a call)
Function block (FB)
- with (recall) memory (static variables)
- parameter-assignable (parameters must be assigned in the call)
Function (FC)
- basically without memory (only temporary variables)
- structured local data storage (Instance DB)
Data block (DB)
- structured global data storage (valid throughout the entire program)
System function
block (SFB)
- FB (with memory) stored in the CPU‘s operating system and
callable by the user
System
function (SFC)
- function (without memory) stored in the CPU‘s operating system
and callable by the user
System data
- data block for configuration data and parameters
block (SDB)

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.3

SITRAIN Training for Automation and Industrial Solutions

Blocks in STEP 7

Downloading Blocks Later On

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 CPU‘s 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.

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 FB call with Instance DB OB, FB or FC Call

Instance Formation of Function Blocks

FB call with Instance DB

OB, FB or FC

Call

FBx, DBy

DBy FBx Algorithms Status for control data logic + of conveyor FB Instance FBx DBy
DBy
FBx
Algorithms
Status
for control
data
logic
+ of
conveyor
FB Instance
FBx
DBy

Declaration within FBs (Multi-instances)

CALL FBx, DBy

stat

Guard

FBa

 

stat

Punch

FBc

Status

 

data

CALL #Guard

 

of guard

CALL #Punch

Status

 

data

 

of punch

data CALL #Guard   of guard CALL #Punch Status   data   of punch Conveyor Guard

Conveyor

data CALL #Guard   of guard CALL #Punch Status   data   of punch Conveyor Guard

Guard

data CALL #Guard   of guard CALL #Punch Status   data   of punch Conveyor Guard

Punch

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 Mult iple Instance Model DB10 FB4 FB10 Control Data Such as OB1

Structure of the Multiple Instance Model

DB10 FB4 FB10 Control Data Such as OB1 stat Guard FB4 logic for guard stat
DB10
FB4
FB10
Control
Data
Such as OB1
stat Guard
FB4
logic
for guard
stat Punch
FB5
for a
stat Conv.
FB2
guard
.
FB5
CALL FB10,DB10
CALL Guard
Control
Data
.
logic
for punch
.
for a
CALL Punch
punch
.
CALL Conv.
Data
FB2
for
Control
conveyor
logic
The figure shows a possible technological
structure when only a press and a
conveyor exist.
for a
conveyor
Instance DB of FB10

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.5

SITRAIN Training for Automation and Industrial Solutions

Multiple Instance

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

Model

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: Only one DB

Characteristics of the Multiple Instance Model

Benefits of the multiple instance model:

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:

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:

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:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.6

SITRAIN Training for Automation and Industrial Solutions

Benefits of the Multiple Instance Model

Prerequisites for Multiple Instances

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.

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 Q 4.0 T_System_ON I 0.1 Q 4.1
Basic Program of the Production Line I 0.0 Q 4.0 T_System_ON I 0.1 Q 4.1
Basic Program of the Production Line
I 0.0
Q
4.0
T_System_ON
I 0.1
Q
4.1
T_System_OFF
L_SYSTEM
L_MAN
Q
4.2
I 0.2
T_Jog_RIGHT
I 0.3
L_AUTO
Q
4.3
T_Jog_LEFT
I 0.4
S_M/A_ModeSelect
I 0.5
T_M/A_Accept
Main
(Load/Unload)
I 0.6
Station
Station 1
Station 2
Station 3
I 0.7
"BAY1"
"BAY2"
"BAY3"
"LB"
"L_Bay3"
Raw
"T_Bay3"
"T_Bay-LB"
Material
"L_Bay2"
"T_Bay2"
"L_Bay-LB"
"L_Bay1"
"T_Bay1"

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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

AUTOMATIC 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.

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 station‘s 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 station‘s 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: 18.09.2009 Siemens AG 2008. All rights

Parameter Description: "FB_Modes" (FB 1) Block

Parameter Description: "FB_Modes" (FB 1) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.8

SITRAIN Training for 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

out Parameters

System_ON BOOL

Operating status of system

Auto_Mode

BOOL

Operating status of AUTO mode

Manual_Mode BOOL

Operating status of MAN mode

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: 18.09.2009 Siemens AG 2008. All

Parameter Description: "FB_Main_Station" (FB 2) Block

Parameter Description: "FB_Main_Station" (FB 2) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.9

SITRAIN Training for 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

out Parameters

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

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: 18.09.2009 Siemens AG 2008. All rights

Parameter Description: "FB_Station" (FB 3) Block

Parameter Description: "FB_Station" (FB 3) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.10

SITRAIN Training for 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

Station’s proximity sensor

Pushbutton

BOOL

Pushbutton: Acknowledgement of part processing

Flash_Freq

BOOL

2-Hz frequency for station LED

out Parameters

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

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: 18.09.2009 Siemens AG 2008. All rights

Parameter Description: "FB_Belt" (FB 4) Block

Parameter Description: "FB_Belt" (FB 4) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.11

SITRAIN Training for 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)

Auto_Start_Right BOOL

Request transport right of the stations (signal from stations )

out Parameters

Conv_Belt_Right BOOL

Control conveyor motor right

Conv_Belt_Left

BOOL

Control conveyor motor left

SITRAIN Training for Automation and Industrial Solutions

Page 11

ST-PRO3

FBs and the Multiple Instance Model

Interconnection of Blo cks (Initial Situation) "DB_Stat1" "DB_Stat2" "DB_Stat3"

Interconnection of Blocks (Initial Situation)

"DB_Stat1" "DB_Stat2" "DB_Stat3" "FB_Station" "FB_Station"
"DB_Stat1"
"DB_Stat2"
"DB_Stat3"
"FB_Station"
"FB_Station"
"FB_Station"
1
Enable
Indicator_Light
1
1
Enable
Indicator_Light
1
1
Enable
Indicator_Light
1
1
Sta_activate
Sta_ready
1
Sta_activate
Sta_ready
1
Sta_activate
Sta_ready
0
Prox_Sw
Stop_Busy
0
Prox_Sw
Stop_Busy
0
Prox_Sw
Stop_Busy
0
Pushbutton
Transp_ready
0
Pushbutton
Transp_Ready
0
Pushbutton
Transp_Ready
Flash_Freq
Flash_Freq
Flash_Freq
"DB_Belt"
"DB_Main_Station"
"FB_Belt"
"FB_Main_Station"
Manual_Mode
1
Auto_Mode
Enable
Jog_Right
1
Photo_Eye
Jog_Left
Pushbutton
Auto_Stop
Flash_Freq
Transp_Req
Conv_Belt
Auto_Start_Right
1
Conv_Stopped
Transp_Stop
Right
Conv_Belt
Indicator_Light
Auto_Start_left
Line_Ready
1
Left
SIMATIC S7
Date:
18.09.2009
SITRAIN Training for
Automation and Industrial Solutions
File:
PRO3_02E.12
Siemens AG 2008. All rights reserved.

Initial Situation

Production Process

All rights reserved. Initial Situation Production Process Documentation of the Production Process The slide above

Documentation of the Production Process

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.

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.

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 Date: 18.09.2009 Siemens

Exercise 1: Creating a HW Station and Commissioning the Program

Exercise 1: Creating a HW Station and Commissioning the Program

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 Main_Station Station 1 Station 2 Station 3
Task Description: "FB_Sequence" (FB 30)
Conveyor
Control
Main_Station
Station 1
Station 2
Station 3
"FB_Belt"
FB_Station
FB_Station
FB_Station
"FB_Main_Station"
Left
Right
L_Bay-LB
L_Bay1
L_Bay2
L_Bay3
T_Bay1
T_Bay2
T_Bay3
T_Bay-LB
Possible work sequences:
"F B _ S e q u e n c e"
"IW_BCD_Sequence", IW2
(thumbwheel on the simulator)
to Station 2
0
1
2
3
to Station 3
to Station 1
0
1
3
2
Back to Main Station
0
2
1
3
0
2
3
1
0
3
1
2
0
3
2
1

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 Main Main Station Station

Sequential Control of Part Processing using "FB_Sequence"

#Work_Sequence

Part Processing using "FB_Sequence" #Work_Sequence Main Main Station Station   #First_Sta_Activate
Part Processing using "FB_Sequence" #Work_Sequence Main Main Station Station   #First_Sta_Activate
Part Processing using "FB_Sequence" #Work_Sequence Main Main Station Station   #First_Sta_Activate

Main Main Station Station

 

#First_Sta_Activate

#Second_Sta_Activate

#Third_Sta_Activate

#Go_To_Unload

#Work_Sequence_123 = true

#First_Sta_Activate #Second_Sta_Activate #Third_Sta_Activate #Go_To_Unload #Second_Sta_Activate #First_Sta_Activate
#First_Sta_Activate
#Second_Sta_Activate
#Third_Sta_Activate
#Go_To_Unload
#Second_Sta_Activate
#First_Sta_Activate
#Third_Sta_Activate
#Go_To_Unload

#Work_Sequence_132 = true

#Work_Sequence_213 = true

#First_Sta_Activate #Second_Sta_Activate Steps #Work_Sequence_231 = true #Third_Sta_Activate #Go_To_Unload
#First_Sta_Activate
#Second_Sta_Activate
Steps
#Work_Sequence_231 = true
#Third_Sta_Activate
#Go_To_Unload
#Second_Sta_Activate
#First_Sta_Activate
#Work_Sequence_312 = true
#Third_Sta_Activate
#Go_To_Unload

#Work_Sequence_321 = true

#Third_Sta_Activate

#Second_Sta_Activate

#First_Sta_Activate

 

#Go_To_Unload

Actions

#Work_Sequence

#Transp_Req_LFT

#Transp_Req_RT

1

- 2 - 3

#First_Sta_Activate

#Second / #Third_Sta_Activate, #Go_To_Unload

1

- 3 - 2

#First / #Third_Sta_Activate

#Second_Sta_Activate, #Go_To_Unload

2

-

1 - 3

#First / #Second_Sta_Activate

#Third_Sta_Activate, #Go_To_Unload

2

- 3 - 1

#First / #Third_Sta_Activate

#Second_Sta_Activate, #Go_To_Unload

3

-

1 - 2

#First / #Second_Sta_Activate

#Third_sta_Activate, #Go_To_Unload

3

- 2 - 1

#First / #Second / #Third_Sta_Activate

#Go_To_Unload

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.15

SITRAIN Training for Automation and Industrial Solutions

Sequential

The slide shows that the production line part processing follows a strict step

Control System

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 Processi ng (According to IEC 61131-3)   Transitions Steps     Actions

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

 

Transitions

Steps

   

Actions

 
   

T

5

 
 
 

S

0

 

Initialization

 

#Initial_Step

#Main_Station_Transp_Req

     
   

T

1

 

S

1

N

#Sta_X_Activate

#First_Sta_Activate

L

 
 

#Sta_X_Transp_Req

 

T

2

#Transp_Req_L / R

 

S

2

N

#Sta_Y_Activate

   

#Second_Sta_Activate

L

#Transp_Req_L / R

#Sta_Y_Transp_Req

 

T

3

 

S

3

N

#Sta_Z_Activate

#Third_Sta_Activate

L

#Transp_Req_L / R

 

#Sta_Z_Transp_Req

   
   

T

4

 

S

4

L

   

#Go_To_Unload

#Transp_Req_R

#Main_Station_Transp_Stop

#Main_Station_Transp_Stop
#Main_Station_Transp_Stop
#Main_Station_Transp_Stop
#Main_Station_Transp_Stop

T 5

S 0

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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

Static Variables of "FB_Sequence" (FB 30)

"FB_Sequence" w#16#231 Work_Sequence Checking the work sequence Sorting the parameters / stat Var Example:
"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
Sta_1_Activate
Second_Sta_Activate
Sta_2_Activate
Third_Sta_Activate
Sta_3_Activate
SIMATIC S7
Date:
18.09.2009
SITRAIN Training for
Automation and Industrial Solutions
File:
PRO3_02E.17
Siemens AG 2008. All rights reserved.

Static Variables (BOOL)

In addition to the IN and OUT parameters, the declaration of the following static variables makes sense:

Operation sequence or station sequence 1-2-3 Operation sequence or station sequence 1-3-2 Operation sequence or station sequence 2-1-3 Operation sequence or station sequence 2-3-1 Operation sequence or station sequence 3-1-2 Operation sequence or station sequence 3-2-1 Transport request of first station Transport request of second station Transport request of third station

#First_Sta_Transp

#Second_Sta_Transp

#Third_Sta_Transp

#Work_Sequence_321

#Work_Sequence_312

#Work_Sequence_231

#Work_Sequence_213

#Work_Sequence_132

#Work_Sequence_123

Assignment of

The internal static variables are used to "sort" FB input parameters and FB output

Static Variables

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 Date: 18.09.2009 Siemens AG 2008. All

Parameter Description: "FB_Sequence" (FB 30) Block

Parameter Description: "FB_Sequence" (FB 30) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.18

SITRAIN Training for Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

Enable

BOOL

Enable block

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

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: 18.09.2009 Siemens AG 2008.

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

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

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 Press_1 Punch Guard Press_2

Object-Oriented Programming by Means of Multiple Instances

Example: Pressline

Press_1 Punch Guard
Press_1
Punch
Guard
Press_1 Punch Guard Press_2 Transport

Press_2

Transport

Transport

Machine Structure

Transport M a c h i n e S t r u c t u r

FB: "Pressline"

FB: #Press_1

FB: #Punch

FB: #Guard

FB: #Press_2

FB: #Punch

FB: #Guard

FB: #Transport

Logical division of the program with the help of FB instances

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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

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

Software

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 pre- fabricated 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" DB10 FB1:"Press" Data of FB10 Data

Implementing the "Press Line" in STEP 7

FB4:"Punch"

DB10

FB1:"Press"

in STEP 7 FB4:"Punch" DB10 FB1:"Press" Data of FB10 Data for Press_1 Press_1. Punch

Data of FB10

Data for Press_1

Press_1. Punch

Data of FB10 Data for Press_1 Press_1. Punch Press_1. Guard Data for Press_2 Press_2. Punch Press_2.

Press_1. Guard

Data for Press_2

Press_2. Punch

of FB10 Data for Press_1 Press_1. Punch Press_1. Guard Data for Press_2 Press_2. Punch Press_2. Guard

Press_2. Guard

Data for Transport

Instance-DB of FB10

stat Punch FB4 FB10:"Pressline" stat Guard FB5 stat Press_1 FB1 FB5:"Guard" stat Press_2 FB1
stat
Punch
FB4
FB10:"Pressline"
stat
Guard
FB5
stat
Press_1
FB1
FB5:"Guard"
stat
Press_2
FB1
CALL #Punch
stat
Transport
FB2
.
CALL #Guard
FB1: "Press"
CALL #Press_1
FB4:"Punch"
stat
Punch
FB4
.
stat
Guard
FB5
CALL #Press_2
.
CALL #Transport
FB5:"Guard"
FB5:"Guard"
CALL #Punch . CALL #Guard FB2: "Transport"
CALL #Punch
.
CALL #Guard
FB2: "Transport"

OB1

CALL FB10, DB10

#Press_2 . CALL #Transport FB5:"Guard" CALL #Punch . CALL #Guard FB2: "Transport" OB1 CALL FB10, DB10

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.21

SITRAIN Training for Automation and Industrial Solutions

Multiple Instance

When a multiple instance model is used, the instance DB contains the data for

Model

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 Main (Load/Unload) Conveyor Station Control Station 1 Station 2 Station
Task Description: Multiple Instance Model Main (Load/Unload) Conveyor Station Control Station 1 Station 2 Station
Task Description: Multiple Instance Model
Main
(Load/Unload)
Conveyor
Station
Control
Station 1
Station 2
Station 3
"FB_Belt"
"FB_Station"
"FB_Station"
"FB_Station"
"FB_Main_Station"
M u l t i
-
I n s t a n c e s
Left
Right
#TON_Delay
#TON_Delay
#TON_Delay
_Proc
_Proc
_Proc
L_Bay-LB
TON
TON
TON
T_Bay-LB
Work sequence
"FB_Sequence"

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 station‘s 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 Proc essing Time with SFB 4 "TON" SIMATIC S7 Date: 18.09.2009

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

Exercise 3: Programming the Proc essing Time with SFB 4 "TON"

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.23

SITRAIN Training for Automation and Industrial Solutions

What to Do

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", on- delay 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) Main Production Line Conveyor (Load/Unload) Control
Task Description: Multiple Instance "FB_Line" (FB 31) Main Production Line Conveyor (Load/Unload) Control
Task Description: Multiple Instance "FB_Line" (FB 31)
Main
Production Line
Conveyor
(Load/Unload)
Control
Station
"F B _ L I n e"
"FB_Belt"
#Station_1
#Station_2
#Station_3
"FB_Main_Station"
Left
Right
#TON_Delay
#TON_Delay
#TON_Delay
_Proc.
_Proc.
_Proc.
L_Bay-LB
TON
TON
TON
T_Bay-LB
Work sequence
"F B _ S e q u e n c e"

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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: 18.09.2009 Siemens AG 2008. All

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

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

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.25

SITRAIN Training for Automation and Industrial Solutions

What to Do

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 Date: 18.09.2009 File: PRO3_02E.26 SIMATIC S7 Siemens AG 2008.

If You Want to Know More

If You Want to Know More
Date: 18.09.2009 File: PRO3_02E.26
Date:
18.09.2009
File:
PRO3_02E.26

SIMATIC S7

SIMATIC S7

Siemens AG 2008. All rights reserved.

SITRAIN Training for Automation and Industrial Solutions

Note

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 Processi ng (According to IEC 61131-3)   Transitions Steps     Actions

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

 

Transitions

Steps

   

Actions

 
   

T

5

 
 
 

S

0

 

Initialization

 

#Initial_Step

#Main_Station_Transp_Req

     
   

T

1

 

S

1

N

#Sta_X_Activate

#First_Sta_Activate

L

 
 

#Sta_X_Transp_Req

 

T

2

#Transp_Req_L / R

 

S

2

N

#Sta_Y_Activate

   

#Second_Sta_Activate

L

#Transp_Req_L / R

#Sta_Y_Transp_Req

 

T

3

 

S

3

N

#Sta_Z_Activate

#Third_Sta_Activate

L

#Transp_Req_L / R

 

#Sta_Z_Transp_Req

   
   

T

4

 

S

4

L

   

#Go_To_Unload

#Transp_Req_R

#Main_Station_Transp_Stop

#Main_Station_Transp_Stop
#Main_Station_Transp_Stop
#Main_Station_Transp_Stop
#Main_Station_Transp_Stop

T 5

S 0

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

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 S 1 #First_Sta_Activate #First_Sta_Transp_Req T 2 N S 2 #Sta_Y_Activate

Sequencer: According to IEC61131-3

S 1 #First_Sta_Activate #First_Sta_Transp_Req T 2 N S 2 #Sta_Y_Activate #Second_Sta_Activate L #Transp_Req_L / R
S
1
#First_Sta_Activate
#First_Sta_Transp_Req
T 2
N
S
2
#Sta_Y_Activate
#Second_Sta_Activate
L
#Transp_Req_L / R

Sequencer: Conversion to STEP 7 Ladder Logic

Sequencer:

#First_Sta #First_Sta #First_Sta _Activate _Transp_Req _Activate R #Second_Sta _Activate S
#First_Sta
#First_Sta
#First_Sta
_Activate
_Transp_Req
_Activate
R
#Second_Sta
_Activate
S

Command Output (Actions):

SIMATIC S7

Siemens AG 2008. All rights reserved.

#Work_ #Second_Sta #First_Sta Sequence_XYZ _Activate _Activate #Transp _Req_L/R (other conditions) Date:
#Work_
#Second_Sta
#First_Sta
Sequence_XYZ
_Activate
_Activate
#Transp
_Req_L/R
(other conditions)
Date:
18.09.2009
SITRAIN Training for
Automation and Industrial Solutions
File:
PRO3_02E.28

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 : #Main_Sta_Transp_Stop #Initial_Step S #First_Sta _Activate

Sequencer: Conversion to STEP 7 (Ladder)

Initial Step :

#Main_Sta_Transp_Stop #Initial_Step S #First_Sta _Activate R #Second_Sta _Activate R #Third_Sta _Activate R
#Main_Sta_Transp_Stop
#Initial_Step
S
#First_Sta
_Activate
R
#Second_Sta
_Activate
R
#Third_Sta
_Activate
R
#Go_To_Unload
R

First Step :

#Main_Sta_

#Initial_Step Transp_Req #Initial_Step R #First_Sta _Activate S
#Initial_Step
Transp_Req
#Initial_Step
R
#First_Sta
_Activate
S

Last Step:

SIMATIC S7

Siemens AG 2008. All rights reserved.

#Third_Sta #Third_Sta #Third_Sta _Activate _Transp _Activate R #Go_To_Unload S Date: 18.09.2009 SITRAIN
#Third_Sta
#Third_Sta
#Third_Sta
_Activate
_Transp
_Activate
R
#Go_To_Unload
S
Date:
18.09.2009
SITRAIN Training for
Automation and Industrial Solutions
File:
PRO3_02E.29

Significance of the Initial Step

Last 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.

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

Static Variables of "FB_Sequence" (FB 30)

"FB_Sequence" w#16#231 Work_Sequence Checking the work sequence Sorting the parameters / stat Var Example:
"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
Sta_1_Activate
Second_Sta_Activate
Sta_2_Activate
Third_Sta_Activate
Sta_3_Activate
SIMATIC S7
Date:
18.09.2009
SITRAIN Training for
Automation and Industrial Solutions
File:
PRO3_02E.30
Siemens AG 2008. All rights reserved.

Static Variables (BOOL)

In addition to the IN and OUT parameters, the declaration of the following static variables makes sense:

Operation sequence or station sequence 1-2-3 Operation sequence or station sequence 1-3-2 Operation sequence or station sequence 2-1-3 Operation sequence or station sequence 2-3-1 Operation sequence or station sequence 3-1-2 Operation sequence or station sequence 3-2-1 Transport request of first station Transport request of second station Transport request of third station

#First_Sta_Transp

#Second_Sta_Transp

#Third_Sta_Transp

#Work_Sequence_321

#Work_Sequence_312

#Work_Sequence_231

#Work_Sequence_213

#Work_Sequence_132

#Work_Sequence_123

Assignment of

The internal static variables are used to "sort" FB input parameters and FB output

Static Variables

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 Date: 18.09.2009 Siemens AG 2008. All

Parameter Description: "FB_Sequence" (FB 30) Block

Parameter Description: "FB_Sequence" (FB 30) Block

SIMATIC S7

Date:

18.09.2009

SIMATIC S7 Date: 18.09.2009

Siemens AG 2008. All rights reserved.

File:

PRO3_02E.31

SITRAIN Training for Automation and Industrial Solutions

Declaration

Name

Type

Description

in Parameters

Enable

BOOL

Enable block

Work_Sequence

WORD

Processing sequence at the 3 stations

Stations_ready BOOL

Status of the 3 processing 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

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)

ST-PRO3
ST-PRO3

SITRAIN Training for Automation and Industrial Solutions

Page 32

FBs and the Multiple Instance Model