← Resources
Instructions·5 min read·

Comparison instructions and the analog value that is never equal

EQU, GRT, LES and the reason comparing analog values for equality does not work.

Short answer

Comparison instructions sit on the condition side and pass rung power when the comparison is true. EQU tests equality, NEQ inequality, GRT and LES magnitude, GEQ and LEQ inclusive magnitude. Testing an analog value for exact equality almost never works, because a measured value passes through the target between scans rather than landing on it.

4-20 mA scaled to engineering unitsbroken loop4 mA20 mA0 bar10 bar3277 / 553016384 / 27648raw counts: AB / Siemens

Comparison instructions go on the condition side of a rung and pass power when the comparison holds. The instructions themselves are simple. Applying them to measured values is where the problems live.

Never compare an analog value for equality

A temperature rising through 80 degrees is sampled once per scan. It might read 79.6, then 80.4. It never reads exactly 80, so an equality test never fires and the machine waits forever.

Use greater-than or less-than for anything measured. Reserve equality for values your own program set, such as a step number or a mode.

Add a deadband

A value sitting near the threshold crosses it repeatedly, and an output driven directly from the comparison chatters at scan rate. Contactors do not enjoy this.

Turn on above 80 and off below 78. The two degrees of hysteresis costs nothing and turns a chattering output into a stable one.

Watch the data types

Comparing a REAL against an INT works on most platforms and quietly converts one of them first. Comparing a scaled REAL against a raw count compiles fine and is meaningless. Name the tags so the mismatch is visible in the rung.

Common questions

Why does my equality comparison on an analog value never trigger?
Because the value is sampled once per scan and rarely lands exactly on the target. A temperature rising through 80 degrees might read 79.6 on one scan and 80.4 on the next, never 80. Use a greater-than comparison, and add a deadband so the result does not chatter at the threshold.
What is a deadband and why do I need one?
A deadband is a gap between the point where a condition turns on and the point where it turns off. Without one, a value hovering at the threshold toggles the output every scan. Turning on at 80 and off at 78 gives two degrees of hysteresis and a stable output.

Keep reading