Navigation:  Equipments (Devices) > SCA06 > Ladder > Math > Math Basic >

SUB

Previous pageReturn to chapter overviewNext page

Block that calculates the subtraction between the Value1 and Value2 values, storing the result in Result.

 

Ladder Representation

 

SUB_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

EN

BOOL

Block enabling

Value1

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL

Minuend of operation

Value2

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL

Subtrahend of operation

VAR_OUTPUT

Done

BOOL

End of operation

Result

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL

Variable that stores the result of the operation

 

Operation

 

When this block has a TRUE value in EN, it sends to the Result output the subtraction of Value1 and Value2 variables. If no errors, the Done variable is set. If there is any error in the operation, Done is not set, staying in FALSE status, while Result remains with its value unchanged.

 

When EN has FALSE value, Result remains unchanged and Done remains in FALSE.

 

Block Flowchart

 

SUB_flowchart

 

Example in Ladder

 

SUB_example01

 

The above example calculates the subtraction of VALUE 1 and VALUE2 variables, storing the final result in RESULT.

 

SUB_example02

 

The above example calculates the subtraction of VALUE 1 and VALUE2 variables, storing the final result in RESULT. Notice that the block accepts arguments of both signs.

 

SUB_example03

 

The above example calculates the subtraction of VALUE1 and VALUE2 variables. The final result 141 cannot be stored in RESULT, because it is outside the limits of accepted values by SINT type. Therefore, RESULT remains unchanged and the output is disabled.

 

Example in ST

 

 The example below displays the instructions for applying the example above in the ST language.

 

 

VAR

   VALUE1 : SINT := 52;

   VALUE2 : SINT := -17;

   RESULT : SINT;

END_VAR

 

RESULT := FB_SUB(

   EN:=DI1,

   Value1:=VALUE1,

   Value2:=VALUE2,

   Done=>DO1);