# How to use Different Math Functions using the Siemens TIA Portal – Part 1

In this article, we will see different Math Functions used in the Siemens TIA Portal.

The Siemens TIA Portal Math Functions blocks are:

% IX db.i : Logical inputs (db, data block i, index)
% QX db.i : Logical outputs (db, data block i, index)
% MX db.i : Bit memory (db, data block i, index), for BOOL variables
% MB db.i : Byte memory (db, data block i, index), for BYTE, SINT and

USINT variables

% MW db.i : Word memory (db, data block i, index), for WORD, INT and

UINT variables

% MD db.i : Double word memory (db, data block i, index), for

DWORD, DINT, UDINT, and REAL variables

Siemens TIA Portal V16 software is used to develop the PLC program. As stated above, the following Sections explain the various PLC Math blocks.

1. This math function is similar to the calculator.
2. The calculator function can be declared with different types of data type, as mentioned above. In this article, the calculator function is defined with integer data type.
3. The user can define any type of customized equation.
4. In this article, (IN1+IN2) *(IN1-IN2) is used for understanding the calculator function (Where IN1, IN2 are First and Second Input respectively)
5. The output is stored in the address %MW0. Where %MW is a single word size (16-bit).
1. Similar to the operation mentioned by the math function, each type of math function performs the corresponding operation.
2. ADD and SUB functions are used to add and subtract the given input.
3. In the ADD function input can be increased by clicking the star button mentioned in the function.
4. The result of the ADD function is stored in the address %MW1. Where %MW is a single word size (16-bit).
5. Similarly, the result of the SUB function is stored in the address %MW2. Where %MW is a single word size (16-bit). (The input cannot be increased for this function).
1. MUL and DIV functions are used to Multiply and Divide the given input.
2. In the MUL function input can be increased by clicking the star button mentioned in the function.
3. The result of the MUL function is stored in the address %MW3. Where %MW is a single word size (16-bit).
4. Similarly, the result of the DIV function is stored in the address %MW4. Where %MW is a single word size (16-bit).
1. The MOD function performs a modulus operation.
2. The MOD function has two inputs. Based on the input given in the MOD function, it performs the mod operation, and the result is stored in %MW5.
3. Similarly, the NEG function gives the negative of the given input.
4. The result is stored in %MW6. Where %MW is a single word size (16-bit).
1. The ABS function performs Absolute operation.
2. It takes a single input and writes the value in the absolute form.
3. The result is stored in %MW9. Where %MW is a single word size (16-bit).
1. The SQR function squares the given input.
2. The result is stored in %MD0. Where %MD is a Double word size (32-bit). (The input cannot be increased for this function).
3. The data type is declared as Real. (User can change the data type according to the requirement).
1. The SQRT function square root the given input.
2. The result is stored in %MD1. Where %MD is a Double word size (32-bit).
3. The data type is declared as real. (User can change the data type according to the requirement)

(NOTE: All the MATH function in this article is declared either with INT or REAL based on the type of the function. But the user can change the data type based on the requirement and usage)

The following is a procedure you can follow to program ladder logic on the SIEMENS TIA portal. (Simulation).

Note: Please refer to the previously mentioned article for a comprehensive explanation of how to program ladder logic using the Siemens TIA Portal.

(Note: For all the math blocks, values (variable) are given for understanding. Users can change the memory address in place of value such as %MW, or %MD. So, that the input can be changed during run time)

1. The Simulation results show the working of the calculator function.
2. The calculator function can be used with any of the blocks of PLC directly or indirectly.
3. In this article the input switch or any other block is not connected.
4. This simulation helps to understand the Calculator function and how to use it.
5. The input of the Calculator function can be increased by clicking the star button, based on the equation declared inside the calculator function.
6. In this article, (IN1+IN2) *(IN1-IN2) is used as example for calculator function. Here only two inputs are used i.e., IN1, IN2.
7. The output is stored in the address %MW0. Where %MW is a single word size (16-bit).
1. The addition and subtraction block of the math function exactly does the same operation mentioned in the operand. (i.e., ADD & SUB).
2. The ADD & SUB function can be used with any of the blocks of PLC directly or indirectly.
3. The ADD function adds the number input given to the block.
4. The user can increase the number of inputs by clicking the star button.
5. The output is stored in the address %MW1. Where %MW is a single word size (16-bit).
6. Similarly, the SUB function subtracts the two inputs given to the block. (Note: for subtraction operation, only two inputs can be given)
7. The output is stored in the address %MW2. Where %MW is a single word size (16-bit).
1. The multiplication and division block of the math function exactly does the same operation mentioned in the operand. (i.e., MUL & DIV).
2. The MUL & DIV function can be used with any of the blocks of PLC directly or indirectly.
3. The MUL function multiplies the number input given to the block.
4. The user can increase the number of inputs by clicking the star button.
5. The output is stored in the address %MW3. Where %MW is a single word size (16-bit).
6. Similarly, the DIV function divides the two inputs given to the block. (Note: for division operation, only two inputs can be given, the dividend and divisor)
7. The output is stored in the address %MW4. Where %MW is a single word size (16-bit).
1. The MOD block takes the modulus of the given input.
2. This block can be used directly or indirectly for any of the PLC blocks.
3. After dividing a number by another, the modulo operation returns the signed remainder, also known as the operation’s modulus.
4. The remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor, is represented by the two positive numbers, a and n, or a modulo n (often shortened as a mod n).
5. For example, since the remainder and quotient of 8 divided by 3 are both 2, the formula “8 mod 3” evaluates to 2.
6. The output is stored in the address %MW5. Where %MW is a single word size (16-bit).
7. The NEG block is a simple block that will produce the result as a negative of the input value
8. The output is stored in the address %MW6. Where %MW is a single word size (16-bit).
1. The ABS block takes the absolute of the given input.
2. The non-negative value of a real number x, independent of its sign, is its absolute value, or modulus.
3. For instance, 56 has an absolute value of 56, and âˆ’56 has an absolute value of 56 as well. One way to conceptualize a number’s absolute value is as its distance along the real number line from zero.
4. The output is stored in the address %MW9. Where %MW is a single word size (16-bit).
1. The SQR block squares the input and displays output on %MD0.
2. The user cannot able to increase the number of inputs
3. The output is stored in the address %MD0. Where %MD is a double word size (32-bit).
1. The SQRT blocks the square root of the given input and displays the output on %MD1.
2. The user cannot able to increase the number of inputs
3. The output is stored in the address %MD1. Where %MD is a double word size (32-bit).

By doing the above exercise the user can understand various math functions (Mentioned above) used in the Siemens TIA Portal