reference · South Africa
IEC Comparison Instructions: EQ, Limits and Hysteresis
IEC comparison instructions for PLC learners: test equality, numeric types, inclusive limits, hysteresis and invalid readings with clear worked examples.

IEC comparison instructions turn a relationship between values into a Boolean result. Equal, not equal, less than and greater than appear simple, but a useful PLC implementation also specifies data types, engineering units, boundary inclusion and signal validity. A correct operator can still answer the wrong question if those assumptions are unclear.
For South African PLC learners, comparisons connect measurements, counts and selected parameters to decisions in a program. This reference uses deliberately fictional numeric exercises to show how to test those decisions. The pressure values below are teaching fixtures, not recommended setpoints for machinery or a process.
This site has a commercial connection to PLC Simulator. Its educational practice does not supply vendor software licences or prove arbitrary native comparison code on a controller. The illustrations are conceptual learning scenes, not vendor screenshots, plant photographs or measured results.
The six comparison relationships
A comparison needs two operands and a defined relationship. The result is true when that relationship holds for the values being compared. In Structured Text, relational operators are commonly written between operands; the corresponding graphical instruction names depend on the environment and release.
| Relationship | Common ST operator | Question being answered |
|---|---|---|
| Equal | = | Are the two compared values equal? |
| Not equal | <> | Are the two compared values different? |
| Less than | < | Is the left value strictly smaller? |
| Greater than | > | Is the left value strictly larger? |
| Less than or equal | <= | Is the left value smaller or equal? |
| Greater than or equal | >= | Is the left value larger or equal? |
The CODESYS EQ reference describes equality as yielding a Boolean result for the supported elementary types. For a native project, also check the permitted operands and any conversion rules for the selected comparison. A table of symbols is not a substitute for that type information.
Do not confuse equality with assignment. In an ordinary ST expression, an equality test asks a question; an assignment stores a result in a destination. A readable lesson names the result according to the question, such as CountReached or InsideWindow, rather than leaving the reader to infer its meaning from an unnamed Boolean.
Boundary values reveal the difference between operators
Set the right operand to the exact integer 10 and test left operands 9, 10 and 11. These three cases distinguish the strict comparisons from the inclusive ones. Record the expected results before running an implementation.
| Left value | Equal 10 | Not equal 10 | Less than 10 | Greater than 10 | At most 10 | At least 10 |
|---|---|---|---|---|---|---|
| 9 | False | True | True | False | True | False |
| 10 | True | False | False | False | True | True |
| 11 | False | True | False | True | False | True |
If a requirement says “at least ten completed items,” greater than ten would delay success until eleven. If it says “more than ten,” greater than or equal would accept ten too early. The wording of the requirement determines whether equality belongs in the accepted region.
These are exact integer cases. They do not involve a measurement tolerance or floating-point representation issue. Keeping a simple integer fixture separate from the analogue example helps identify whether a failure comes from the chosen operator or from another assumption.

