IEC Editors and Basic Operations

See also: IEC 61131 Language Editor Programming

See also: Enhanced IEC 61131 Guide

See also: Project Toolbox for IEC

 

Topic Menu

 

IEC Editors

 

Bit Access

Access to bits of an integer

The user can directly specify a bit within an integer variable in expressions and diagrams using the following notation: Variable.BitNo

Where:

Variable: is the name of an integer variable

BitNo: is the number of the bit in the integer.

The variable can have one of the following data types:

0 always represents the least significant bit.

Example: "Tagname.0" , "Tagname.31" etc.

Return to the TopIEC Editors and Basic Operations

Function Calls

Calling a Function - A function calculates a result according to the current value of its inputs. Unlike a function block, a function has no internal data and is not linked to declared instances. A function has only one output: the result of the function. A function can be a standard function (SHL, SIN...)

ST Language

To call a function block in ST, the user has to enter its name, followed by the input parameters written between parentheses and separated by commas. The function call may be inserted into any complex expression. A function call can be used as an input parameter of another function. The following example demonstrates a call to "SEL" functions:

(* the following statement converts any integer value into the nearest even integer *)

iEvenVal := SEL ( ( iValue ), iValue, iValue+1 );

FBD and LD Languages

To call a function block in FBD or LD languages, the user just needs to insert the function in the diagram and connect its inputs and output.

IL Language

To call a function block in IL language, the user must load its first input parameter before the call, and then use the function name as an instruction, followed by the other input parameters, separated by commas. The result of the function is then the current result. The following example demonstrates a call to "SEL" functions:

(* the following statement converts any integer into "0" *)

Op1: LD iValue

SEL iValue, 0

ST iResult

Return to the Top: IEC Editors and Basic Operations

Function Block Calls

Calling a Function Block - CAL CALC CALNC CALCN

A function block groups an algorithm and a set of private data. It has inputs and outputs. A function block can be: a standard function block ( RS, TON10mS...) a block written in " C" language and embedded on the target. To use a function block, the user has to declare an instance of the block as a variable, identified by a unique name. Each instance of a function block is its own set of private data and can be called separately. A call to a function block instance processes the block algorithm on the private data of the instance using the specified input parameters.

ST Language

To call a function block in ST, the user has to specify the name of the instance, followed by the input parameters written between parentheses and separated by commas. To have access to an output parameter, use the name of the instance followed by a dot '.' and the name of the wished parameter. The following example demonstrates a call to an instance of CTU function block:

(* MyCounter is declared as an instance of CTU *)

MyCounter(bCU, bReset, 200); (* calls the function block *)

MaxCountReached:= MyCounter.Q;

CurrentCount := MyTimer.CV;

FBD and LD Languages

To call a function block in FBD or LD languages, the user just needs to insert the block in the diagram and to connect its inputs and outputs. The name of the instance must be specified upon the rectangle of the block.

IL Language

To call a function block in IL language, the user must use the CAL instruction, and use a declared instance of the function block. The instance name is the operand of the CAL instruction, followed by the inut parameters written between parentheses and separated by commas. Alternatively, the CALC, CALCN or CALNC conditional instructions can be used:

  • CAL: Calls the function block
  • CALC: Calls the function block if the current result is TRUE
  • CALNC: Calls the function block if the current result is FALSE
  • CALCN: same as CALNC

The following example demonstrates a call to an instance of CTU function block:

Return to the TopIEC Editors and Basic Operations

 

Calling a Sub-Program

A sub-program is called by another program. Unlike function blocks, local variables of a sub-program are not instantiated, and thus the user does not need to declare instances. A call to a sub-program processes the block algorithm using the specified input parameters. Then output parameters can be accessed.

ST Language

To call a sub-program in ST, the user have to specify its name, followed by the input parameters written between parentheses and separated by commas. To have access to an output parameter, use the name of the sub-program followed by a dot '.' and the name of the desired parameter:

MySubProg (i1, i2); (* calls the sub-program *)

Res1 := MySubProg.Q1;

Res2 := MySubProg.Q2;

Alternatively, if a sub-program has one and only one output parameter, it can be called as a function in ST language:

Res := MySubProg (i1, i2);

FBD and LD Languages

To call a sub-program in FBD or LD languages, the user just needs to insert the block in the diagram and connect its inputs and outputs.

IL Language

To call a sub-program in IL language, the user must use the CAL instruction with the name of the sub-program, followed by the input parameters written between parentheses and separated by commas. Alternatively, the CALC, CALCN or CALNC conditional instructions can be used:

  • CAL Calls the sub-program
  • CALC Calls the sub-program if the current result is TRUE
  • CALNC Calls the sub-program if the current result is FALSE
  • CALCN same as CALNC
Op1 CAL MySubProg (il,i2)
  LD MySubProg.Q1
  ST Res1
  LD MySub
  ST Res2

Return to the TopIEC Editors and Basic Operations

Syntax Coloring

The ST/IL editor supports syntax coloring according to the selected programming language (ST or IL). The editor uses different colors for the following kind of words:

 

  1. Default (identifiers, separators...)

  2. Reserved keywords of the language

  3. Constant expressions

  4. Comments

