1. compare CMP/CMPD/CMPF

ในหน้านี้6 หัวข้อ

1.1. Instruction description#

Compare the sizes of IN1 and IN2, and output the comparison result to OUT and the following two bits.

Assuming IN1=D0, IN2=D2, OUT=Y000.

The value of IN1 the value of IN2 the current comparison result the output of Y000 the output of Y001 the output of Y002
150 100 D0>D2 ON OFF OFF
100 100 D0==D2 OFF ON OFF
50 100 D0<D2 OFF OFF ON

1.2. The valid operands of the instruction#

1.2.1. Single Character Type (CMP):#

Input/Output Data Type operand Description
IN1 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) Input 1
IN2 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) Input 2
OUT ON/OFF Y/M/S, word positioning (D/V/Z) Result

1.2.2. Double Character Type (CMPD):#

Input/Output Data Type operand Description
IN1 32-bit integer D/CV/K/H/FD, bit composite word (X/Y/M/C/T/S), local variable (LD) Input 1
IN2 32-bit integer D/CV/K/H/FD, bit composite word (X/Y/M/C/T/S), local variable (LD) Input 2
OUT ON/OFF Y/M/S, word positioning (D/V/Z) Result

1.2.3. Floating point type (CMPF):#

Input/Output Data Type operand Description
IN1 32-bit real number D/K/FD, local variable (LF) Input 1
IN2 32-bit real number D/K/FD, local variable (LF) Input 2
OUT ON/OFF Y/M/S, word positioning (D/V/Z) Result

1.3. Example#

Command table:

NETWORK 000

LD M0

CMP D0 D1 M100 // compare DO and D1 ,which one is greater.

POP

LD M100

OUT M1000 // if D0 > D1, M100= ON

POP

LD M101

OUT M1001 // if D0 == D1, M101= ON

POP

LD M102

OUT M1002 // if D0 < D1, M102= ON

POP

CMP

图1 CMP

อุปกรณ์ที่ใช้กับคู่มือนี้
2 รายการ
FAT-16MT-DC-E
FAT-16MT-DC-E

PLC 16 I/O 24V DC Transistor Output รองรับ Modbus RTU/RS485 TCP/IP

฿2,590

FAs-32MR-AC-E
FAs-32MR-AC-E

PLC 32 I/O 220V AC Relay Output รองรับ Modbus RTU/RS485 TCP/IP

฿3,690