PRO3 02E FBs Multi-Instances

32
ST-PRO3 FBs and the Multiple Instance Model Page 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 Date: 18.09.2009 File: PRO3_02E.1 SIMATIC S7 SITRAIN Training for Automation and Industrial Solutions Siemens AG 2008. All rights reserved. Block Calls and the Multiple Instance Model

description

multiinstancias s7

Transcript of PRO3 02E FBs Multi-Instances

Page 1: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 1

SITRAIN Training forAutomation and Industrial Solutions

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

Date: 18.09.2009File: PRO3_02E.1

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Block Calls and the Multiple Instance Model

Page 2: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 2

SITRAIN Training forAutomation and Industrial Solutions

Modularization Abstraction is the basis for solving complex problems, in which we concentrateof Tasks 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 STEP7 supports this concept of modularization with its block model. The partialProgramming 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.

Date: 18.09.2009File: PRO3_02E.2

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Blocks for Structured Programming

Modularization of theEntire Task:

Partial tasks are solved in their own blocksParameter assignment enables flexible usage

• Example: Drilling cycle with parameter-assignable depth

Re-usability of Blocks:Blocks can be called as often as is requiredRestrictions:

• no access to global addresses

• communication only via the parameter list

OB 1

Motor 1Motor 1

FB1

ValvesValves

FB2

ControllerController

FB10

FC 5Limitvalue Copying

SFC

. . .

.

.

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

.

.

FB 1Address Decl. Name Type0.0 in Start BOOL0.1 in Stop BOOL2.0 out Motor_on BOOL4.0 out Speed INT6.0 stat Speed_old INT0.0 temp Calc_1 INT

.

.

.A #StartAN #Stop= #Motor_on.

DB 2OB 1

Page 3: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 3

SITRAIN Training forAutomation 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 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.

Downloading In addition to the advantages of structured programming, the STEP 7 block Blocks Later On 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.

Date: 18.09.2009File: PRO3_02E.3

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Block Overview in STEP 7

Properties

Organizationblock (OB)

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

Type of Block

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 functionblock (SFB)

- FB (with memory) stored in the CPU‘s operating system andcallable by the user

Systemfunction (SFC)

- function (without memory) stored in the CPU‘s operating systemand callable by the user

System datablock (SDB) - data block for configuration data and parameters

Page 4: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 4

SITRAIN Training forAutomation and Industrial Solutions

What is an The concept of instantiating function blocks has great importance and makes upInstance? 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.

Date: 18.09.2009File: PRO3_02E.4

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Instance Formation of Function Blocks

Conveyor

FBx

+

DBy

Statusdataof conveyor

Algorithmsfor controllogic

OB, FB or FC

Call FBx, DBy

CALL FBx, DBy

FB call with Instance DB

CALL #Guard

CALL #Punch

...stat Guard FBastat Punch FBc Status

dataof guard

Status dataof punch

FB Instance

FBx

Declaration within FBs(Multi-instances)

Punch

Guard

DBy

Page 5: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 5

SITRAIN Training forAutomation and Industrial Solutions

Multiple Instance In addition to instantiation of function blocks, when you specify an instanceModel 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.

Date: 18.09.2009File: PRO3_02E.5

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Structure of the Multiple Instance Model

FB10

Datafor punch

Instance DB of FB10

CALL Guard.CALL Punch.CALL Conv.

DB10

...stat Guard FB4stat Punch FB5stat Conv. FB2

Datafor conveyor

FB4Control logic for a guard

FB5

Control logic for a punch

Such as OB1

.CALL FB10,DB10.

Datafor guard

FB2Control logic for a conveyor

The figure shows a possible technological structure when only a press and a conveyor exist.

Page 6: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 6

SITRAIN Training forAutomation and Industrial Solutions

Benefits of the With the multiple instance model you can store the respective data sections ofMultiple Instance several instances of one and the same call hierarchy in one single DB.Model 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 To use an FB as a multiple instance without problems, you must adhere to theMultiple Instances following:

• For the purpose of process control, no direct access to global addresses ofthe 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.

Date: 18.09.2009File: PRO3_02E.6

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Characteristics of the Multiple Instance Model

Benefits of the multiple instance model:Only one DB is required for several instancesNo additional management is necessary in the setting up of "private" data areas for the respective instancesThe 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 possibleAccess to process signals or communication with other process units can only take place using FB parametersThe 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>

