Вы находитесь на странице: 1из 26

Logic Developer - PC

IL Editor: an Overview
Accumulator | Accumulator Stack | Nested Operations | Comments | IL Logic Examples

The Instruction List (IL) editor is an intelligent, free-form text editor for editing Instruction List
logic. You can configure the IL editor as to the format and color coding of the IL logic you create,
as well as the behavior of the editor itself. Default indentation rules can be applied while editing or
you can beautify an entire block with a single command. Contextual smart list support is provided
for almost every entry you make, allowing you to choose from a list, labels, variables and
instructions when they are expected.
There two basic methods for entering IL logic:

Right-click, choose Insert, then choose Variable or Keyword. A smart list appears
prompting you to choose a valid item, or create a new item.
Start typing and a smart list will appear listing your valid choices depending on where you
are typing (Quick-edit method).

The IL editor supports cut, copy and paste using the Windows Clipboard, allowing you to interact
with other text-based editors such as Notepad. You can drag and drop between the IL editor and
other Machine Edition tools, such as the Toolchest and the Variable list.
Few restrictions are placed on the way you work in the IL editor. The editor allows the entry of
undefined operands so you can type references to labels or variables that don't yet exist. Any
unresolved references are detected upon validation and easily located and corrected.

About Instruction List Logic


Instruction List (IL) logic is one of five programming languages specified by the IEC 61131-3
standard. In its simplest form an IL program will:
1. Load a data value into the accumulator.
2. Perform an operation on the accumulator, saving the result in the accumulator.
3. Store the accumulator's value to memory (a variable).
4. Do another accumulator load or operation, etc.
The accumulator and the operand must always be the same data type.
There is one accumulator and one accumulator stack that is used by the IL editor for each target.
The data types of these two accumulators can be BOOL, DINT or LREAL, depending upon the data
type of the variable, constant or operation result being loaded into it. For example, if the result of
an operation is LREAL, the accumulator becomes LREAL. The accumulator stack may also become
LREAL if it is used during the operation. If the result of the next operation is BOOL, the result is
loaded to the accumulator and the accumulator becomes BOOL. The data value that was
previously in the accumulator and/or the accumulator stack are permanently lost.
The table below shows the two possible register types:

Register type
Accumulator

Number of Register
types
1

Accumulator stack 1

Data types
BOOL, DINT,
LREAL
BOOL, DINT,
LREAL

Maximum number of data


values per Register type
1
10

The Accumulator
IL logic is accumulator based, much like the assembler languages used for programming
microprocessors. When IL logic is executed by a PC, a single accumulator is used as a working
register. The accumulator is common to all IL blocks for each target with an IL block logic
component in it.
The accumulator can be of data type BOOL, DINT or LREAL, depending upon the data type of the
value loaded into it. For example, if the result of the current operation is BOOL, the accumulator
will be BOOL.
Most IL instructions operate on the contents of the accumulator and the accumulator stack. The
content of the accumulator is retained until modified by an operation, until the data type changes
(for example, DINT to LREAL), or the IL block has completed execution.
The accumulator can only contain a single data value.
Please refer to the IL logic examples below.
Note: The accumulator and the operand must always be the same data type.

The Accumulator Stack


Because of nested operations in IL logic, accumulator stacks are required to store intermediate
data values.
Nested operations are always inside brackets '( )'. Each time a nested operation is encountered
(or a left '(' bracket), the content of the accumulator is pushed onto the accumulator stack. Each
time the end of a nested operation is encountered (or a right ')' bracket), the latest data value is
popped from the accumulator stack and loaded to the accumulator.
One accumulator stack is defined for each PC target in your project. The accumulator stack can be
of data type BOOL, DINT or LREAL, depending upon the data type of the value being loaded into
it. For example, if the result of the operation is DINT, the accumulator stack will be DINT.
Most IL instructions operate on the contents of the accumulator and the accumulator stack. The
accumulator stack stores intermediate data values during operations, and can contain a maximum
of ten data values.
Loading a data value into the accumulator stack is referred to as pushing a value onto the
accumulator stack. Retrieving a data value from the accumulator stack is referred to as popping
a value from the accumulator stack . This cannot be done manually; the IL editor automatically

