Function Block

Help Contents

Introduction

A Function_Block is a sequence of statements executed in order with state information preserved between executions.

Syntax

A Function Block uses this syntax:

function-block ::=
  FUNCTION_BLOCK function-block-name
    { variable-declaration }
    [ function-block-code ]
  END_FUNCTION_BLOCK

function-block-code ::= [ structured-text | instruction-list ]

Where:

Remarks

Use any of the following for the function-block-code:

A Function Block can call another Function or Function Block.

Examples

  1. A rising edge detector:
    (* Rising edge detector *)
    Function_Block R_TRIG
        Var_Input CLK : Bool; End_Var
        Var_Output Q : Bool; End_Var
        Var M : Bool := False; End_Var
    
        Q := CLK AND NOT M;
        M := CLK;
    End_Function_Block

Standards Compliance

IEC 61131-3 Second Edition: Table 33.

IEC 61131-3 Third Edition: Table 40.

Further Information

Program Units

To learn about other program units.

Variable Declarations

To learn about variable declarations.

ST Statements

To learn about ST Statements.

Glossary

For the meaning of terms used in Fernhill SCADA.