Page 7: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 7

SITRAIN Training forAutomation and Industrial Solutions

How the Production The production line consists of the processing stations 1 to 3, a main stationLine Works 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 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.

Date: 18.09.2009File: PRO3_02E.7

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Basic Program of the Production LineI 0.0I 0.1I 0.2I 0.3I 0.4I 0.5I 0.6I 0.7

Q 4.0

S_M/A_ModeSelect

T_System_ON

T_M/A_Accept

L_SYSTEML_MAN

L_AUTO

T_System_OFFT_Jog_RIGHTT_Jog_LEFT

Q 4.1Q 4.2Q 4.3

"BAY3"

"T_Bay3"

"LB"

RawMaterial

"L_Bay3"

"T_Bay2""L_Bay2"

"T_Bay1""L_Bay1"

"T_Bay-LB"

"L_Bay-LB"

Station 3

Main(Load/Unload)

Station"BAY2"

Station 2"BAY1"

Station 1

Page 8: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 8

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin 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 preselected1 = AUTO mode preselected

Mode_Accept BOOL Accept or activate preselected mode

out Parameters System_ON BOOL Operating status of systemAuto_Mode BOOL Operating status of AUTO modeManual_Mode BOOL Operating status of MAN mode

Date: 18.09.2009File: PRO3_02E.8

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Modes" (FB 1) Block

Page 9: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 9

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin Parameters Enable BOOL Enable Main Station

Photo_Eye BOOL Light barrier of Main StationPushbutton BOOL Pushbutton of Main Station: Start production

sequenceFlash_Freq BOOL 2-Hz frequency for optical status indicationConv_Stopped BOOL Status of conveyor motor: 1 = conveyor stoppedLine_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 stopIndicator_Light BOOL Status indication:

Continuous light: new part can be loadedFlashing: start / end part processing

Date: 18.09.2009File: PRO3_02E.9

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Main_Station" (FB 2) Block

Page 10: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 10

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin Parameters Enable BOOL Enable processing station

Sta_activate BOOL Activate station for new part processingProx_Sw BOOL Station’s proximity sensorPushbutton BOOL Pushbutton: Acknowledgement of part processingFlash_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 activatedFlashing: Part is being processed

Date: 18.09.2009File: PRO3_02E.10

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Station" (FB 3) Block

Page 11: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 11

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin 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 rightJog_Left BOOL Jog conveyor motor leftAuto_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 rightConv_Belt_Left BOOL Control conveyor motor left

Date: 18.09.2009File: PRO3_02E.11

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Belt" (FB 4) Block

Page 12: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 12

SITRAIN Training forAutomation 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_Autoof "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.

Date: 18.09.2009File: PRO3_02E.12

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Interconnection of Blocks (Initial Situation)

Indicator_Light

Transp_Stop

"FB_Main_Station"

"DB_Main_Station"

"FB_Belt"

"DB_Belt"

1

Jog_Right

Jog_Left

Auto_Stop

Auto_Start_Right

Auto_Start_left

Auto_Mode

Conv_BeltRight

Conv_BeltLeft

Manual_Mode

1

Transp_Req

Pushbutton

Flash_Freq

Conv_Stopped

Photo_Eye

Enable

1

Line_Ready

1

0

1Indicator_Light

Transp_ready

Sta_ready

"FB_Station"

Enable

Stop_Busy

"DB_Stat1"

Sta_activate

Prox_Sw

Pushbutton

Flash_Freq

0

11

0

1Indicator_Light

Transp_Ready

Sta_ready

"FB_Station"

Enable

Stop_Busy

"DB_Stat2"

Sta_activate

Prox_Sw

Pushbutton

Flash_Freq

0

11

0

1Indicator_Light

Transp_Ready

Sta_ready

"FB_Station"

Enable

Stop_Busy

"DB_Stat3"

Sta_activate

Prox_Sw

Pushbutton

Flash_Freq

0

11

Documentation of the Production Process

Page 13: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 13

SITRAIN Training forAutomation 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.

Date: 18.09.2009File: PRO3_02E.13

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Exercise 1: Creating a HW Station and Commissioning the Program

Page 14: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 14

SITRAIN Training forAutomation and Industrial Solutions

The Function The station sequence 3->2->1 for the processing of parts in the production Up Until Now 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 – .

