Functions for program flow control (FBD)

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 280 - 285)

The functions for program flow control are:

b The jump functions to continue program execution in the desired network b The jump list to select a jump destination depending on a numerical value b The jump distributor for selecting a jump destination depending on

number ranges

b The block end function to end program execution in the block b The block call functions for calling functions and function blocks

Fig. 8.38 shows an overview of these functions. A detailed description of these func- tions is provided in Chapter 12 “Program flow control” on page 406.

Fig. 8.38 Overview of functions for program flow control in the function block diagram JMP

JMPN

RET Binary tag

Destination

Destination

SWITCH Data type EN

K

==

== DEST1

ELSE DEST0

*

Jump functions Jump list

Jump distributor

Block calls

Function call (FC)

Function block call (FB) Block end function

Functions for program flow control

FC name

JMP_LIST

EN

EN

name1

K

...

name2 ...

name3

DEST1

...

ENO

DEST0

DB name FB name EN

name1 ...

name2 ...

name3 ...

ENO Jump if “0”

Jump if “1”

Jump destination Destination

*

8.6.1 Jump functions in the function block diagram

A JMP or JMPN jump function is used to exit the linear processing in a block and – depending on the result of preceding logic operation – continue this processing in another network in the block. If there is no preceding logic operation for JMP, the jump function is always performed. To program a jump function, drag the JMP or JMPN function from the program elements catalog under Basic instructions > Pro- gram control operations to the working area.

The jump label above the jump function defines the jump destination, which must be at the beginning of a network. To program the jump destination, drag the Label function from the program elements catalog under Basic instructions > Program control operations to the working area.

Fig. 8.39 shows a jump function using a program loop as an example. In a #Current data field with 16 components from #Current[0] to #Current[15], the maximum value is searched for. The tags #Index and #MaxValue are initialized with the value 0. A comparison function in the program loop compares the value of #MaxValue with the value of #Current[#Index]. If #MaxValue is less than #Current[#Index], it is overwritten with the larger value of #Current[#Index]. #Index is then increased by +1. As long as #Index is less than or equal to 15, it jumps to the beginning of the pro- gram loop (to the jump destination MaxSearch) and the program part runs again.

Fig. 8.39 Example of a program loop with conditional jump

8.6.2 Jump list in the function block diagram

The jump list is represented as a box. It is only processed if the EN input signal state is “1”. The value of parameter K (0 to 99) determines the box output whose jump destination is jumped to. To program the jump list, drag the JMP_LIST function from the program elements catalog under Basic instructions > Program control operations to the working area.

If in Fig. 8.40 the #JumpSelection tag has value 0, it jumps to the Adder jump label;

if the value is 1, to the jump label FC_call, and if the value is 3, to the jump label FB_- call.

8.6.3 Jump distributor in the function block diagram

The jump distributor is represented as a box. The box is only processed if the EN input signal state is “1”. The value of parameter K is compared with a value of one of the other input parameters. If the two match, program processing continues at the assigned jump destination. The comparison operations can be selected from a drop-down list. To program a jump distributor, drag the SWITCH function from the program elements catalog under Basic instructions > Program control operations to the working area.

If in Fig. 8.41 the #JumpSelection tag has a value less than 10, it jumps to jump label FC_call; for a value greater than 120 to jump label FB_call; otherwise to jump label Adder.

Fig. 8.40 Example of a jump list

Fig. 8.41 Example of a jump distributor

8.6.4 Block end function in the function block diagram

The processing in a block is terminated by the RET box. The block end function may not be present in a network together with a jump function.

To program a block end function, drag the RET function from the program elements catalog under Basic instructions > Program control operations to the working area.

In Fig. 8.42, the block is exited if an error occurs when processing the ADD box. The ENO output has the signal state “0” which is then negated, thus triggering the RET box. The RET box receives the logic operation result “0” (which is output by the ter- minated block at the ENO output) by means of the FALSE constant. The result can be scanned in the calling block.

8.6.5 Block call functions in the function block diagram

Calling of blocks is represented by EN/ENO boxes. With functions (FC), the block name is present quasi as a function name in the box; with function blocks, the instance name (the name of the instance data block or of the local instance) is addi- tionally present above the box.

A block call is programmed by opening the Program blocks folder in the project tree and dragging the desired block to the working area.

Fig. 8.42 Examples of a block end function

Fig. 8.43 Example of calling a function (FC)

In the example in Fig. 8.43, if the signal state is “1” at the “Input 2” tag, the function

“Adder_2” is called. Program processing in the block is then ended with the value of the return variable #AddError.

In the example in Fig. 8.44, the “Totalizer” function block is called. Its instance data is present in the data block “Totalizer_DB”.

Fig. 8.44 Example of calling a function block

9 Structured Control Language SCL

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 280 - 285)

Tải bản đầy đủ (PDF)

(577 trang)