Use the instruction name for the actual software release
Older Logix Designer projects commonly show EQU, NEQ, LES, GRT, LEQ and GEQ. Rockwell's version 36 release notes document updated mnemonics including EQ, NE, LT, GT, LE and GE. A learner comparing an older course screenshot with a newer editor should establish the version before concluding that the instruction is missing.
The current Logix Designer EQ reference distinguishes the graphical instruction from the equality operator used in expressions. Do not assume that every graphical instruction can be called as a named function in Structured Text. Use the language form documented for the target environment.
For Siemens, confirm the operand types and comparator variant in the actual project. Its STEP 7 data-type reference distinguishes INT as a sixteen-bit integer and DINT as a thirty-two-bit integer. Referring to a Siemens “32-bit INT” obscures the distinction and can lead to the wrong range assumption.
When documenting a practical exercise, record the application version, target, operand declarations and expression used. That small amount of context makes an instructor's result reproducible and prevents a generic instruction-name list from becoming misleading platform advice.
Compare quantities in compatible units
Suppose a fictional pressure value is stored as 450 hundredths of a bar. It represents 4.50 bar. Comparing the raw integer 450 directly with a threshold written as 6.0 bar would mix a storage representation with an engineering value.
There are two clear approaches. Convert the reading to bar and compare it with thresholds also expressed in bar, or keep the exact hundredths representation and express the thresholds as 400 and 600. The latter can be appropriate for this exercise because the input resolution and thresholds are deliberately defined in hundredths.
Whichever approach you choose, document the conversion, type and range. A scale factor does not establish sensor accuracy, and adding more decimal places to the display does not create more measurement information. If the raw signal includes special invalid values, those require separate interpretation before an ordinary process comparison.
The analogue scaling and resolution guide explains that distinction in more depth. A comparison should receive a value whose meaning is already clear, rather than being used to guess whether a raw number is in counts, percent or engineering units.
Worked inclusive pressure window
Define a fictional accepted window from 4.00 through 6.00 bar, including both endpoints. A valid reading is inside only when it is greater than or equal to the lower limit and less than or equal to the upper limit. Both conditions must hold.
| Valid reading in bar | At least 4.00? | At most 6.00? | Inside the window? |
|---|---|---|---|
| 3.99 | False | True | False |
| 4.00 | True | True | True |
| 4.01 | True | True | True |
| 5.99 | True | True | True |
| 6.00 | True | True | True |
| 6.01 | True | False | False |
In the exact hundredths representation, these inputs become 399, 400, 401, 599, 600 and 601. The accepted integer interval is 400 through 600 inclusive. This makes the boundary expectations unambiguous for the mathematical fixture.
Using OR instead of AND would answer a different question. For ordered limits 4 and 6, an ordinary finite value below the lower limit still satisfies “at most 6,” and a value above the upper limit satisfies “at least 4.” That mistaken OR expression would accept values the requirement rejects.
Also validate the limits themselves. A lower limit greater than the upper limit is an invalid configuration for this exercise. Do not silently swap the limits unless the requirement explicitly asks for that behaviour. Return a configuration status so the caller can distinguish a bad setup from an otherwise valid reading outside the window.

Tolerance is not the same as hysteresis
A tolerance test asks whether two values are sufficiently close under a stated criterion. A process window asks whether a value lies inside an accepted region. Hysteresis uses different thresholds depending on the current state, so the decision can depend on history as well as the present input.
For example, a mathematical closeness test might accept an absolute difference no greater than a specified tolerance. The tolerance must have compatible units and a justified size. A value chosen merely to make a failing test pass can hide a scaling error or an unacceptable physical deviation.
Some numerical calculations need a relative criterion because the magnitude changes substantially. Others need an absolute allowance near zero. Decide from the requirement and the numerical method; there is no universal epsilon that makes every PLC comparison correct. Measurement uncertainty, quantisation and floating-point rounding are also different contributors.
A tolerance around a target does not automatically stop a Boolean from changing repeatedly as a signal crosses the edge of that band. Hysteresis addresses that switching behaviour by preserving the previous state between separate switching thresholds. It requires explicitly owned state.
Worked hysteresis decision with stated equality rules
For another fictional exercise, define a High state that starts false. A valid reading at or above 6.00 sets High true. A valid reading at or below 5.50 clears High. Between those limits, High keeps its previous state. These thresholds are chosen only to demonstrate the logic.
| Update | Valid reading | Previous High | New High | Reason |
|---|---|---|---|---|
| 1 | 5.80 | False | False | Between thresholds: hold |
| 2 | 6.00 | False | True | Pickup includes equality |
| 3 | 5.90 | True | True | Between thresholds: hold |
| 4 | 5.50 | True | False | Clear includes equality |
| 5 | 5.60 | False | False | Between thresholds: hold |
| 6 | 6.10 | False | True | Above pickup |
At 5.80, either state could be consistent with the hysteresis rule depending on the prior history. That differs from a simple stateless window check. An implementation must therefore establish the initial state and explain what happens after a reset or restart.
The example's pickup threshold is strictly higher than its clear threshold. If a configuration reverses them, the intended state machine is no longer defined by these rules. Detect that configuration rather than relying on the accidental order of two independent assignments to settle a conflict.
Our PLC alarm-priority guide places a threshold decision within the wider alarm context. A High Boolean alone does not specify priority, operator response, acknowledgement, shelving or a safety function.