pushes/pops values onto/from the accumulator stack.


IL logic can only immediately access the last or latest value loaded to the accumulator stack. After
popping a value from the accumulator stack, the next value becomes available for retrieval, if one
exists, and so on. The data values in the accumulator stack are:

Automatically received from the accumulator, since the accumulator can only contain one
data value.
The same data type as the accumulator.
Never directly used as part of an operation.
The content of the accumulator stack is retained until modified by an operation, until the
data type changes (for example, DINT to LREAL), or the IL block has completed execution.

Please refer to the IL logic examples below.

Nested Operations
IL syntax allows for nested operations using the ADD, AND, ANDN, NOT, OR, ORN, XOR, XORN,
SUB, MUL, DIV, MOD, GT, GE, EQ, NE, LT, LE, LD and ST execution instructions where the
expected operand is an operation resulting in a BOOL, DINT or LREAL value.
A maximum of ten levels of nesting are supported.
No control instructions may be placed within nested operations.
Note: The accumulator and the result of the operand (which may be a nested operation) must always be of the same data
type; that is, BOOL, DINT or LREAL.

Please refer to the IL logic examples below.

Comments
It is good practice to document your IL logic with detailed comments to aid yourself and others in
understanding the code. The IL editor provides two types of comments:

Block comments are contained between (* and *). Any text that appears between these
delimiters will be ignored by the compiler. Block comments can span one or more lines. For
example,

Inline comments are prefixed by ' and terminated by a line break. For example.

IL Logic Examples
Please refer to the four IL logic examples below for examples of valid and invalid IL logic, nested
operations, use of the accumulator, the accumulator stack and comments.

Refer to the table below to see the data values of the accumulator and the accumulator stack.

Line Accumulator

Accumulator stack

BOOLA

NULL

BOOLB

BOOLA

BOOLB OR BOOLC

BOOLA

BOOLB OR BOOLC AND BOOLB

BOOLA

BOOLD

BOOLB OR BOOLC AND BOOLB


BOOLA

BOOLD OR BOOLE

BOOLB OR BOOLC AND BOOLB


BOOLA

BOOLD OR BOOLE

BOOLB OR BOOLC AND BOOLB


BOOLA

BOOLD OR BOOLE ANDN BOOLF

BOOLB OR BOOLC AND BOOLB


BOOLA

(BOOLB OR BOOLC AND BOOLB) OR (BOOLD OR BOOLE


ANDN BOOLF)

BOOLA

10

(BOOLB OR BOOLC AND BOOLB) OR (BOOLD OR BOOLE


ANDN BOOLF) AND BOOLF

BOOLA

11

(BOOLB OR BOOLC AND BOOLB) OR (BOOLD OR BOOLE


ANDN BOOLF) AND BOOLF OR BOOLG

BOOLA

12

BOOLA AND (BOOLB OR BOOLC AND BOOLB) OR (BOOLD


OR BOOLE ANDN BOOLF) AND BOOLF OR BOOLG

BOOLA

13

BOOLA AND (BOOLB OR BOOLC AND BOOLB) OR (BOOLD


OR BOOLE ANDN BOOLF) AND BOOLF OR BOOLG

NULL

Refer to the table below to see the data values of the accumulator and the accumulator stack.
Line

Accumulator

Accumulator stack

NULL

(A + B)

(A + B) * C

NULL

(A + B) * C

A
(A + B) * C

B
A
(A + B) * C

(D * C)

B
A
(A + B) * C

(D * C) + B

A
(A + B) * C

10

A - ((D * C) + B)

(A + B) * C

11

((A + B) * C) + (A - ((D * C) + B))

NULL

12

((A + B) * C) + (A - ((D * C) + B))

NULL

