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.
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
- Safety
SIL or PL: which one does your machine need?
Two standards, two scales, and one machine. Which one applies, how they map to each other, and why the answer is usually ISO 13849.
- Safety
Categories B, 1, 2, 3 and 4, in plain terms
Five architectures, what a single fault does to each, and the practical wiring that goes with them.
- Safety
Safety relay or safety PLC: how to decide
One is a wiring decision, the other is a programming one. The count of safety functions, not the size of the machine, is what settles it.