Functions and function blocks

Một phần của tài liệu Bsi bs en 61131 3 2013 (Trang 200 - 203)

The general rules and features for function calls and for function block calls apply also in IL.

The features for the call of function blocks and functions are defined in Table 69.

7.2.4.2 Function

Functions shall be called by placing the function name in the operator field. The parameters may be given all together in one operand field or each parameter in an operand field line by line.

In case of the non-formal call the first parameter of a function need not to be contained in the parameter, but the current result shall be used as the first parameter of the function. Addition- al parameters (starting with the second one), if required, shall be given in the operand field, separated by commas, in the order of their declaration.

Functions may have a result. As shown in features 3 in Table 69 the successful execution of a RET instruction or upon reaching the end of the POU the POU delivers the result as the “cur- rent result”.

If a function is called which does not have a result, the “current result” is undefined.

7.2.4.3 Function block

Functions block shall be called by placing the keyword CAL in the operator field and the func- tion block instance name in the operand field. The parameters may be given all together or each parameter may be placed in an operand field.

Function blocks can be called conditionally and unconditionally via the EN operator.

All parameter assignments defined in a parameter list of a conditional function block call shall only be performed together with the call, if the condition is true.

If a function block instance is called, the “current result” is undefined.

7.2.4.4 Methods

Methods shall be called by placing the function block instance name, followed by a single pe- riod “.”, and the method name in the operator field. The parameters may be given all together in one operand field or each parameter in an operand field line by line.

In case of the non-formal call the first parameter of a method need not to be contained in the parameter, but the current result shall be used as the first parameter of the function. Addition-

al parameters (starting with the second one), if required, shall be given in the operand field, separated by commas, in the order of their declaration.

Methods may have a result. As shown in features 4 in Table 69 the successful execution of a RET instruction or upon reaching the end of the POU the POU delivers the result as the “cur- rent result”.

If a method is called which does not have a result, the “current result” is undefined.

Table 69 shows the alternative calls of the IL language.

Table 69 – Calls for IL language

No. Description Example (NOTE)

1a Function block call with non-formal parameter

list CAL C10(%IX10, FALSE, A, OUT, B)

CAL CMD_TMR(%IX5, T#300ms, OUT, ELAPSED) 1b Function block call with formal parameter list CAL C10( // FB instance name

CU := %IX10, R := FALSE, PV := A,

Q => OUT, CV => B) CAL CMD_TMR(

IN := %IX5, PT := T#300ms, Q => OUT, ET => ELAPSED, ENO => ERR) 2 Function block call with load/store of standard

input parameters LD A

ADD 5 ST C10.PV LD %IX10 ST C10.CU

CAL C10 // FB instance name LD C10.CV // current result 3a Function call with formal parameter list LIMIT( // Function name

EN := COND, IN := B, MN := 1, MX := 5, ENO => TEMPL

) ST A // Current result new 3b Function call with non-formal parameter list LD 1 // set current result

LIMIT B, 5 // and use it as IN ST A // new current result 4a Method call with formal parameter list FB_INST.M1( // Method name

EN := COND, IN := B, MN := 1, MX := 5, ENO => TEMPL

) ST A // Current result new 4b Method call with non-formal parameter list LD 1 // set current result

FB_INST.M1 B, 5 // and use it as IN ST A // new current result

No. Description Example (NOTE) NOTE A declaration such as

VAR C10 : CTU;

CMD_TMR: TON;

A, B : INT;

ELAPSED: TIME;

OUT, ERR, TEMPL, COND: BOOL;

END_VAR

is assumed in the above examples.

The standard input operators of standard function blocks defined in Table 70 can be used in conjunction with feature 2 (load/store) in Table 69. This call is equivalent to a CAL with a pa- rameter list, which contains only one variable with the name of the input operator.

Parameters, which are not supplied, are taken from the last assignment or, if not present, from initialization. This feature supports problem situations, where events are predictable and therefore only one variable can change from one call to the next.

EXAMPLE 1

Together with the declaration

VAR C10: CTU; END_VAR the instruction sequence

LD 15

PV C10

gives the same result as

CAL C10(PV:=15)

The missing inputs R and CU have values previously assigned to them. Since the CU input detects a rising edge, only the PV input value will be set by this call; counting cannot happen because an unsupplied pa- rameter cannot change. In contrast to this, the sequence

LD %IX10

CU C10

results in counting at maximum in every second call, depending on the change rate of the input %IX10.

Every call uses the previously set values for PV and R.

EXAMPLE 2

With bistable function blocks, taking a declaration VAR FORWARD: SR; END_VAR

this results into an implicit conditional behavior. The sequence LD FALSE

S1 FORWARD

does not change the state of the bistable FORWARD. A following sequence LD TRUE

R FORWARD resets the bistable.

Table 70 – Standard function block operators for IL language

No. Function

block Input

operator Output

operator

1 SR S1,R Q

2 RS S,R1 Q

3 F/R_TRIG CLK Q

4 CTU CU,R,PV CV, Q,

also RESET

5 CTD CD,PV CV, Q

6 CTUD CU,CD,R,PV CV, QU,QD,

also RESET

7 TP IN,PT CV, Q

8 TON IN,PT CV, Q

9 TOF IN,PT CV, Q

NOTE LD (Load) is not necessary as a Standard Function Block input operator, because the LD functionality is included in PV.

Parameters, which are not supplied, are taken from the last assignment or, if not present, from initialization. This feature supports problem situations, where events are predictable and therefore only one variable can change from one call to the next.

Một phần của tài liệu Bsi bs en 61131 3 2013 (Trang 200 - 203)

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

(234 trang)