Note: In IL logic, there is no operator precedence. Each operator is executed as it occurs, unless a nested operation is
encountered, in which case the innermost nested operation is executed first.

Advanced Math Instructions (IL)


These IL instructions perform trigonometric, exponential and logarithmic
operations on data and can only be performed on DINT or LREAL operands.
Expressions or BOOL variables are not allowed as operands for any of these.
For further information, consult the Advanced Math Instructions help. The
functionality, operands, and CPU support for LD functions is the same as for
IL instructions.
Absolute Value

ABS

Square Root

SQRT

Cosine

COS

Sine

SIN

Tangent

TAN

Arc Cosine

ACOS

Arc Sine

ASIN

Arc Tangent

ATAN

Arc Tangent (Operand1 / Operand2)

ATAN2

Hyperbolic Cosine

COSH

Hyperbolic Sine

SINH

Hyperbolic Tangent

TANH

Degrees to Radians

DTOR

Radians to Degrees

RTOD

Log

LOG

Natural Log

LN

Natural Exponent

EXP

Exponent (operand1 operand2)

EXPT

PC IL Instructions

Basic Instructions (IL)


Accumulator | Coil | BOOL | Math | Relational | Program Flow

Most of the basic IL instructions support operations on BOOL, DINT and/or


LREAL variables. These instructions generally operate on the accumulator's
content to generate a new value for the same accumulator. Nested
expressions are allowed for the BOOL, Relational and Math instruction groups
and the ST instruction.

Accumulator Instructions (IL)


Mnemonic Description
LD
Load a value in the accumulator. Operand can be a BOOL, DINT,
LREAL variable, expression or constant.
LDN
Load the inverse of a value in the accumulator. Operand can be a
BOOL, DINT, LREAL variable, expression or constant.
ST
Store the accumulator content in a variable. Operand can be a
BOOL, DINT, LREAL variable, expression or constant.
STN
Store the inverse of the accumulator content in a variable.
Operand can be a BOOL, DINT, LREAL variable, expression or
constant.

Coil Instructions (IL)


Mnemonic Description
S
Set the Set Coil variable to ON (1). Operand can only be a BOOL
variable or constant.
R
Set the Reset Coil variable to OFF (0). Operand can only be a
BOOL variable or constant.

BOOL Instructions (IL)


Mnemonic Description
NOT
Change the state of the accumulator and store the result in the
accumulator. No operand is allowed for the NOT instruction. This
instruction is only valid when the accumulator contains a BOOL
value.
AND
Perform a logical AND between the operand and the
accumulator. Operand can be a BOOL variable, expression or
constant.
ANDN
Perform a logical AND between the accumulator and the inverse
of the operand. Operand can be a BOOL variable, expression or
constant.
OR
Perform a logical OR between the operand and the accumulator.
Operand can be a BOOL variable, expression or constant.
ORN
Perform a logical OR between the accumulator and the inverse of
the operand. Operand can be a BOOL variable, expression or
constant.
XOR
Perform a logical XOR between the operand and the accumulator.
Operand can be a BOOL variable, expression or constant.
XORN
Perform a logical XOR between the accumulator and the inverse
of the operand. Operand can be a BOOL variable, expression or
constant.
Note: The accumulator and the operand must always be the same data type.

Math Instructions (IL)


Mnemonic Description
ADD
Add the accumulator content to the operand. Operand can be a
DINT, LREAL variable, expression or constant.
SUB
Subtract the operand from the accumulator content. Operand can
be a DINT, LREAL variable, expression or constant.
MUL
Multiply the accumulator content and the operand. Operand can
be a DINT, LREAL variable, expression or constant.

DIV

Divide the accumulator content by the operand. Operand can be a


DINT, LREAL variable, expression or constant.
Note: #Overflow is set to ON (1) on division by zero.

MOD

Divide the accumulator content by the operand and store the


remainder in the accumulator. Operand can be only be a DINT
variable, expression or constant.

Note: The accumulator and the operand must always be the same data type.

Relational Instructions (IL)