Date: 18.09.2009File: PRO3_02E.14

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Task Description: "FB_Sequence" (FB 30)

to Station 2

to Station 3

to Station 1

Back to Main Station

Station 3

FB_Station

T_Bay3

L_Bay3

Station 1

FB_Station

T_Bay1

L_Bay1

Station 2

FB_Station

T_Bay2

L_Bay2

"FB_Main_Station"

Main_Station

T_Bay-LB

L_Bay-LB

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

"FB_Belt"

Left

Right

ConveyorControl

Possible work sequences:"IW_BCD_Sequence", IW2(thumbwheel on the simulator)

0 1 2 30 1 3 20 2 1 30 2 3 10 3 1 20 3 2 1

Page 15: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 15

SITRAIN Training forAutomation and Industrial Solutions

Sequential The slide shows that the production line part processing follows a strict stepControl 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.

Date: 18.09.2009File: PRO3_02E.15

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Station 1Station 1 Station 2Station 2 Station 3Station 3#Work_Sequence

#Work_Sequence_123 = true#First_Sta_Activate

#Second_Sta_Activate #Third_Sta_Activate

#First_Sta_Activate#Second_Sta_Activate

#Third_Sta_Activate

#First_Sta_Activate#Second_Sta_Activate#Third_Sta_Activate

#First_Sta_Activate#Second_Sta_Activate

#Third_Sta_Activate

#First_Sta_Activate#Second_Sta_Activate#Third_Sta_Activate

Actions

#Work_Sequence #Transp_Req_LFT1 - 2 - 31 - 3 - 22 - 1 - 32 - 3 - 13 - 1 - 23 - 2 - 1

#First_Sta_Activate#First / #Third_Sta_Activate#First / #Second_Sta_Activate#First / #Third_Sta_Activate#First / #Second_Sta_Activate#First / #Second / #Third_Sta_Activate

#First_Sta_Activate#Second_Sta_Activate#Third_Sta_Activate

#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

#Go_To_Unload

#Go_To_Unload

#Go_To_Unload

#Go_To_Unload

#Go_To_Unload

#Go_To_Unload

Main StationMain Station

Sequential Control of Part Processing using "FB_Sequence"

#Work_Sequence_132 = true

#Work_Sequence_213 = true

#Work_Sequence_231 = true

#Work_Sequence_312 = true

#Work_Sequence_321 = true

#Transp_Req_RT

Steps

Page 16: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 16

SITRAIN Training forAutomation 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.

Date: 18.09.2009File: PRO3_02E.16

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

#Main_Station_Transp_Req

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

S 1#First_Sta_Activate

S 2#Second_Sta_Activate

S 3#Third_Sta_Activate

S 4#Go_To_Unload

#Sta_Z_Activate#Transp_Req_L / R

#Transp_Req_R

Initialization

#Sta_X_Transp_Req

#Sta_Y_Transp_Req

#Sta_Z_Transp_Req

#Main_Station_Transp_Stop

S 0

T 5

T 4

T 3

T 2

T 1

T 5

Transitions Steps Actions

S 0#Initial_Step

#Sta_Y_Activate#Transp_Req_L / R

N

L

NL

L

#Sta_X_Activate#Transp_Req_L / R

N

L

Page 17: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 17

SITRAIN Training forAutomation 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 The internal static variables are used to "sort" FB input parameters and FB outputStatic 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.

Date: 18.09.2009File: PRO3_02E.17

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Static Variables of "FB_Sequence" (FB 30)

"FB_Sequence"

Station_3_Transp_Req

Station_2_Transp_Req

Work_Seq_Error

Sta_1_Activate

Work_Sequence

Station_1_Transp_Req

Sta_2_Activate

Sta_3_Activate

First_Sta_Transp

Third_Sta_Activate

w#16#231 Checking the work sequenceSorting the parameters / stat Var

Example: #Work_Sequence_231 = true

Transp_Req_R

Transp_Req_L

Sequencer

Second_Sta_Transp

Third_Sta_Transp

Second_Sta_Activate

First_Sta_Activate

Main_Station_Transp_Req

Page 18: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 18

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin Parameters Enable BOOL Enable block

Work_Sequence WORD Processing sequence at the 3 stationsMain_Sta_Transp_Req BOOL Transport request from Main StationMain_Sta_Transp_Stop BOOL Request stop from Main StationSta_1_Transp_Req BOOL Transport request from Station 1Sta_2_Transp_Req BOOL Transport request from Station 2Sta_3_Transp_Req BOOL Transport request from Station 3