Filtering and delay answer different questions again
Filtering changes the signal presented to the comparator. A persistence delay can require a condition to remain true for a specified duration before changing an output. Hysteresis changes the switching thresholds according to the existing state. These mechanisms can interact, but they should not be treated as interchangeable names.
A filter can reduce rapid variation while also changing response dynamics. A delay can prevent a brief excursion from asserting a condition, but it also postpones that assertion. Hysteresis can reduce repeated switching near a threshold without defining a minimum duration. The application must justify whichever behaviour it needs.
For a lesson, test the comparator first using known values. Then add one mechanism at a time and write the new expected behaviour. Otherwise, a failed test can be difficult to attribute: the input may have been filtered, the timer may still be running or the previous hysteresis state may legitimately be holding.
Do not describe every noisy-signal problem as requiring a filter. Check signal quality, scaling, sampling and the process requirement. A comparison exercise can teach these questions without prescribing changes to a live alarm or protective function.
Floating-point equality has a precise meaning
Equality on floating-point operands compares their represented values. That operation is not inherently random or broken. The difficulty is that apparently equal decimal calculations may produce slightly different stored values, or a monitoring display may round distinct stored values to the same text.
CODESYS demonstrates this issue in its REAL/LREAL equality analysis guidance. Its example shows calculations that display as 2.2 while their represented results differ. The guidance also discusses an exact-zero exception, reinforcing that every use of floating-point equality is not automatically the same problem.
Use equality where exact represented equality is actually the requirement and the data path supports it. For a computed measurement near a target, a defined acceptance interval is often a better expression of the intended decision. For an exact identifier or event count, choose a suitable discrete representation instead of introducing an unnecessary floating-point conversion.
The CODESYS REAL and LREAL reference describes IEEE 754 floating-point types and target-dependent LREAL support. A wider type can preserve more numerical information where supported, but converting to it after information has already been rounded away cannot reconstruct the original value.
Large counters can lose distinctions during conversion
Consider the distinct integers 16,777,216 and 16,777,217. In an IEEE binary32 round-to-nearest, ties-to-even demonstration, converting each to that floating-point format produces 16,777,216. An equality comparison after both conversions can therefore report equal even though the original integers differed.
This is a mathematical representation example, not a report that every PLC compiler performs every mixed comparison in that way. Its lesson is to inspect conversion before blaming the comparison operator. The relevant questions are which common type is used, where conversion occurs and whether that type preserves the distinction the requirement needs.
If an application needs an exact count, keep the comparison in an appropriate integer domain where possible. If it genuinely needs a converted engineering quantity, document the resulting resolution and test values near important boundaries. A cast is not a guarantee of preserved meaning merely because the program compiles.
Similarly, copying a raw bit pattern and numerically converting a value are different operations. Do not recommend a memory-copy instruction as a general cure for mismatched numeric operands. Use the conversion documented for the source type, destination type and intended value, including out-of-range handling.

