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:

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

ouse 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

G-SE-0004461.1.gif-high.gif

 

 

with input parameters:

SetRTCDrift

G-SE-0004463.1.gif-high.gif

 

 

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

G-SE-0004460.1.gif-high.gif

 

 

IL example of a function with input parameters:

SetRTCDrift

G-SE-0004464.1.gif-high.gif

 

 

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:

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

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

Each parameter (I/O) is an instruction:

oValues to inputs are set by ":=".

oValues 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

G-SE-0004465.1.gif-high.gif

 

 

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

Function Block

Representation in POU IL Editor

TON

G-SE-0004462.1.gif-high.gif