How to Use a Function or a Function Block in IL Language

General Information

This part explains how to implement a function and a function block in IL language.

Functions IsFirstMastCycle and SetRTCDrift and Function Block TON are used as examples to show implementations.

Using a Function in IL Language

This procedure describes how to insert a function in IL language:

Step

Action

1

Open or create a new POU in Instruction List language.

NOTE: The procedure to create a POU is not detailed here. For more information, refer to Adding and Calling POUs.

2

Create the variables that the function requires.

3

If the function has 1 or more inputs, start loading the first input using LD instruction.

4

Insert a new line below and:

  • type the name of the function in the operator column (left field), or

  • use the Input Assistant to select the function (select Insert Box in the context menu).

5

If the function has more than 1 input and when Input Assistant is used, the necessary number of lines is automatically created with ??? in the fields on the right. Replace the ??? with the appropriate value or variable that corresponds to the order of inputs.

6

Insert a new line to store the result of the function into the appropriate variable: type ST instruction in the operator column (left field) and the variable name in the field on the right.

To illustrate the procedure, consider the Functions IsFirstMastCycle (without input parameter) and SetRTCDrift (with input parameters) graphically presented below:

Function

Graphical Representation

without input parameter:

IsFirstMastCycle

with input parameters:

SetRTCDrift

In IL language, the function name is used directly in the operator column:

Function

Representation in POU IL Editor

IL example of a function without input parameter:

IsFirstMastCycle

IL example of a function with input parameters:

SetRTCDrift

Using a Function Block in IL Language

This procedure describes how to insert a function block in IL language:

Step

Action

1

Open or create a new POU in Instruction List language.

NOTE: The procedure to create a POU is not detailed here. For more information, refer to Adding and Calling POUs.

2

Create the variables that the function block requires, including the instance name.

3

Function Blocks are called using a CAL instruction:

  • Use the Input Assistant to select the FB (right-click and select Insert Box in the context menu).

  • Automatically, the CAL instruction and the necessary I/O are created.

Each parameter (I/O) is an instruction:

  • Values to inputs are set by ":=".

  • Values to outputs are set by "=>".

4

In the CAL right-side field, replace ??? with the instance name.

5

Replace other ??? with an appropriate variable or immediate value.

To illustrate the procedure, consider this example with the TON Function Block graphically presented below:

Function Block

Graphical Representation

TON

In IL language, the function block name is used directly in the operator column:

Function Block

Representation in POU IL Editor

TON