Mnemonic Description
GT
If the numerical value in the accumulator is greater than the
numerical value in the operand, load 1 into the accumulator. If
the numerical value in the accumulator is less than or equal to
the numerical value in the operand, load 0 into the accumulator.
Operand can be a DINT, LREAL variable, expression or constant.
GE
If the numerical value in the accumulator is greater than or equal
to the numerical value in the operand, load 1 into the
accumulator. If the numerical value in the accumulator is less
than the numerical value in the operand, load 0 into the
accumulator. Operand can be a DINT, LREAL variable, expression
or constant.
EQ
If the numerical value in the accumulator is exactly equal to the
numerical value in the operand, load 1 into the accumulator. If
the numerical value in the accumulator is not exactly equal to the
numerical value in the operand, load 0 into the accumulator.
Operand can be a BOOL, DINT, LREAL variable, expression or
constant.
NE
If the numerical value in the accumulator is not exactly equal to
the numerical value in the operand, load 1 into the accumulator.
If the numerical value in the accumulator is exactly equal to the
numerical value in the operand, load 0 into the accumulator.
Operand can be a BOOL, DINT, LREAL variable, expression or
constant.

LE

LT

If the numerical value in the accumulator is less than or equal to


the numerical value in the operand, load 1 into the accumulator.
If the numerical value in the accumulator is greater than the
numerical value in the operand, load 0 into the accumulator.
Operand can be a DINT, LREAL variable, expression or constant.
If the numerical value in the accumulator is less than the
numerical value in the operand, load 1 into the accumulator. If
the numerical value in the accumulator is greater than or equal to
the numerical value in the operand, load 0 into the accumulator.
Operand can be a DINT, LREAL variable, expression or constant.

Note: The accumulator and the operand must always be the same data type.

Program Flow Instructions (IL)


Mnemonic Description
JMP
Unconditional transfer of execution to a label within the current
block.
JMPC
Conditional transfer of execution to a label within the current
block if the accumulator contains a value of 1 or TRUE, otherwise
execution continues at the instruction following JMPC.
JMPCN Conditional transfer of execution to a label within the current
block if the accumulator contains a value of 0, otherwise
execution continues at the instruction following JMPCN.

PC IL Instructions Advanced Math

Absolute Value Instruction (IL)


ABS operand
accumulator

ABS (operand)

Store the unsigned magnitude of the operand in the accumulator.


Operand: DINT, LREAL variable or constant.
Example:
LD 1.0 'load accumulator; accumulator becomes LREAL
ABS -3.5 'store the unsigned magnitude of -3.5 in the accumulator
For more details, see ABS (LD).
Notes

The result of this instruction can be DINT or LREAL; therefore, the accumulator may be
DINT or LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Logarithmic Instructions (IL)


ln | LOG

ln operand
accumulator

ln(operand)

Calculate the natural (base e) logarithm of the operand and store the result
in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see ln (LD).
Notes

Taking the ln of zero is invalid.


The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
If the operand is too large, the result will be zero.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

LOG operand
accumulator

LOG(operand)

