PLC programming - Structured Text Arithmetic Operators
Structured Text Arithmetic Operators perform mathematics operation of non-Boolean value, Structured Text Arithmetic Operators follows the standard mathematical BODMAS (Brackets, Order, Division, Multiplication, Addition, Subtraction) rules. Ladder logic Arithmetic Instruction Generally Have Two Input Variable and One Output Variable, and both input is same data type. it is also possible to append input of arithmetic instruction but data type is same for all input, but in structure text no rules for data and no limit for input variable.
Structured Text Addition Arithmetic Operators
addition arithmetic Operator perform addition of values or expressions. "+" symbol is used to perform addition. Below is the example of addition operator
in above example of arithmetic operator addition of values with constant number is perform. result of addition depend on data type of we add different data type like if we have var_1 and var_2 are real data type and var_3 and var_4 are DINT data. if var_1 = 12.3 , var_2 = 10.8 and var_3 = 4 and var_4 =2 so our addition expression look like total_2_add := var_1 + var_2 + var_3 + var_4; so if our resulted tag (total_2_add) is DINT data type so the result(total_2_add) = 29 and if we have real tag so the value is exactly as it is i.e. 29.1 so always choose proper data type for arithmetic operation for achieving a result.
Structured Text subtraction Arithmetic Operators
it perform subtraction of values, tag and expressions. "-" symbol is used for subtraction operator.
above is the example of Structured Text subtraction in this, if the resulted value is negative for example var_1 and var_2 =0 so result of subtraction (total_3_sub) is -4.56 so same value with minus sign is stored in total_2_sub tag.
Structured Text Multiplication Arithmetic Operators
it perform Multiplication of values. "*" symbol is used for Multiplication operator.
above is the example of Structured Text Multiplication you can multiply more than two value. you can also multiply constant value, real value etc.
Structured Text Division Arithmetic Operators
it perform Division of values. "/" symbol is used for Multiplication operator.
above is some example of Structured Text Division Operators in this example i am dividing multiple constant value. In multiple values division is perform left to right and result is store to resulted tag.
Structured Text Exponent Arithmetic Operators
an exponent Arithmetic Operators used for multiplied a number by itself n times. The expressions for exponent is A**n. means A multiplied by itself n times. If n is negative, then A**-N means the reciprocal of A**N, or 1/(A**N). If n is 0, then a**n is defined to be 1."**" symbol is used for Exponent operator.
above is the example of Exponent Arithmetic Operators. in first example 2 ** 4 so 2 multiplied by itself 4 times so the result is 2*2*2*2 = 16. in second example 2 ** -4 so result is reciprocal of 2 ** 4 (1/16). with help of Exponent Operators you also find square root, cube root (n=1/m) of value in example 3 ** 0.5 so result is 1.732 which is square root of 3.
Structured Text Modulo-Divide MOD Arithmetic Operators
modulo divide (MOD) is a Arithmetic operation that finds the remainder when one value is divided by another value. "MOD" symbol is used for Modulo-Divide operator.
above is the example Structured Text MOD Operators in this example we determine whether a number is even or odd. We already discuss if_Else statment. so if value is even than value_even tag bit set to 1 and value_odd bit set to 0 bot tag is bool data type. in plc even odd program you can also perform same thing by using ladder logic.
example of Structured Text Arithmetic Operators
in this example arithmetic operation is perform by using BODMAS rules. According to BODMAS rule for evaluating an expression, first simplify brackets expressions or parentheses expressions, then evaluate any exponents or square roots, followed by any multiplication or division (from left to right), and finally any addition or subtraction (from left to right).