Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lessons In Industrial Instrumentation-5.pdf
Скачиваний:
11
Добавлен:
25.06.2023
Размер:
3.92 Mб
Скачать

834

CHAPTER 12. PROGRAMMABLE LOGIC CONTROLLERS

12.4.4Data comparison instructions

As we have seen with counter and timers, some PLC instructions generate digital values other than simple Boolean (on/o ) signals. Counters have current value (CV) registers and timers have elapsed time (ET) registers, both of which are typically integer number values. Many other PLC instructions are designed to receive and manipulate non-Boolean values such as these to perform useful control functions.

The IEC 61131-3 standard specifies a variety of data comparison instructions for comparing two non-Boolean values, and generating Boolean outputs. The basic comparative operations of “less than” (<), “greater than” (>), “less than or equal to” (≤), “greater than or equal to” (≥), “equal to” (=), and “not equal to” (=)6 may be found as a series of “box” instructions in the IEC standard:

 

 

EN

ENO

 

 

 

 

EN

ENO

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

EQ

 

 

 

 

 

NE

 

 

 

 

 

GT

 

 

 

IN1

Q

 

 

 

 

IN1

Q

 

 

 

 

IN1

Q

 

 

 

 

 

 

 

 

 

 

IN1 = IN2

 

 

 

 

IN1 ¹ IN2

 

 

 

 

IN1 > IN2

 

 

 

IN2

 

 

 

 

 

IN2

 

 

 

 

 

IN2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

EN

ENO

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LT

 

 

 

 

 

GE

 

 

 

 

 

LE

 

 

 

IN1

Q

 

 

 

 

IN1

Q

 

 

 

 

IN1

Q

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IN1 < IN2

 

 

 

 

IN1 ³ IN2

 

 

 

 

IN1 £ IN2

 

 

 

IN2

 

 

 

 

 

IN2

 

 

 

 

 

IN2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The Q output for each instruction “box” activates whenever the evaluated comparison function is “true” and the enable input (EN) is active. If the enable input remains active but the comparison function is false, the Q output de-activates. If the enable input de-de-activates, the Q output retains its last state.

12.4. LADDER DIAGRAM (LD) PROGRAMMING

835

A practical application for a comparative function is something called alternating motor control, where the run-times of two redundant electric motors27 are monitored, with the PLC determining which motor to turn on next based on which motor has run the least:

Real-world I/O wiring

 

 

 

 

 

 

Discrete input

Discrete output

 

 

"Start" pushbutton card

 

card

Motor "A"

 

 

 

 

 

 

 

 

 

 

IN_switch_Start OUT_motor_A

 

 

contactor coil

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

"Stop" pushbutton

 

 

Motor "B"

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

contactor coil

 

 

 

 

 

 

 

 

 

 

IN_switch_Stop

OUT_motor_B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PLC program

IN_switch_Start

A_morethan_B

IN_switch_Stop

 

 

OUT_motor_A

OUT_motor_A

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

TON

 

 

 

 

IN

Q

 

 

 

 

PT

ET

Motor_A_runtime

 

 

 

 

 

0

IN_switch_Start

A_morethan_B

IN_switch_Stop

 

 

OUT_motor_B

OUT_motor_B

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

TON

 

 

 

 

IN

Q

 

 

 

 

PT

ET

Motor_B_runtime

 

 

 

 

 

0

OUT_motor_A

OUT_motor_B

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

 

GT

A_morethan_B

 

 

 

 

 

 

 

Motor_A_runtime

IN1

Q

 

 

 

0

IN1 > IN2

 

 

 

 

 

 

 

Motor_B_runtime

IN2

 

 

 

 

0

 

 

 

In this program, two retentive on-delay timers keep track of each electric motor’s total run time, storing the run time values in two registers in the PLC’s memory: Motor A runtime and

27Perhaps two pumps performing the same pumping function, one serving as a backup to the other. Alternating motor control ensures the two motors’ run times are matched as closely as possible.

836

CHAPTER 12. PROGRAMMABLE LOGIC CONTROLLERS

Motor B runtime. These two integer values are input to the “greater than” instruction box for comparison. If motor A has run longer than motor B, motor B will be the one enabled to start up next time the “start” switch is pressed. If motor A has run less time or the same amount of time as motor B (the scenario shown by the blue-highlighted status indications), motor A will be the one enabled to start. The two series-connected virtual contacts OUT motor A and OUT motor B ensure the comparison between motor run times is not made until both motors are stopped. If the comparison were continually made, a situation might arise where both motors would start if someone happened to press the Start pushbutton with one motor is already running.

