PLC Programming Comparison Instructions – LES | Less Than
The LES, also known as the Less Than, is an instruction used to compare two values against each other. The instruction takes two integers, floats or constants and will return TRUE if the value specified in “Source A” is less than the one in “Source B”. The “Source B” operand must be strictly less than the one specified in “Source A”. In other words, the instruction will return FALSE if they are equal.
This instruction can be used to test for an upper limit for an analog sensor and reliably notify the programmer should the value be exceeded.
In RSLogix 500, you may not compare two constants; this restriction is not present in RSLogix 5000 as well as Studio 5000. This is also the case for all comparison instructions.
Example & Usage of LES
Here’s a real-world scenario of a LES instruction:
- A Micrologix 1100 Allen Bradley PLC is used to control a process.
- A LES instruction is used to compare a Float F7:10 to a Float F7:11.
- The Float F7:10 is currently set to “345.464” and the Float F7:11 is set to “2.15915”.
- This LES instruction evaluates to FALSE since the value of F7:10 is NOT Less Than the value in F7:11.
- Note: The logic displays the boolean B3:1/0 as energized due to the fact that it’s used elsewhere in the logic. It is not being energized by this rung.
- A LES instruction is used to compare an Integer N7:0 to the Integer N7:1.
- The Integer N7:0 is currently set to “564” while the Integer N7:1 is set to “6”.
- This LES instruction evaluates to FALSE since N7:0 is NOT Less Than N7:1.
- A TON instruction is used to run a continuous timer T4:2 loop 2 seconds (200 x 0.01 = 2000 msec.)
- A LES instruction is used to compare the value of the accumulated (.ACC) value of Timer T4:2 to the integer N7:3.
- The LES instruction will evaluate to TRUE during the first half of the timer because N7:3 is set to 100 (100 x 0.01 = 1000 = 1/2 of the timer).
- The LES instruction will evaluate to FALSE during the second half of the timer because N7:3 is set to 100 (100 x 0.01 = 1000 = 1/2 of the timer).
Programming example in RSLogix 500:
The first two examples of the LES instruction are straightforward. We’re comparing two operands to each other and return TRUE if the one specified in “Source A” is less than the one in “Source B”. The first instruction is evaluating two distinct float registers. Since the one specified in “Source A” is NOT less than the one in “Source B”, the instruction returns a FALSE. The same is true for the second LES instruction, but it’s used on a set of integers.
The last example which uses the LES instruction in ladder logic is slightly less obvious. A timer is running in a continuous loop due to the XIO Instruction used on its .DN bit. The setting on the timer causes the loop to repeat every two seconds. The LES instruction below the timer is comparing the accumulated value in the timer to the integer N7:3. Since the integer is set to 100, it causes the instruction to evaluate to TRUE during the first half of the timer.
Data Types Allowed for LES
The LES can be used to compare two values of identical types. These value can be INTs, DINTs, or FLOATs.
- Integer – You may specify each operand to be of “Integer” type.
- Float – You may specify each operand to be of “Float” or “Real” type.
- Note 1 – Both operands need to be exactly the same while the rung containing the LES instruction is being scanned. Otherwise, the instruction will evaluate to TRUE. In an instance where the value is changed in other locations for only a brief duration, the LES comparison may result in unforeseen outcomes.
- Note 2 – When working with constants, RSLogix 500 will not allow the user to use the constant in the “Operand A” field. The constant must be specified within “Operand B”. This limitation is not present in all software packages.
- Note 3 – The user may not specify a comparison of two constants within RSLogix 500. In other words, you may not use the LES instruction with “Operand A” set to 7 and “Operand B” set to 20. This case will always evaluate to FALSE which should not be used.