IL (Instruction List)

From Bauman National Library
This page was last modified on 21 May 2016, at 23:46.
Instruction List
Paradigm imperative, structured
Designed by IEC
First appeared 1993
Website Instruction List

Instruction List (IL) is one of the 5 languages supported by the IEC 61131-3 standard and is designed for programmable logic controllers (PLCs). All of the languages share IEC61131 Common Elements. Instruction List is a low level language and resembles assembly. The variables and function call are defined by the common elements so different languages can be used in the same program.

Syntax

Instruction list programs are sequences of statements. A statement consist of an instruction (operator) and an operand which can either be a variable, a constant or a jump label. Additionally, programs can be augmented by comments.

Some instructions can be augmented by modifiers. There are two modifiers: N and C. The N modifier changes an operation from the original to an operation with the negated argument, i.e., negated operand value, while an instruction augmented by the C modifier is only executed under the condition that the CR value is true. The use of brackets is allowed to force the evaluation of sub-expressions first and, hence, to avoid auxiliary variables or additional load/store operations.

Basic IL commands
Instruction Description
LD loads operand
ST stores operand
S sets operand to true
R sets operand to false
NOT Boolean negation
AND Boolean AND
OR Boolean OR
XOR Boolean XOR
ADD addition
SUB subtraction
MUL multiplication
DIV integer division
GT comparison greater than
GE comparison greater equal
LT comparison less than
LE comparison less equal
EQ comparison equal
NE comparison unequal
JMP jump to label
RET return from function (block)

Data types

Data Typing is a common element of the standard with the purpose to prevent errors early on in development. It defines the type of parameters that will be used, and attempts to avoid errors like dividing a Date by an Integer. The different type of data supported are Boolean, Integer, Real, Byte, Word, Date, Time-of-Day and String. The Standard also allows users to define their own variables. These are known as derived data types. In this way an engineer would be able to define an analog input channel as a data type and re-use it over and over again.

  • Bit Strings - groups of on/off values
    • BIT - 1 bit
    • BYTE - 8 bit (1 byte)
    • WORD - 16 bit (2 byte)
    • DWORD - 32 bit (4 byte)
    • LWORD - 64 bit (8 byte)
  • INTEGER - whole numbers (Considering byte size 8 bits)
    • SINT - signed short (1 byte)
    • INT - signed integer (2 byte)
    • DINT - double integer (4 byte)
    • LINT - long integer (8 byte)
    • U - Unsigned - prefix a U to the type to make it an unsigned integer.
  • REAL - floating point IEC 60559
    • REAL - (4 byte)
    • LREAL - (8 byte)
  • TIME - duration for timers, processes.
  • Date and Time of day:
    • DATE - calendar date
    • TIME_OF_DAY - clock time
    • DATE_AND_TIME: time and date
  • STRING - character strings surrounded by single quotes. Escaped characters are preceded by a dollar sign.
    • WSTRING - holds multi-byte strings.
  • Arrays - multiple values stored in the same variable.
  • Sub Ranges - puts limits on value i.e., (4-20) for current
  • Derived - type derived from one of the above types.
    • TYPE - single type
    • STRUCT - composite of several variables and types.
  • Generic - groups of the above types:
    • ANY
      • ANY_DERIVED
      • ANY_ELEMENTARY
      • ANY_MAGNITUDE
        • ANY_NUM - LREAL, REAL
        • ANY_INT - LINT, DINT, INT, SINT, ULINT, UDINT, UINT, USINT
      • ANY_BIT - LWORD, DWORD, WORD, BYTE, BOOL
      • ANY_STRING - STRING, WSTRING
      • ANY_DATE - DATE, TOD, DT
STRING escape sequences
Escape sequence Produces
$$ $
$' '
$L linefeed
$N newline
$P page (form feed)
$R return
$T tab
$xx hex value

Variables

Variable attributes: RETAIN, CONSTANT, AT

  • Global
  • Direct (local)
  • I/O Mapping - Input, Output, I/O
  • External
  • Temporary

Configuration

At the highest level, the entire software required to solve a particular control problem can be formulated as a Configuration. A Configuration is specific to a particular type of control system, including the arrangement of the hardware, i.e. processing resources, memory addresses for I/O channels, and system capabilities.

Within a configuration one can define resources. A resource can be thought of as a processing facility that is able to execute programs. Within a resource, one or more Tasks can be defined. Tasks control the execution of a set of programs and/or function blocks. These can either be executed periodically or upon occurrence of a specified trigger.

Program organization units (POU)

  • Functions
    • Standard: ADD, SQRT, SIN, COS, GT, MIN, MAX, AND, OR, etc.
    • Custom
  • Function Blocks
    • Standard
    • Custom - Libraries of functions can be supplied by a vendor or third party.
  • Programs

Code examples

A program to put the number (4000) in a memory location, and the number (41) in another location. Divide the first one by the second and put the result in a memory location.

LD SM 0.1              
MOVD #4000 , VD200 (* Put 4000 in address VD200 *)
LD SM 0.1 
MOVW #41 , VW10    (* Put 41 in address VW10 *)
LD SM 0.1
DIV VW10 , VD200   (* DIV value in address VD200 on the value VW10 put result in the address VW200 *)

Make a program to increase the counter by one with each pulse from the pulse generator SM0.4, and decrease another counter by the same pulse.

LD SM 0.1              
MOVD #0 , VW100  (* Put 0 in address VW100 *)
MOVD #10 , VW110 (* Put 10 in address VW110 *)
LD SM 0.4        (* Pulse generator *)
EU 
INCW VW100       (* Increment VW100 *)
DECW VW100       (* Decrement VW110 *)
                              
MEND

References

  1. IEC 61131-3:2013 Programmable controllers - Part 3: Programming languages
  2. IEC 61131-3 Protocol Overview
  3. Wikipedia article
  4. Semantics and Analysis of Instruction List Programs

The article is written by Fadeev P.V.