Skip to main content

SUB

Subtracts Value2 from Value1 and stores the result in Result.

Ladder Representation

SUB block

Block Structure

Variable TypeNameData TypeDescription
VAR_INPUTENBOOLBlock enabling.
VAR_INPUTValue1BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REALMinuend of the operation.
VAR_INPUTValue2BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REALSubtrahend of the operation.
VAR_OUTPUTDoneBOOLEnd of operation.
VAR_OUTPUTResultBYTE USINT SINT WORD UINT INT DWORD UDINT DINT REALVariable that stores the operation result.

Operation

When EN is TRUE, the block writes the subtraction result between Value1 and Value2 to Result.

If the operation completes without errors, Done is set. If an operation error occurs, Done remains FALSE and Result keeps its previous value.

When EN is FALSE, Result remains unchanged and Done remains FALSE.

Execution Flowchart

SUB execution flowchart

Examples

SUB ladder example 1

This example subtracts VALUE2 from VALUE1 and stores the final result in RESULT.

SUB ladder example 2

This example subtracts VALUE2 from VALUE1 and stores the final result in RESULT. The block accepts arguments with different signs.

SUB ladder example 3

This example subtracts VALUE2 from VALUE1. The final result, 141, cannot be stored in RESULT because it is outside the accepted range for SINT. For this reason, RESULT remains unchanged and the output is disabled.