Math (output instruction)

ABS: Absolute Value

Writes A with any negative sign removed.

Also called: absolute value, magnitude.

ABS(number, a, real)

Arguments

NameWhat it isAcceptsDefault
destinationWhat the instruction acts ona registerrequired
aSourcea number or a tag0
realFloating pointtrue or falsefalse

Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.

What it does

ABS answers how far, not which way. It is the instruction that turns a signed error into a distance.

That makes it the second half of nearly every deviation alarm. Subtract to get the error, take its magnitude, then compare against a band. Without the ABS the comparison only ever catches deviation in one direction, and the alarm that was meant to say the process has drifted stays silent for half of the ways it can drift.

Give the result its own tag. If the sign is still needed elsewhere, and in control it usually is, overwriting the signed error with its magnitude quietly breaks whatever was using it.

A rung you can run

A deviation alarm that catches both directions

RUNG 1SUB Temp_ErrorOven_Temp − Temp_Set…RUNG 2ABS Temp_DeviationABS Temp_Err…RUNG 3Temp_Deviation> 10Heat_EnableTON Dev_Delay5000 msRUNG 4Dev_Delay.DNTemp_Deviation_Alarm
SUB(Temp_Error,Oven_Temp,Temp_Setpoint)
ABS(Temp_Deviation,Temp_Error)
GRT(Temp_Deviation,10)XIC(Heat_Enable)TON(Dev_Delay,5000)
XIC(Dev_Delay.DN)OTE(Temp_Deviation_Alarm)

Set Temp_Setpoint to 180 and Heat_Enable on, then try Oven_Temp at 165 and at 195. Both are 15 out, both raise the alarm, and the five second on-delay means a brief excursion on the way to setpoint does not. The signed error is still there in Temp_Error for anything that needs to know which way.

Run this rung in the simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)ABS
Siemens (TIA Portal)ABS
Mitsubishi (GX Works)ABS
CODESYS and IEC 61131-3ABS

Common mistakes

  • Comparing a signed error directly. An error of -30 satisfies a test for less than 5, so a deviation alarm without ABS passes happily while the process runs a long way under setpoint.
  • Writing the magnitude back over the signed value. Anything downstream that needed to know which way the error went now cannot, and the fault appears somewhere else entirely.

Practise it

Interactive exercises that use ABS. Each one checks your ladder against a real scan.

Related instructions

All ladder logic instructions