NoteWhen 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 StationSta_1_activate BOOL Activate Station 1 for part processingSta_2_activate BOOL Activate Station 2 for part processingSta_3_activate BOOL Activate Station 3 for part processingTransp_Req_R BOOL Request transport to the RIGHTTransp_Req_L BOOL Request transport to the LEFT

Date: 18.09.2009File: PRO3_02E.18

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Sequence" (FB 30) Block

Page 19: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 19

SITRAIN Training forAutomation 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".

Date: 18.09.2009File: PRO3_02E.19

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

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

Page 20: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 20

SITRAIN Training forAutomation 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 You can implement an object-oriented programming style with the help ofProgramming Style 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-timeSoftware 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.

Date: 18.09.2009File: PRO3_02E.20

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Object-Oriented Programming by Means of Multiple Instances

Machine StructureLogical division of theprogram with the help ofFB instances

Press_2Press_1

Transport

Example: PresslineFB: "Pressline"

FB: #Transport

FB: #Press_1

PunchGuard

FB: #Punch

FB: #Guard

FB: #Press_2

FB: #Punch

FB: #Guard

Page 21: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 21

SITRAIN Training forAutomation and Industrial Solutions

Multiple Instance When a multiple instance model is used, the instance DB contains the data forModel 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).

Date: 18.09.2009File: PRO3_02E.21

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Implementing the "Press Line" in STEP 7

FB10:"Pressline"

Instance-DB of FB10

CALL #Press_1.CALL #Press_2.CALL #Transport

DB10

...stat Press_1 FB1stat Press_2 FB1stat Transport FB2...

FB1:"Press"...stat Punch FB4stat Guard FB5...

CALL #Punch.CALL #Guard

...stat Punch FB4stat Guard FB5...

CALL #Punch.CALL #Guard

...

...

FB2: "Transport"

FB4:"Punch"

FB5:"Guard"

CALL FB10, DB10

OB1

FB1: "Press"

FB4:"Punch"

FB5:"Guard"

Data for Press_1

Data for Transport

Press_1. Guard

Press_2. Punch

Press_2. Guard

Data for Press_2

Data of FB10

Press_1. Punch

Page 22: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 22

SITRAIN Training forAutomation and Industrial Solutions

The Function When a piece reaches an activated station, "FB_Station" (FB 3) initiatesUp Until Now "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.

Date: 18.09.2009File: PRO3_02E.22

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Task Description: Multiple Instance Model

"FB_Main_Station"

Main(Load/Unload)

Station

T_Bay-LB

L_Bay-LB

Station 3

"FB_Station"

Station 2

"FB_Station"

Station 1

TON

#TON_Delay_Proc

"FB_Station""FB_Belt"

Left

Right

Conveyor Control

"FB_Sequence"

M u l t i - I n s t a n c e s

Work sequence

TON

#TON_Delay_Proc

TON

#TON_Delay_Proc

Page 23: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 23

SITRAIN Training forAutomation 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 thistime 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 beregenerated 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 therespective calls for the individual stations.

Date: 18.09.2009File: PRO3_02E.23

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

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

Page 24: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 24

SITRAIN Training forAutomation 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).

Date: 18.09.2009File: PRO3_02E.24

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

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

#Station_1

TON

#TON_Delay_Proc.

"FB_Main_Station"

Main(Load/Unload)

Station

"FB_Belt"

Left

Right

Conveyor Control

Production Line

"F B _ L I n e"

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

#Station_2

TON

#TON_Delay_Proc.

#Station_3

TON

#TON_Delay_Proc.

T_Bay-LB

L_Bay-LB

Page 25: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 25

SITRAIN Training forAutomation 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 DBsare 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.

Date: 18.09.2009File: PRO3_02E.25

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

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

Page 26: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 26

SITRAIN Training forAutomation and Industrial Solutions

Date: 18.09.2009File: PRO3_02E.26

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

If You Want to Know More

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.

Page 27: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 27

SITRAIN Training forAutomation 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.

Date: 18.09.2009File: PRO3_02E.27

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

#Main_Station_Transp_Req

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

S 1#First_Sta_Activate

S 2#Second_Sta_Activate

