• 沒有找到結果。

ZoneCmp

在文檔中 Instructions Reference Manual (頁 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.

Additional Information

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.

Precautions for Correct Use

• If the data types of In, MX, and MN are different, they will be cast to a data type which can accom-modate every possible value in all the types before comparison.

• If In, MX, and MN are real numbers and include any non-terminating decimal numbers, error may cause unexpected processing results.

• Signed integers (SINT, INT, DINT, and LINT) cannot be compared to unsigned integers (USINT, UINT, UDINT, and ULINT).

• Always compare data with the same data type for TIME, DATE, TOD, and DT data. If variables with different data types are specified, a building error will occur.

• Two values that are positive infinity or two values that are negative infinity are equivalent.

• If the value of In is nonnumeric data, the value of Out is FALSE.

• If this instruction is used in a ladder diagram, the value of Out changes to FALSE when an error occurs in the previous instruction on the rung.

• An error occurs in the following cases. Out will be FALSE.

a) The value of MN is greater than the value of MX.

b) Either MX or MN contains nonnumeric data.

Comparison Instructions

2

ZoneCmp

TableCmp

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

Function

The TableCmp instruction compares comparison data In with the number of defined ranges specified by the value of Size in comparison table Table[].

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 results of comparing In and Table[] are stored in individual comparison results array AryOut[]. If In is within the defined range for element i, AryOut[i] will be TRUE. If it is not within the range, AryOut[i]

will be FALSE. If all Size elements of AryOut[] are TRUE, comparison result Out will be TRUE. Other-wise, it will be FALSE.

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

Precautions for Correct Use

• Use the same data type for In and Table[]. Otherwise, a building error will occur.

• Use a two-dimensional array for Table[].

• If an array with more than two dimensions is used for Table[], the elements in the third and higher dimensions are ignored.

• If the AryOut[] array is larger than the value of Size, the comparison results will be stored in Ary-Out[0] to AryOut[Size-1]. Other elements of the array will not change.

• Signed integers (SINT, INT, DINT, and LINT) cannot be compared to unsigned integers (USINT, UINT, UDINT, and ULINT).

• If real numbers are compared, error may cause unexpected processing results. This can occur, for example, when they contain non-terminating decimal numbers.

• If the value of Size is 0, the value of Out will be FALSE and AryOut[] will not change.

• If this instruction is used in a ladder diagram, the value of Out changes to FALSE if an error occurs in the previous instruction on the rung.

• An error occurs in the following cases. Out will be FALSE.

a) If the value of Size exceeds the size of the AryOut[] array.

b) If the value of Size exceeds the size of the first dimension of the Table[] array.

c) The size of the second dimension of Table[] is 1.

AryCmpEQ and AryCmpNE

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

Function

These instructions compare the values of the elements with the same element numbers in two arrays (In1[0] to In1[Size-1] and In2[0] and In2[Size-1]). The comparison results are stored in comparison re-sults array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to Ary-Out[Size-1]).

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

Precautions for Correct Use

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

• Use an AryOut[] array that is at least as large as the value of Size.

• If In1[] and In2[] contain real numbers, error may cause unexpected processing results. This can oc-cur, for example, when they contain non-terminating decimal numbers.

• If the value of Size is 0, the value of Out will be TRUE and AryOut[] will not change.

• Return value Out is not used when the instruction is used in ST.

• An error occurs in the following case. ENO will be FALSE, and AryOut[] will not change.

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

AryCmpLT, AryCmpLE, Ar-yCmpGT, and AryCmpGE

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

Function

These instructions compare the values of the elements with the same element numbers in two arrays (In1[0] to In1[Size-1] and In2[0] and In2[Size-1]). The comparison results are stored in comparison re-sults array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to Ary-Out[Size-1]).

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

Precautions for Correct Use

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

• Use an AryOut[] array that is at least as large as the value of Size.

• If In1[] and In2[] contain real numbers, error may cause unexpected processing results. This can oc-cur, for example, when they contain non-terminating decimal numbers.

• If the value of Size is 0, the value of Out will be TRUE and AryOut[] will not change.

• Return value Out is not used when the instruction is used in ST.

• An error occurs in the following case. ENO will be FALSE, and AryOut[] will not change.

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

Comparison Instructions

2

AryCmpLT, AryCmpLE, AryCmpGT, and AryCmpGE

AryCmpEQV and AryCmpNEV

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

Function

These instructions compare comparison value In2 with the specified elements in an array (In1[0] to In1[Size-1]).

The comparison results are stored in comparison results array AryOut[] in the elements with the corre-sponding element numbers (AryOut[0] to AryOut[Size-1]).

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

Precautions for Correct Use

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

• Use an AryOut[] array that is at least as large as the value of Size.

• If In1[] contains real numbers and In2 is a real number, error may cause unexpected processing re-sults. This can occur, for example, when they contain non-terminating decimal numbers.

• If the value of Size is 0, the value of Out will be TRUE and AryOut[] will not change.

• Return value Out is not used when the instruction is used in ST.

• An error occurs in the following case. ENO will be FALSE, and AryOut[] will not change.

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

Comparison Instructions

2

AryCmpEQV and AryCmpNEV

AryCmpLTV, AryCmpLEV, Ar-yCmpGTV, and AryCmpGEV

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

Function

These instructions compare comparison value In2 with the specified elements in an array (In1[0] to In1[Size-1]).

The comparison results are stored in comparison results array AryOut[] in the elements with the corre-sponding element numbers (AryOut[0] to AryOut[Size-1]).

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

Precautions for Correct Use

• 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

• Use an AryOut[] array that is at least as large as the value of Size.

• If In1[] contains real numbers and In2 is a real number, error may cause unexpected processing re-sults. This can occur, for example, when they contain non-terminating decimal numbers.

• If the value of Size is 0, the value of Out will be TRUE and AryOut[] will not change.

• Return value Out is not used when the instruction is used in ST.

• An error occurs in the following case. ENO will be FALSE, and AryOut[] will not change.

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

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

2

TON

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

Function

The TON instruction outputs TRUE when the set time elapses after the timer starts. The time is set in nanoseconds.

The timer starts when timer input In changes to TRUE. Elapsed time ET is incremented as time elap-ses.

When ET reaches set time PT, timer output Q changes to TRUE. ET is not incremented after that.

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

在文檔中 Instructions Reference Manual (頁 180-198)