Return to the Top: IEC Editors and Basic Operations

Tooltips

The user does not need to run any specific command to open the tooltip. Just activate the editor window by clicking upon it and put the mouse on the variable symbol and wait for one second. The tooltip will show fields of the variable pointed to by the mouse cursor. However, the tooltip has to be enabled in the IEC Language Editor settings window and the specific fields need to be selected. It can be accessed from System > Logic Editing > Tooltips > Symbols Tooltip Settings.

In the Debug mode, the tooltip will show the current value in addition to all the fields shown in Editor mode.

The value shown in the tooltip is automatically refreshed while the tooltip is open.

Return to the Top: IEC Editors and Basic Operations

Jumps

JMPJMPCJMPNCJMPCN

Statement - Jump to a label.

Remarks - A jump to a label branches the execution of the program after the specified label. Labels and jumps cannot be used in structured ST language. In FBD language, a jump is represented by the ">>" symbol followed by the label name. The input of the ">>" symbol must be connected to a valid BooleanClosed Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. signal. The jump is performed only if the input is TRUE. In LD language, the ">>" symbol, followed by the target label name, is used as a coil at the end of a rung. The jump is performed only if the rung state is TRUE. In IL language, JMP, JMPC, JMPCN and JMPNC instructions are used to specify a jump. The destination label is the operand of the jump instruction.

Warning: Backward jumps may lead to infinite loops that block the target cycle.

ST Language

Not available.

FBD Language

(* In this example the TON100mS block will not be called if bEnable is TRUE *)

LD Language

(* In this example the second rung will be skipped if IN1 is TRUE *)

 

IL Language

Below is the meaning of possible jump instructions:

  • >JMP: Jump always
  • JMPC : Jump if the current result is TRUE
  • JMPNC: Jump if the current result is FALSE
  • JMPCN: Same as JMPNC

Return to the Top: IEC Editors and Basic Operations

Labels

Statement - Destination of a Jump instruction.

Remarks - Labels are used as a destination of a jump instruction in FDB, LD or IL language. Labels and jumps cannot be used in structured ST language. A label must be represented by a unique name, followed by a colon (":"). In FBD language, labels can be inserted anywhere in the diagram, and are connected to nothing. In LD language, a label must identify a rung, and is shown on the left side of the rung. In IL language, labels are destination for JMP, JMPC, JMPCN and JMPNC instructions. They must be written before the instruction at the beginning of the line, and should index the beginning of a valid IL statement: LD (load) instruction, or unconditional instructions such as CAL, JMP or RET. The label can also be written alone on a line before the indexed instruction. In all languages, it is not mandatory that a label be a target of a jump instruction. The user can also use label for marking parts of the programs in order to increase its readability.

ST Language

Not available.

FBD Language

(* In this example the TON100mS block will not be called if bEnable is TRUE *)

LD Language

(* In this example the second rung will be skipped if IN1 is TRUE *)

 

IL Language

Return to the TopIEC Editors and Basic Operations

Parentheses

Operator - force the evaluation order in a complex expression.

Remarks - Parentheses are used in ST and IL language for changing the default evaluation order of various operations within a complex expression. For instance, the default evaluation of "2 * 3 + 4" expression in ST language gives a result of 10 as "*" operator has highest priority. Changing the expression as "2 * ( 3 + 4 )" gives a result of 14. Parenthesis can be nested in a complex expression.

Below is the default evaluation order for ST language operations (1st is highest priority):

In IL language, the default order is the sequence of instructions. Each new instruction modifies the current result sequentially. In IL language, the opening parenthesis "(" is written between the instruction and its operand. The closing parenthesis ")" must be written alone as an instruction without operand.

ST Language

Q := (IN1 + (IN2 / IN 3)) * IN4;

FBD Language

Not available.

LD Language

Not available.

IL Language

Return to the Top: IEC Editors and Basic Operations

RETURN

RET RETC RETNC RETCN

Statement - Jump to the end of the program.

Remarks - The "RETURN" statement jumps to the end of the program. In FBD language, the return statement is represented by the "<RETURN>" symbol. The input of the symbol must be connected to a valid BooleanClosed Boolean- [Data Type BOOL] - A single bit, binary value, or register/variable. Boolean points have only two possible values, 'TRUE' or 'FALSE'. signal. The jump is performed only if the input is TRUE. In LD language, the "<RETURN>" symbol is used as a coil at the end of a rung. The jump is performed only if the rung state is TRUE. In IL language, RET, RETC, RETCN and RETNC instructions are used. When used within an action block of a SFC step, the RETURN statement jumps to the end of the action block.

ST Language

IF NOT bEnable THEN

RETURN;

END_IF

(* the rest of the program will not be executed if bEnabled is FALSE *)

FBD Language

(* In this example the TON100mS block will not be called if bIgnore is TRUE *)

 

IL Language

Below is the meaning of possible instructions:

  • RET: Jump to the end always
  • RETC: Jump to the end if the current result is TRUE
  • RETNC: Jump to the end if the current result is FALSE
  • RETCN: Same as RETNC

Return to the Top: IEC Editors and Basic Operations