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

- Math Function’s Part I
- Size of Data Type Used by the Different Math Functions in Siemens TIA Portal
- Various Types of Address Allocation by Siemens TIA Portal
- Different Math Functions of Plc Ladder Logic Used in Siemens TIA Portal
- Declaration of Address for Different Math Functions
- Working with Different Math Functions Used in the Siemens TIA Portal
- Simulation Screenshots Of Different Math Function

**Math Function’s Part I**

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

The Siemens TIA Portal Math Functions blocks are:

S. NO | TYPES OF FUNCTIONS | FUNCTION |

1 | CALCULATE | Work similar to the calculator for any type of Functions |

2 | ADD, SUB, MUL, DIV, MOD, NEG, ABS | The Function does the corresponding operation mentioned by the operand based on the data type given in the input. |

3 | SQRSQRT | These two functions find the square and square root of the given number |

**Size of Data Type Used by the Different Math Functions in Siemens TIA Portal**

S. NO | DATA TYPE | LOWER LIMIT | UPPER LIMIT | MEMORY SPACE |

1 | SINT | –128 | 127 | 8 bit |

2 | USINT | 0 | 255 | 8 bit |

3 | BYTE | 0 | 255 | 8 bit |

4 | WORD | 0 | 65,535 | 16 bit |

5 | INT | –32,768 | 32,767 | 16 bit |

6 | UINT | 0 | 65,535 | 16 bit |

7 | DWORD | 0 | 4,294,967,295 | 32 bit |

8 | DINT | –2,147,483,648 | 2,147,483,647 | 32 bit |

9 | UDINT | 0 | 4,294,967,295 | 32 bit |

10 | LINT | –2^{63} | 2^{63}-1 | 64 bit |

11 | ULINT | 0 | 2^{64}-1 | 64 bit |

12 | LWORD | 0 | 2^{64}-1 | 64 bit |

**Various Types of Address Allocation by Siemens TIA Portal**

% 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

**Different Math Functions of Plc Ladder Logic Used in Siemens TIA Portal**

**CALCULATE**

**ADDITION AND SUBTRACTION FUNCTION**

**MULTIPLICATION AND DIVISION**

**MODULUS AND NEGATIVE**

**ABSOLUTE FUNCTION**

**SQUARE AND SQUARE ROOT**

**Declaration of Address for Different Math Functions**

S. No | Operation | Input/Output Address | Output Address | Data type |

1 | CALCULATE | Output | %MW0 | Int |

2 | ADD | Output | %MW1 | Int |

3 | SUB | Output | %MW2 | Int |

4 | MUL | Output | %MW3 | Int |

5 | DIV | Output | %MW4 | Int |

6 | MOD | Output | %MW5 | Int |

7 | NEG | Output | %MW6 | Int |

8 | ABS | Output | %MW9 | Int |

9 | SQR | Output | %MD0 | Real |

10 | SQRT | Output | %MD1 | Real |

**Working with Different Math Functions Used in the Siemens TIA Portal**

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

**CALCULATE**

- This math function is similar to the calculator.
- 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.
- The user can define any type of customized equation.
- In this article, (IN1+IN2) *(IN1-IN2) is used for understanding the calculator function (Where IN1, IN2 are First and Second Input respectively)
- The output is stored in the address
**%MW0**. Where %MW is a single word size (16-bit).

**ADDITION AND SUBTRACTION FUNCTION**

- Similar to the operation mentioned by the math function, each type of math function performs the corresponding operation.
- ADD and SUB functions are used to add and subtract the given input.
- In the ADD function input can be increased by clicking the star button mentioned in the function.
- The result of the
**ADD**function is stored in the address**%MW1**. Where**%MW**is a single word size (16-bit). - Similarly, the result of the
**SUB f**unction is stored in the address**%MW2**. Where**%MW**is a single word size (16-bit). (The input cannot be increased for this function).

**MULTIPLICATION AND DIVISION FUNCTION**

**MUL**and**DIV**functions are used to Multiply and Divide the given input.- In the
**MUL**function input can be increased by clicking the star button mentioned in the function. - The result of the
**MUL**function is stored in the address**%MW3**. Where**%MW**is a single word size (16-bit). - Similarly, the result of the
**DIV**function is stored in the address**%MW4**. Where**%MW**is a single word size (16-bit).

