This instruction is used to compare the contents of two tags of the “Timers” or “Date and time” data type in SIemens TIA Portal and PLC S7-1500.
The instruction supports the comparison of the following data types: DATE, TIME, LTIME, TOD (TIME_OF_DAY), LTOD (LTIME_OF_DAY), DT (DATE_AND_TIME), LDT (DATE_AND_LTIME), DTL, S5Time.
The data types must be the same length and format to carry out the comparison.
The comparison result is output at the OUT parameter as a return value. For this purpose, the parameter OUT is set to “1” if the condition used for the comparison is satisfied.
The following comparison options are available:
Symbol | Description |
---|---|
EQ | The return value has the signal state “1″ if the time is the same at the parameters IN1 and IN2. |
NE | The return value has the signal state “1″ if the time at the parameter IN1 is not the same as that at the parameter IN2. |
GE | The return value has the signal state “1” if the time at parameter IN1 is greater (more recent) than or equal to the time at parameter IN2 . |
LE | The return value has the signal state “1” if the time at parameter IN1 is smaller (less recent) than or equal to the time at parameter IN2. |
GT | The return value has the signal state “1” if the time at parameter IN1 is greater (more recent) than the time at parameter IN2. |
LT | The return value has the signal state “1” if the time at parameter IN1 is smaller (older) than the time at parameter IN2 . |
Parameters
The following table shows the parameters of the “T_COMP” instruction:
Parameter | Declaration | Data type | Memory area | Description |
---|---|---|---|---|
IN1 | Input | DATE, TIME, LTIME, TOD, LTOD, DT, LDT, DTL, S5Time | I, Q, M, D, L, P or constant | First value to be compared. |
IN2 | Input | DATE, TIME, LTIME, TOD, LTOD, DT, LDT, DTL, S5Time | I, Q, M, D, L, P or constant | Second value to be compared. |
OUT | Output | BOOL | I, Q, M, D, L, P | Return value |
Example
In the following example, you use the “Greater or equal” comparison option to compare two times with the LTIME data type.
Create three tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. Select the “GE” comparison option.
Since the time of the first value to be compared (“timeValue1”) is greater than or equal to the second value (“timeValue2”), the return value (“value1GEvalue2”) shows the signal state “TRUE”.