Comparison and Math Operations in Programmable Logic Controllers by Dr. D. J. Jackson, Slides of Programmable Logic Controllers

An overview of comparison and math instructions in programmable logic controllers (plcs). It covers various comparison instructions such as equal (equ), not equal (neq), less than (les), less than or equal (leq), greater than (grt), greater than or equal (geq), masked comparison for equal (meq), and limit test (lim). The document also explains the use and logic of each instruction, as well as the role of source and destination addresses. Additionally, it discusses the arithmetic status bits and their updates after an instruction is executed.

Typology: Slides

2011/2012

Uploaded on 03/02/2012

cristelle
cristelle 🇺🇸

4.5

(53)

374 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
7-1
Programmable Logic
Controllers
Comparison and Math Operations
Dr. D. J. Jackson Lecture 7-1Electrical & Computer Engineering
Comparison Instructions
Instruction Purpose
Mnemonic Name
E
QU
E
qua
l
Tes t
wh
et
h
e
r
t
w
o
v
a
l
ues
a
r
e
equa
l
QU
qua
est et e t o a ues a e equa
NEQ Not Equal Test whether one value is not equal to a second
value
LES Less Than Test whether one value is less than a second
value
LEQ Less Than
or Equal Test whether one value is less than or equal to a
second value
GRT Greater Than Test whether one value is greater than another
Dr. D. J. Jackson Lecture 7-2Electrical & Computer Engineering
GEQ Greater Than or
Equal
T
est whether one value is greater
than or equal to a second value
MEQ Masked Comparison
for Equal Test portions of two values to see whether they
are equal. Compares data through a mask
LIM Limit Test Test whether one value is within the limit range
of two other values
pf3
pf4
pf5

Partial preview of the text

Download Comparison and Math Operations in Programmable Logic Controllers by Dr. D. J. Jackson and more Slides Programmable Logic Controllers in PDF only on Docsity!

Programmable Logic

Controllers

Comparison and Math Operations

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

Comparison Instructions

Instruction Purpose Mnemonic Name EQUQU Equalqua Test whether two values are equalest et e t o a ues a e equa NEQ Not Equal Test whether one value is not equal to a second value LES Less Than Test whether one value is less than a second value LEQ Less Than or Equal

Test whether one value is less than or equal to a second value GRT Greater Than Test whether one value is greater than another

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

GEQ Greater Than or Equal

Test whether one value is greater than or equal to a second value MEQ Masked Comparison for Equal

Test portions of two values to see whether they are equal. Compares data through a mask LIM Limit Test Test whether one value is within the limit range of two other values

About the Comparison Instructions

• Comparison instructions are used to test

pairs of values to condition the logical

continuity of a rungf

– Thus, comparison instructions would seldom, if

ever, be the last instruction on a rung

• As an example, suppose a LES instruction is

presented with two values

If the fi st al e is less than the second then the

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

– If the first value is less than the second, then the

comparison instruction is true

Equal (EQU) & Not Equal (NEQ)

  • Use the EQU instruction to test whether two values are equal. - If source A and source B are equal, the instruction is logicallyq , g y true. If these values are not equal, the instruction is logically false.
  • Use the NEQ instruction to test whether two values are not equal. - If source A and source B are not equal, the instruction is logically true. S A b dd

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

  • Source A must be an address. Source B can be either a program constant or an address.
  • Negative integers are stored in two’s complementary form.

Masked Comparison for Equal (MEQ)

  • Use the MEQ instruction to compare data at a source address with data at a compare address.
  • Source is the address of the value you want to compare.
  • Mask is the address of the mask through which the instruction moves data

p

  • Use of this instruction allows portions of the data to be masked by a separate word.

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

  • The mask can be a hexadecimal value.
  • Compare is an integer value or the address of the reference.
  • If the 16 bits of data at the source address are equal to the 16 bits of data at the compare address (less masked bits), the instruction is true.
  • The instruction becomes false as soon as it detects a mismatch.

Limit Test (LIM)

  • Use the LIM instruction to

test for values within or

outside a specified range,

depending on how you setp^ g^ y

the limits.

  • The Low Limit, Test, and

High Limit values can be

word addresses or constants,

restricted to the following

combinations:

  • If the Test parameter is a program constant, both the Low Limit and High Limit t t b d

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

parameters must be word addresses.

  • If the Test parameter is a word address, the Low Limit and High Limit parameters can be either a program constant or a word address.

True/False Status of the LIM

Instruction

  • If the Low Limit has a value equal to or less than the High Limit, the instruction is true when the Test value is between the limits or is equal to either limitvalue is between the limits or is equal to either limit.

Example, low limit less than high limit:

False True False

Low Limit High Limit

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

Low Limit High Limit Instruction is True when Test value is

Instruction is False when Test value is 5 8 5 through 8 -32768 through 4 and 9 through 32767

True/False Status of the LIM

Instruction (continued)

  • If the Low Limit has a value greater than the High Limit, the instruction is false when the Test value is between the limitsbetween the limits.

Example, high limit less than low limit:

True False True

High Limit Low Limit

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

Low Limit High Limit Instruction is True when Test value is

Instruction is False when Test value is 8 5 -32768 through 5 and 8 through 32767

6 through 7

Updates to Arithmetic Status Bits

• The arithmetic status bits are found in Word 0, bits

0–3 in the controller status file.

• After an instruction is executed, the arithmetic statusAfter an instruction is executed the arithmetic status

bits in the status file are updated:

With this bit: The Controller:

S:0/0 Carry (C) sets if carry is generated; otherwise cleared

S:0/1 Overflow (V) indicates that the actual result of a math instruction does not fit in the designated d ti ti

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 7-

destination

S:0/2 Zero (Z) indicates a 0 value after a math, move, or logic instruction S:0/3 Sign (S) indicates a negative (less than 0) value after a math, move, or logic instruction