**MODULUS AND NEGATIVE**

- The
**MOD**function performs a modulus operation**.** - 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.** - Similarly, the
**NEG**function gives the negative of the given input. - The result is stored in
**%MW6.**Where**%MW**is a single word size (16-bit).

**ABSOLUTE FUNCTION**

- The
**ABS**function performs Absolute operation. - It takes a single input and writes the value in the absolute form.
- The result is stored in
**%MW9.**Where**%MW**is a single word size (16-bit).

**SQUARE AND SQUARE ROOT**

**SQUARE**

- The
**SQR**function squares the given input. - The result is stored in
**%MD0.**Where**%MD**is a Double word size (32-bit). (The input cannot be increased for this function). - The data type is declared as Real. (User can change the data type according to the requirement).

**SQUARE ROOT**

- The
**SQRT**function square root the given input. - The result is stored in
**%MD1.**Where**%MD**is a Double word size (32-bit). - 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.**

**Simulation Screenshots Of Different Math Function**

**(Not****e: 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)**

**CALCULATE**

- The Simulation results show the working of the calculator function.
- The calculator function can be used with any of the blocks of PLC directly or indirectly.
- In this article the input switch or any other block is not connected.
- This simulation helps to understand the Calculator function and how to use it.
- The input of the Calculator function can be increased by clicking the star button, based on the equation declared inside the calculator function.
- In this article,
**(IN1+IN2) *(IN1-IN2)**is used as example for calculator function. Here only two inputs are used i.e., IN1, IN2. - The output is stored in the address
**%MW0**. Where %MW is a single word size (16-bit).

**ADDITION AND SUBTRACTION FUNCTION**

- The addition and subtraction block of the math function exactly does the same operation mentioned in the operand. (i.e., ADD & SUB).
- The
**ADD**&**SUB**function can be used with any of the blocks of PLC directly or indirectly. - The
**ADD**function adds the number input given to the block. - The user can increase the number of inputs by clicking the star button.
- The output is stored in the address
**%MW1**. Where %MW is a single word size (16-bit). - Similarly, the
**SUB**function subtracts the two inputs given to the block. (Note: for subtraction operation, only two inputs can be given) - The output is stored in the address
**%MW2**. Where %MW is a single word size (16-bit).

**MULTIPLICATION AND DIVISION**

- The multiplication and division block of the math function exactly does the same operation mentioned in the operand. (i.e.,
**MUL**&**DIV**). - The
**MUL**&**DIV**function can be used with any of the blocks of PLC directly or indirectly. - The
**MUL**function multiplies the number input given to the block. - The user can increase the number of inputs by clicking the star button.
- The output is stored in the address
**%MW3**. Where %MW is a single word size (16-bit). - 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) - The output is stored in the address
**%MW4**. Where %MW is a single word size (16-bit).

**MODULUS AND NEGATIVE**

- The
**MOD**block takes the modulus of the given input. - This block can be used directly or indirectly for any of the PLC blocks.
- After dividing a number by another, the modulo operation returns the signed remainder, also known as the operation’s modulus.
- 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).
- For example, since the remainder and quotient of 8 divided by 3 are both 2, the formula “8 mod 3” evaluates to 2.
- The output is stored in the address
**%MW5**. Where %MW is a single word size (16-bit). - The
**NEG**block is a simple block that will produce the result as a negative of the input value - The output is stored in the address
**%MW6**. Where %MW is a single word size (16-bit).

**ABSOLUTE FUNCTION**

- The
**ABS**block takes the absolute of the given input. - The non-negative value of a real number x, independent of its sign, is its absolute value, or modulus.
- 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.
- The output is stored in the address
**%MW9**. Where %MW is a single word size (16-bit).

**SQUARE AND SQUARE ROOT**

**SQUARE**

- The
**SQR**block squares the input and displays output on**%MD0.** - The user cannot able to increase the number of inputs
- The output is stored in the address
**%MD0**. Where %MD is a double word size (32-bit).

**SQUARE ROOT**

- The SQRT blocks the square root of the given input and displays the output on
**%MD1.** - The user cannot able to increase the number of inputs
- 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**