CMP >=: Greater or equal (S7-1200, S7-1500) - STEP 7

FBD (S7-1200, S7-1500)

ft:publication_title
FBD (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
CMP >=: Greater or equal

Description

You can use the "Greater or equal" instruction to query whether the value at input IN1 is greater or equal to the value at input IN2. Both values to be compared must be of the same data type.

If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO) "1". If the comparison condition is not fulfilled, the instruction returns RLO "0".

Comparison of character strings

The individual characters are compared by means of their code (for example, 'a' is greater than 'A') during the comparison of the strings. The comparison is performed from left to right. The first character to be different decides the result of the comparison. If the left part of the longer string is identical to the shorter string, the longer string is considered greater.

The following table shows examples of string comparisons:

IN1

IN2

RLO of the instruction

'BB'

'AA'

1

'AAA'

'AA'

1

'Hello World'

'Hello World'

1

'Hello World'

'HelloWorld'

0

'AA'

'aa'

0

'AAA'

'a'

0

You can also compare individual characters of a string. The number of the character to be compared is specified in square brackets next to the operand name. "MyString[2]", for example, compares the second character of the "MyString" string.

Note

Status still displayed despite "inactive" instruction

Under the following requirements:

  • Prior to the instruction "CMP >=: Greater or equal" (with data type STRING, WSTRING or VARIANT), a condition (e.g. of a NO contact) is queried in the network.

  • "Monitoring on" is switched on.

  • A new result of the condition resets the network to FALSE. The instruction "CMP >=: Greater or equal" will become inactive.

Result:

For the instruction "CMP >=: Greater or equal" (data type STRING, WSTRING or VARIANT), the previous status is still shown in the network.

When you switch "Monitoring on" off and on again or scroll to a different network, the correct status of the instruction "CMP >=: Greater or equal" (data type STRING, WSTRING or VARIANT) is displayed. The instruction "CMP >=: Greater or equal" is shown as grayed out in the network in the inactive status.

Comparison of timers, date and time

In comparing timer values, the RLO of the instruction is "1" if the timer at input IN1 is greater (more recent) than or equal to the timer at input IN2.

Not all times can be compared directly with each other, such as S5TIME. In this case they are implicitly converted into another time so that they can be compared, for example to TIME.

If you want to compare dates and times of different data types, the value of the smaller date or time data type is implicitly converted into the larger date or time data type. This means the two date and time data types DATE and DTL, for example, are compared on the basis of DTL.

When the implicit conversions fail, the comparison result is FALSE.

Comparing tags of WORD data type to tags of the S5TIME data type

Both tags are converted to the TIME data type when comparing a tag of WORD data type to a tag of S5TIME data type. The WORD tag is interpreted as an S5TIME value. If one of the two tags cannot be converted, the comparison is not performed and the result is FALSE. If the conversion is successful the comparison is performed based on the selected comparison instruction.

Parameters

The following table shows the parameters of the "Greater or equal" instruction:

Parameters

Declaration

Data type

Memory area

Description

IN1

Input

Bit strings, integers, floating-point numbers, character strings, timers, date and time

I, Q, M, D, L, P, or constant

First comparison value

IN2

Input

Bit strings, integers, floating-point numbers, character strings, timers, date and time

I, Q, M, D, L, P, or constant

Second value to compare

You can select the data type of the instruction from the "???" drop-down list of the instruction box.

Example

The following example shows how the instruction works:

The "TagOut" output is set when the following conditions are fulfilled:

  • The operand "TagIn_1" has the signal state "1".

  • The condition of the comparison instruction is fulfilled if "Tag_Value1" >= "Tag_Value2".