Validity must remain visible to the decision
A reading can be unavailable, stale or marked invalid even when a numeric field still contains its previous value. An ordinary threshold comparison of that retained number cannot establish that a fresh valid measurement exists. Keep validity and age information available where the decision needs them.
For the fictional window exercise, define three outcomes: inside, outside and unavailable. Invalid quality produces unavailable rather than inside or outside. A separate configuration error covers reversed limits. This avoids treating “not inside” as proof of a valid out-of-range measurement.
Special floating-point values also need the platform's documented handling. Do not assume every possible operand participates in the ordinary ordered-number relationships used in the truth table. Check the supported validity tests before using a result for an application decision.
For the fictional hysteresis model, an invalid sample holds the stored High state but marks the current evaluation unavailable. That is a chosen teaching policy, not a universally safe response to a failed instrument. An operational system must define how bad quality affects indications, controls and alarms according to its actual requirements.
Our analogue signal types guide explains how the input representation and measurement path affect interpretation. Use that context when defining valid data for a comparison.
Test both boundaries and histories
For each stateless relation, test a value below, equal to and above the threshold. For a window, test both ends and values immediately inside and outside them. Include an invalid configuration and invalid input quality, so a nominal success does not conceal an undefined branch.
For hysteresis, test sequences rather than isolated values. Reach the band from below and from above, then demonstrate that the same intermediate value can preserve different states. Include equality at both switching thresholds and an explicit initial-state case.
For numeric conversions, test representative extremes and values around a precision boundary. Compare the stored or otherwise sufficiently precise diagnostic value with the display. A screenshot rounded to two decimal places may be insufficient evidence for explaining an equality result.
The PLC program testing exercises support the habit of writing expectations before execution. The checked models accompanying this reference validate its mathematical fixtures; they do not establish a vendor runtime's conversion behaviour or the suitability of a process threshold.
What a practical comparison lesson should assess
Ask a PLC training provider to show a task where learners choose the operator from a written requirement and explain equality at the boundary. A second task should involve units or data types, so the assessment goes beyond finding a graphical block in the editor.
For a South African classroom or remote course, confirm the software release, target and individual learner access. An older Logix screenshot can still teach a useful relationship, but the instructor should explain changed mnemonics and current project requirements. Native engineering practice should be described separately from general simulator exercises.
A useful portfolio contains the requirement, operand declarations, expected tables and a failed case with its correction. State whether the example is a mathematical model, a vendor simulation or an equipment exercise. Avoid presenting a classroom threshold as evidence of production commissioning or a formally recognised qualification.
The Structured Text learning tools provide a relevant route into readable expressions. Use the required vendor environment when the goal is to verify a particular instruction, conversion or diagnostic behaviour.
Common questions about PLC comparisons
Should I always replace REAL equality with a tolerance?
No. First decide whether the requirement is exact represented equality or acceptable closeness. Where tolerance is appropriate, choose it from the numerical and application requirements. An arbitrary allowance can conceal a real defect.
Is deadband the same as a delay timer?
No. Hysteresis uses separate switching thresholds and stored state. A delay adds a time requirement. Document the desired response and test each mechanism separately before combining them.
Why does an older Allen-Bradley lesson show EQU instead of EQ?
Rockwell changed several instruction mnemonics from version 36. Establish the course and project versions, then consult the corresponding instruction reference. The relationship being taught can remain equality while the displayed instruction name changes.
Can I compare raw counts directly with engineering setpoints?
Only when they intentionally use the same representation. Otherwise, convert the measurement or express the limits in the raw representation with a documented scale. A number without its units and type is an incomplete comparison operand.
Is an invalid reading simply outside the acceptable range?
Not in this exercise. It returns unavailable, because the program lacks a valid value on which to decide. The actual application must define its response to bad quality separately from a valid low or high reading.

Make the decision explainable
A reviewer should be able to identify the units, types, equality rules, validity handling and any required previous state. Show why 4.00 and 6.00 are inside the fictional window, why 5.90 preserves High after pickup and why two large integer counts can become indistinguishable after a lossy conversion.
Those explanations make comparison logic useful beyond a memorised list of instructions. They connect a Boolean result to the precise requirement it is intended to represent and provide a clear basis for testing the implementation.