# ZoneCmp

In document Instructions Reference Manual (Page 180-198)

Data type Relationship

TIME The numerically larger value is considered to be larger.

DATE, TOD, or DT Later dates or times of day are considered to be larger.

### The following example is for when MN is INT#10, In is INT#20 and MX is INT#30. The value of varia-ble abc will be TRUE.

abc:=ZoneCmp(INT#10, INT#20, INT#30);

LD ST

abc INT#10

INT#20 INT#30

ZoneCmp EN MN

In MX

INT#30

INT#20 Out = abc TRUE

MX

INT#10 MN

In

The instruction determines if In is between MX and MN.

The ZoneCmp instruction determines if MX ≥ In ≥ MN.

If the comparison conditions are met, the value of abc will be TRUE.

Comparison conditions met.

### When you compare TIME, DT, or TOD data, adjust the accuracy of their values so that the comparison can be based on the same accuracy. You can use the following instructions to adjust the accuracy:

TruncTime on page 2-698, TruncDt on page 2-702, and TruncTod on page 2-706.

### b) Either MX or MN contains nonnumeric data.

Comparison Instructions

ZoneCmp

### The TableCmp instruction compares the comparison data with multiple defined ranges in a compari-son table.

Instruction Name FB/

FUN Graphic expression ST expression

TableCmp Table

Compari-son FUN

(@)TableCmp

EN Out In

Table Size AryOut

Out:=TableCmp(In, Table, Size, AryOut);

### Variables

Meaning I/O Description Valid range Unit Default

In Comparison data

Input

Value to compare

Depends on

da-ta type.

---Table[] *1

(two-dimen-sional array)

Comparison table

Two-dimensional array that contains the ele-ments for the defined ranges

Size Comparison size

Number of elements in Table[] to which to compare In

1

AryOut[] (ar-ray)

Individual comparison

results array In-out

Comparison results for Table[] elements TRUE: Condition met.

FALSE: Condition not met.

Depends on

da-ta type. ---

---Out Comparison result Output

TRUE: In meets all comparison conditions for elements of Table[]

FALSE: The compari-son condition is not met for one or more sets of elements.

Depends on

da-ta type. ---

---*1. If you omit an input parameter, the default value is not applied. A building error will occur.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In OK OK OK OK OK OK OK OK OK OK

Table[] (two-dimensional array)

Must be a two-dimensional array with elements that have the same data type as In.

Size OK

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

AryOut[]

(ar-ray) OK

Out OK

### Table[] is a two-dimensional array. The first dimension contains the numbers of the defined ranges. In the second dimension, element 0 is set value A of the defined range and element 1 is set value B of the defined range.

Set value B Range 0

Range Size -1 Range 1

Set value A

Table[Size-1,0] Table[Size-1,1]

Table[1,0] Table[1,1]

Table[0,0] Table[0,1]

### Set value A and set value B define range as shown below. Set value A and set value B are always included in the range.

Set value A ≥ Set value B

Defined range

Defined range Defined

range Set value A ≤ Set value B

Set value B

Set value A Set value B Set value A

### The following example is for when In is INT#120 and Size is UINT#3.

Comparison Instructions

### 2

TableCmp

ghi:=TableCmp(INT#120, abc[1,2], UINT#3, def[3]);

LD ST

ghi INT#120

abc[1,2]

def[3] def[3]

UINT#3

TableCmp EN In Table Size AryOut

Table[0,0]=abc[1,2]

Table[1,0]=abc[2,2]

Table[2,0]=abc[3,2]

Table[0,1]=abc[1,3] AryOut[0]=def[3]

AryOut[1]=def[4]

AryOut[2]=def[5]

0 99

TRUE FALSE FALSE Table[1,1]=abc[2,3]

100 199

Table[2,1]=abc[3,3]

200 299

Out=ghi FALSE Size=UINT#3

In=INT#120

### These instructions compare the corresponding elements of two arrays.

AryCmpEQ : Determines if the corresponding elements of two arrays are equal.

AryCmpNE : Determines if the corresponding elements of two arrays are not equal.

Instruction Name FB/

FUN Graphic expression ST expression

AryCmpEQ Array

Compari-son Equal FUN

(@)AryCmpEQ EN ENO In1 Out In2

Size AryOut

AryCmpEQ(In1, In2, Size, Ary-Out);

AryCmpNE Array Compari-son Not Equal FUN

(@)AryCmpNE EN ENO In1 Out In2

Size AryOut

AryCmpNE(In1, In2, Size, AryOut);

### Variables

Meaning I/O Description Valid range Unit Default

In1[] and In2[] (ar-rays)

Comparison arrays

Input

Arrays containing the

elements to compare Depends on

da-ta type.

---*1

Size Number of comparison

elements

Number of elements to

compare 1

AryOut[] (ar-ray)

Comparison results

ar-ray In-out Comparison results

ar-ray

Depends on

da-ta type. ---

---Out Return value Output Always TRUE TRUE only ---

---*1. If you omit an input parameter, the default value is not applied. A building error will occur.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In1[] (array) OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK

In2[] (array) Must be an array with the same data type as In1[].

Size OK

AryOut[]

(ar-ray) OK

Out OK

Comparison Instructions

### 2

AryCmpEQ and AryCmpNE

### The value of AryOut[i] is as follows for each instruction:

Instruction Value of AryOut[i]

AryCmpEQ If In1[i] = In2[i], the result is TRUE. Otherwise, it is FALSE.

AryCmpNE If In1[i] ≠ In2[i], the result is TRUE. Otherwise, it is FALSE.

### The following example shows the AryCmpEQ instruction when Size is UINT#3.

AryCmpEQ(abc[1], def[2], UINT#3, ghi[3]);

LD ST

abc[1]

def[2]

ghi[3] ghi[3]

UINT#3

AryCmpEQ EN ENO In1 In2

Size AryOut

In1[0]=abc[1]

In1[1]=abc[2]

In1[2]=abc[3]

In2=INT#10 In2=INT#10 In2=INT#10

AryOut[0]=def[2]

AryOut[1]=def[3]

AryOut[2]=def[4]

Size=UINT#3

10 20 30

TRUE FALSE FALSE

### These instructions compare the corresponding elements of two arrays as below.

AryCmpLT : Performs a less than comparison.

AryCmpLE : Performs a less than or equal comparison.

AryCmpGT : Performs a greater than comparison.

AryCmpGE : Performs a greater than or equal comparison.

Instruction Name FB/

FUN Graphic expression ST expression

AryCmpLT Array Compari-son Less Than FUN

(@)AryCmpLT EN ENO In1 Out In2

Size AryOut

AryCmpLT(In1, In2, Size, AryOut);

AryCmpLE

Array Compari-son Less Than Or Equal

FUN

(@)AryCmpLE EN ENO In1 Out In2

Size AryOut

AryCmpLE(In1, In2, Size, AryOut);

AryCmpGT

Array Compari-son Greater Than

FUN

(@)AryCmpGT EN ENO In1 Out In2

Size AryOut

AryCmpGT(In1, In2, Size, AryOut);

AryCmpGE

Array Compari-son Greater Than Or Equal

FUN

(@)AryCmpGE EN ENO In1 Out In2

Size AryOut

AryCmpGE(In1, In2, Size, Ary-Out);

### Variables

Meaning I/O Description Valid range Unit Default

In1[] and In2[] (ar-rays)

Comparison arrays

Input

Arrays containing the

elements to compare Depends on

da-ta type.

---*1

Size Number of comparison

elements

Number of elements to

compare 1

AryOut[] (ar-ray)

Comparison results

ar-ray In-out Comparison results

ar-ray

Depends on

da-ta type. ---

Comparison Instructions

### 2

AryCmpLT, AryCmpLE, AryCmpGT, and AryCmpGE

Meaning I/O Description Valid range Unit Default

Out Return value Output Always TRUE TRUE only ---

---*1. If you omit an input parameter, the default value is not applied. A building error will occur.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In1[] (array) OK OK OK OK OK OK OK OK OK OK

In2[] (array) Must be an array with the same data type as In1[].

Size OK

AryOut[]

(ar-ray) OK

Out OK

### The value of AryOut[i] is as follows for each instruction:

Instruction Value of AryOut[i]

AryCmpLT If In1[i] < In2[i], the result is TRUE. Otherwise, it is FALSE.

AryCmpLE If In1[i] <= In2[i], the result is TRUE. Otherwise, it is FALSE.

AryCmpGT If In1[i] > In2[i], the result is TRUE. Otherwise, it is FALSE.

AryCmpGE If In1[i] >= In2[i], the result is TRUE. Otherwise, it is FALSE.

### The following example shows the AryCmpLT instruction when Size is UINT#3.

AryCmpLT(abc[1], def[2], UINT#3, ghi[3]);

LD ST

abc[1]

def[2]

ghi[3] ghi[3]

UINT#3

AryCmpLT EN ENO In1 In2

Size AryOut

In1[0]=abc[1]

In1[1]=abc[2]

In1[2]=abc[3]

In2[0]=def[2]

In2[1]=def[3]

In2[2]=def[4]

AryOut[0]=ghi[3]

AryOut[1]=ghi[4]

AryOut[2]=ghi[5]

Size=UINT#3

110 120 140

100 130 160

FALSE TRUE TRUE

### a) If the In1[], In2[], or AryOut[] array is smaller than the value of Size.

Comparison Instructions

### 2

AryCmpLT, AryCmpLE, AryCmpGT, and AryCmpGE

### These instructions compare each element of an array with a comparison value.

AryCmpEQV : Determines if each element of the array is equal to the comparison value.

AryCmpNEV : Determines if each element of the array is not equal to the comparison value.

Instruction Name FB/

FUN Graphic expression ST expression

AryCmpEQV

Array Value Comparison Equal

FUN

(@)AryCmpEQV EN ENO In1 Out In2

Size AryOut

AryCmpEQV(In1, In2, Size, Ary-Out);

AryCmpNEV

Array Value Comparison Not Equal

FUN

(@)AryCmpNEV EN ENO In1 Out In2

Size AryOut

AryCmpNEV(In1, In2, Size, Ary-Out);

### Variables

Meaning I/O Description Valid range Unit Default

In1[] (array) Comparison array

Input

Array containing the el-ements to compare

Depends on

da-ta type.

---*1

In2 Comparison value Value to compare

Size Number of comparison

elements

Number of elements to

compare 1

AryOut[] (ar-ray)

Comparison results

ar-ray In-out Comparison results

ar-ray

Depends on

da-ta type. ---

---Out Return value Output Always TRUE TRUE only ---

---*1. If you omit an input parameter, the default value is not applied. A building error will occur.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In1[] (array) OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK

In2 Must be same data type as the elements of In1[].

Size OK

AryOut[]

(ar-ray) OK

Out OK

### The value of AryOut[i] is as follows for each instruction:

Instruction Value of AryOut[i]

AryCmpEQV If In1[i] = In2, the result is TRUE. Otherwise, it is FALSE.

AryCmpNEV If In1[i] ≠ In2, the result is TRUE. Otherwise, it is FALSE.

### The following example shows the AryCmpEQV instruction when In2 is INT#10 and Size is UINT#3.

AryCmpEQV(abc[1], INT#10, UINT#3, def[2]);

LD ST

abc[1]

INT#10

def[2] def[2]

UINT#3

AryCmpEQV EN ENO In1

In2 Size AryOut

In1[0]=abc[1]

In1[1]=abc[2]

In1[2]=abc[3]

In2=INT#10 In2=INT#10 In2=INT#10

AryOut[0]=def[2]

AryOut[1]=def[3]

AryOut[2]=def[4]

Size=UINT#3

10 20 30

TRUE FALSE FALSE

### a) If the In1[] or AryOut[] array is smaller than the value of Size.

Comparison Instructions

### 2

AryCmpEQV and AryCmpNEV

### These instructions compare each element of an array with a comparison value as below.

AryCmpLTV : Performs a less than comparison.

AryCmpLEV : Performs a less than or equal comparison.

AryCmpGTV : Performs a greater than comparison.

AryCmpGEV : Performs a greater than or equal comparison.

Instruction Name FB/

FUN Graphic expression ST expression

AryCmpLTV

Array Value Comparison Less Than

FUN

(@)AryCmpLTV EN ENO In1 Out In2

Size AryOut

AryCmpLTV(In1, In2, Size, Ary-Out);

AryCmpLEV

Array Value Comparison Less Than Or Equal

FUN

(@)AryCmpLEV EN ENO In1 Out In2

Size AryOut

AryCmpLEV(In1, In2, Size, Ary-Out);

AryCmpGTV

Array Value Comparison Greater Than

FUN

(@)AryCmpGTV EN ENO In1 Out In2

Size AryOut

AryCmpGTV(In1, In2, Size, Ary-Out);

AryCmpGEV

Array Value Comparison Greater Than Or Equal

FUN

(@)AryCmpGEV EN ENO In1 Out In2

Size AryOut

AryCmpGEV(In1, In2, Size, Ary-Out);

### Variables

Meaning I/O Description Valid range Unit Default

In1[] (array) Comparison array

Input

Array containing the el-ements to compare

Depends on

da-ta type.

---*1

In2 Comparison value Value to compare

Size Number of comparison

elements

Number of elements to

compare 1

AryOut[] (ar-ray)

Comparison results

ar-ray In-out Comparison results

ar-ray

Depends on

da-ta type. ---

---Meaning I/O Description Valid range Unit Default

Out Return value Output Always TRUE TRUE only ---

---*1. If you omit an input parameter, the default value is not applied. A building error will occur.

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In1[] (array) OK OK OK OK OK OK OK OK OK OK

In2 Must be same data type as the elements of In1[].

Size OK

AryOut[]

(ar-ray) OK

Out OK

### The value of AryOut[i] is as follows for each instruction:

Instruction Value of AryOut[i]

AryCmpLTV If In1[i] < In2, the result is TRUE. Otherwise, it is FALSE.

AryCmpLEV If In1[i] <= In2, the result is TRUE. Otherwise, it is FALSE.

AryCmpGTV If In1[i] > In2, the result is TRUE. Otherwise, it is FALSE.

AryCmpGEV If In1[i] >= In2, the result is TRUE. Otherwise, it is FALSE.

### The following example shows the AryCmpLEV instruction when In2 is INT#20 and Size is UINT#3.

AryCmpLEV(abc[1], INT#20, UINT#3, def[2]);

LD ST

abc[1]

INT#20

def[2] def[2]

UINT#3

AryCmpLEV EN ENO In1

In2 Size AryOut

In1[0]=abc[1]

In1[1]=abc[2]

In1[2]=abc[3]

In2=INT#20 In2=INT#20 In2=INT#20

AryOut[0]=def[2]

AryOut[1]=def[3]

AryOut[2]=def[4]

Size=UINT#3

10 20 30

TRUE TRUE FALSE

### • Use the same data type for In1[] and In2. If they are different, a building error will occur.

Comparison Instructions

### 2

AryCmpLTV, AryCmpLEV, AryCmpGTV, and AryCmpGEV

### Timer Instructions

Instruction Name Page

TON On-Delay Timer page 2-136

TOF Off-Delay Timer page 2-142

TP Timer Pulse page 2-145

AccumulationTimer Accumulation Timer page 2-148

Timer Hundred-ms Timer page 2-152

### The TON instruction outputs TRUE when the set time elapses after the timer starts.

Instruction Name FB/

FUN Graphic expression ST expression

TON On-Delay Timer FB

TON In Q PT ET TON_instance

TON_instance (In, PT, Q,ET);

### Variables

Meaning I/O Description Valid range Unit Default

In Timer input

Input

TRUE: Timer start sig-nal

FALSE: Timer reset signal

Depends on

da-ta type. --- FALSE

PT Set time

Time from when timer starts until Q changes to TRUE

*1 ms 0

Q Timer output

Output

TRUE: Timer output ON

FALSE: Timer output OFF

Depends on

da-ta type.

---ET Elapsed time Elapsed time since

tim-er started *1 ms

*1. T#0 ms to T#106751d_23h_47m_16s_854.775807ms

Boo

lean Bit strings Integers

Real num-bers

Times, durations, dates, and text strings

BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING

In OK

PT OK

Q OK

ET OK

### The timer is reset when In changes to FALSE. ET changes to 0, and Q changes to FALSE.

In document Instructions Reference Manual (Page 180-198)