Calculate the base 10 logarithm of the operand and store the result in the
accumulator.
operand: DINT, LREAL variable or constant.
For more details, see LOG (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
If the operand is too large, the result will be zero.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Angle Conversion Instructions (IL)


DTOR | RTOD

DTOR operand
accumulator

DTOR (operand)

Convert the operand (angle in degrees) to radians and store the result in the
accumulator (angle in radians).
Operand: DINT, LREAL variable or constant.
For more details, see DTOR (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.

RTOD operand
accumulator

RTOD (operand)

Convert the operand (angle in radians) to degrees and store the result in the
accumulator (angle in degrees).
Operand: DINT, LREAL variable or constant.
For more details, see RTOD (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.

IL and LD functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Exponential Instructions (IL)


EXP | EXPT

EXP operand
accumulator

eoperand

Calculate the natural exponent of e and store the result in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see EXP (LD).
Notes

If the operand is too large, the result will be zero.


The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

EXPT operand
accumulator

EXPT(accumulatoroperand)

Calculate the base (content of the accumulator) to the power of the operand
and store the result in the accumulator.
operand: DINT, LREAL variable or constant.
Example:
LD 2.0 'load accumulator; accumulator becomes LREAL
EXPT 3.5 'calculate 2.03.5 and store the result in the accumulator

For more details, see EXPT (LD).


Notes

If the operand is too large, the result will be zero.


IL and LD functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Hyperbolic Instructions (IL)


COSH | SINH | TANH

COSH operand
accumulator

COSH(operand)

Calculate the hyperbolic cosine of the operand (in radians) and store the
result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see COSH (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

SINH operand
accumulator

SINH(operand)

Calculate the hyperbolic sine of the operand (in radians) and store the result
in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see SINH (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

TANH operand
accumulator

TANH(operand)

Calculate the hyperbolic tangent of the operand (in radians) and store the
result in the accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see TANH (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and LD functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Inverse Trigonometric Instructions (IL)


ACOS | ASIN | ATAN | ATAN2

ACOS operand
accumulator

ACOS(operand)

Calculate the inverse cosine of the operand (in radians) and store the result
in the accumulator.
The operand must be in the range -1 to +1.
The angle is returned in radians, in the range 0 to pi.
Operand: DINT, LREAL variable or constant where (-1

operand

1).

For more details, see ACOS (LD).


Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
An operand outside of the range (-1

operand

1) causes the result to be zero.

IL and Ladder functions are generally the same, with some differences in data types for
operands.

ASIN operand
accumulator

ASIN(operand)

Calculate the inverse sine of the operand (in radians) and store the result in
the accumulator.
The operand must be in the range -1 to +1.
The angle is returned in radians, in the range -pi/2 to +pi/2.

Operand: DINT, LREAL variable or constant where (-1

operand

1).

For more details, see ASIN (LD).


Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
An operand outside of the range (-1

operand

1) causes the result to be zero.

IL and Ladder functions are generally the same, with some differences in data types for
operands.

ATAN operand
accumulator

ATAN(operand)

Calculate the inverse tangent of the operand (in radians) and store the result
in the accumulator.
The angle is returned in radians, in the range -pi/2 to +pi/2.
Operand: DINT, LREAL variable or constant.
For more details, see ATAN (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

ATAN2 operand
accumulator

ATAN2(operand/accumulator)

Calculate the inverse tangent of (operand/accumulator) and store the result


in the accumulator.
The angle is returned in radians, in the range -pi to +pi.
operand: DINT, LREAL variable or constant.
Example:
LD 2 'load accumulator; accumulator becomes DINT
ATAN2 3 'calculate ATAN2 (3/2) and store the result in the accumulator;
accumulator becomes LREAL
ST myLREAL ' store the result of the calculation in the LREAL variable
myLREAL
For more details, see ATAN2 (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.

If the operand is zero, the result will be zero.

If the accumulator is zero, the result will NOT be correct.

IL and Ladder functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Trigonometric Instructions (IL)


COS | SIN | TAN

COS operand
accumulator

COS(operand)

Calculate the cosine of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see COS (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

SIN operand
accumulator

SIN(operand)

Calculate the sine of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see SIN (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be

LREAL.

IL and Ladder functions are generally the same, with some differences in data types for
operands.

TAN operand
accumulator

TAN(operand)

Calculate the tangent of the operand and store the result in the accumulator.
The angle is returned in radians.
Operand: DINT, LREAL variable or constant.
For more details, see TAN (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

PC IL Instructions Advanced Math

Square Root Instruction (IL)


SQRT operand
accumulator

operand

Calculate the square root of the operand and store the result in the
accumulator.
Operand: DINT, LREAL variable or constant.
For more details, see SQRT (LD).
Notes

The result of this instruction is always LREAL; therefore, the accumulator will always be
LREAL.
A negative operand causes the result to be zero.
IL and Ladder functions are generally the same, with some differences in data types for
operands.

Вам также может понравиться