12.4. LADDER DIAGRAM (LD) PROGRAMMING

837

12.4.5Math instructions

The IEC 61131-3 standard specifies several dedicated ladder instructions for performing arithmetic calculations. Some of them are shown here:

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ADD

 

 

 

 

 

SUB

 

 

 

 

 

MOD

 

 

 

 

IN1

OUT

 

 

 

 

 

IN1

OUT

 

 

 

 

 

IN1

OUT

 

 

 

 

 

 

 

 

 

 

 

 

IN1 + IN2

 

 

 

 

 

IN1 - IN2

 

 

 

 

 

IN1 % IN2

 

 

 

 

IN2

 

 

 

 

 

 

IN2

 

 

 

 

 

 

IN2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MUL

 

 

 

 

 

 

DIV

 

 

 

 

 

EXPT

 

 

 

 

IN1

OUT

 

 

 

 

 

IN1

OUT

 

 

 

 

 

IN1

OUT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IN1 * IN2

 

 

 

 

 

IN1 ÷ IN2

 

 

 

 

 

 

IN1IN2

 

 

 

 

IN2

 

 

 

 

 

 

IN2

 

 

 

 

 

 

IN2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SIN

 

 

 

 

 

COS

 

 

 

 

 

TAN

 

 

 

 

sin (IN)

 

 

 

 

 

cos (IN)

 

 

 

 

 

 

tan (IN)

 

 

 

 

IN

OUT

 

 

 

 

 

IN

OUT

 

 

 

 

 

IN

OUT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LN

 

 

 

 

 

LOG

 

 

 

 

 

EXP

 

 

 

 

 

ln (IN)

 

 

 

 

 

 

log (IN)

 

 

 

 

 

 

eIN

 

 

 

 

IN

OUT

 

 

 

 

 

IN

OUT

 

 

 

 

 

IN

OUT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EN

ENO

 

 

 

 

 

EN

ENO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SQRT

 

 

 

 

 

ABS

 

 

 

 

 

 

 

 

 

 

 

 

IN

 

 

 

 

 

 

|IN|

 

 

 

 

 

 

 

 

 

 

 

IN

OUT

 

 

 

 

 

IN

OUT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

As with the data comparison instructions, each of these math instructions must be enabled by an “energized” signal to the enable (EN) input. Input and output values are linked to each math instruction by tag name.

838

CHAPTER 12. PROGRAMMABLE LOGIC CONTROLLERS

An example showing the use of such instructions is shown here, converting a temperature measurement in units of degrees Fahrenheit to units of degrees Celsius. In this particular case, the program inputs a temperature measurement of 138 oF and calculates the equivalent temperature of 58.89 oC:

PLC program

Always_ON

 

Always_ON

Always_ON

 

 

 

Always_ON

 

 

 

 

EN

ENO

 

 

SUB

 

IN_deg_F

IN1

OUT

X

138

IN1 - IN2

106

 

 

32

IN2

 

 

Always_ON

 

 

 

 

EN

ENO

 

 

DIV

 

X

IN1

OUT

OUT_deg_C

106

IN1

÷ IN2

58.89

 

 

1.8

IN2

 

 

Note how two separate math instructions were required to perform this simple calculation, as well as a dedicated variable (X) used to store the intermediate calculation between the subtraction and the division “boxes.”

Although not specified in the IEC 61131-3 standard, many programmable logic controllers support Ladder Diagram math instructions allowing the direct entry of arbitrary equations. Rockwell

12.4. LADDER DIAGRAM (LD) PROGRAMMING

839

(Allen-Bradley) Logix5000 programming, for example, has the “Compute” (CPT) function, which allows any typed expression to be computed in a single instruction as opposed to using several dedicated math instructions such as “Add,” “Subtract,” etc. General-purpose math instructions dramatically shorten the length of a ladder program compared to the use of dedicated math instructions for any applications requiring non-trivial calculations.

For example, the same Fahrenheit-to-Celsius temperature conversion program implemented in Logix5000 programming only requires a single math instruction and no declarations of intermediate variables:

Rockwell Logix5000 PLC program

Always_ON

Always_ON

Always_ON

 

Always_ON

 

Compute

 

Dest

OUT_deg_C

 

58.89

Expression

(IN_deg_F - 32)/1.8