S 3#Third_Sta_Activate

S 4#Go_To_Unload

#Sta_Z_Activate#Transp_Req_L / R

#Transp_Req_R

Initialization

#Sta_X_Transp_Req

#Sta_Y_Transp_Req

#Sta_Z_Transp_Req

#Main_Station_Transp_Stop

S 0

T 5

T 4

T 3

T 2

T 1

T 5

Transitions Steps Actions

S 0#Initial_Step

#Sta_Y_Activate#Transp_Req_L / R

N

L

NL

L

#Sta_X_Activate#Transp_Req_L / R

N

L

Page 28: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 28

SITRAIN Training forAutomation 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 FBsthat 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 StepAND 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)

Date: 18.09.2009File: PRO3_02E.28

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Sequencer: According to IEC61131-3

Sequencer: Conversion to STEP 7 Ladder Logic

S 1#First_Sta_Activate

S 2#Second_Sta_Activate

#First_Sta_Transp_Req T 2

#First_Sta_Activate

#First_Sta_Transp_Req

#First_Sta_Activate

#Second_Sta_Activate

Sequencer: Command Output (Actions):

#Transp_Req_L/R

#Work_Sequence_XYZ

#Second_Sta_Activate

(other conditions)

#First_Sta_Activate

#Sta_Y_Activate#Transp_Req_L / R

N

L

R

S

Page 29: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 29

SITRAIN Training forAutomation and Industrial Solutions

Significance of the With the initial step, the starting point of the sequencer is defined in the program Initial Step - 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)

Date: 18.09.2009File: PRO3_02E.29

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Sequencer: Conversion to STEP 7 (Ladder)

#Main_Sta_Transp_Stop #Initial_Step

#First_Sta_Activate

Initial Step :

#Second_Sta_Activate

#Third_Sta_Activate

#Go_To_Unload

#First_Sta_Activate

First Step :

#Initial_Step#Main_Sta_Transp_Req #Initial_Step

Last Step:

#Go_To_Unload

#Third_Sta_Activate

#Third_Sta_Activate

#Third_Sta_Transp

R

S

S

R

R

R

R

R

S

Page 30: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 30

SITRAIN Training forAutomation 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 The internal static variables are used to "sort" FB input parameters and FB outputStatic 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.

Date: 18.09.2009File: PRO3_02E.30

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Static Variables of "FB_Sequence" (FB 30)

"FB_Sequence"

Station_3_Transp_Req

Station_2_Transp_Req

Work_Seq_Error

Sta_1_Activate

Work_Sequence

Station_1_Transp_Req

Sta_2_Activate

Sta_3_Activate

First_Sta_Transp

Third_Sta_Activate

w#16#231 Checking the work sequenceSorting the parameters / stat Var

Example: #Work_Sequence_231 = true

Transp_Req_R

Transp_Req_L

Sequencer

Second_Sta_Transp

Third_Sta_Transp

Second_Sta_Activate

First_Sta_Activate

Main_Station_Transp_Req

Page 31: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 31

SITRAIN Training forAutomation and Industrial Solutions

Declaration Name Type Descriptionin Parameters Enable BOOL Enable block

Work_Sequence WORD Processing sequence at the 3 stationsStations_ready BOOL Status of the 3 processing stationsMain_Sta_Transp_Req BOOL Transport request from Main StationMain_Sta_Transp_Stop BOOL Request stop from Main StationSta_1_Transp_Req BOOL Transport request from Station 1Sta_2_Transp_Req BOOL Transport request from Station 2Sta_3_Transp_Req BOOL Transport request from Station 3

NoteWhen 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 StationSta_1_activate BOOL Activate Station 1 for part processingSta_2_activate BOOL Activate Station 2 for part processingSta_3_activate BOOL Activate Station 3 for part processingTransp_Req_R BOOL Request transport to the RIGHTTransp_Req_L BOOL Request transport to the LEFT

Date: 18.09.2009File: PRO3_02E.31

SIMATIC S7 SITRAIN Training forAutomation and Industrial Solutions

Siemens AG 2008. All rights reserved.

Parameter Description: "FB_Sequence" (FB 30) Block

Page 32: PRO3 02E FBs Multi-Instances

ST-PRO3FBs and the Multiple Instance ModelPage 32

SITRAIN Training forAutomation and Industrial Solutions

Structogram for "FB_Sequence" (FB30)