Arithmetic operators in Structured Text (ST) are used to perform essential mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/), exponentiation (**), and modulo (MOD). These operators are fundamental to numeric calculations in PLC programming, enabling logic that can evaluate values, calculate setpoints, scale analog inputs, and process real-time data from sensors or user-defined variables. ST supports these operators in a clean, readable format that closely resembles traditional programming languages, making it easy to write efficient control logic.
In industrial automation, arithmetic operators are commonly used to adjust process values, compute totals from flow meters, calculate errors for PID control, scale temperature or pressure signals, and create conditional logic based on numeric thresholds. These calculations ensure smooth operation of systems like HVAC, motors, batch processes, and packaging machinery. Understanding how to use arithmetic operators properly in ST helps programmers write optimized, reusable, and readable code for both simple and advanced PLC applications.
In Structured Text programming, arithmetic expressions follow the standard BODMAS rule: Brackets, Orders (such as powers), Division and Multiplication, and Addition and Subtraction. This rule ensures a logical and hierarchical order of execution during computation.
The image above illustrates how Structured Text evaluates arithmetic expressions:
Addition arithmetic operators in Structured Text (ST) are used to perform the sum of numerical values, constants, or expressions. The plus symbol (+) is used as the operator to carry out addition. This operator supports simple as well as nested expressions, allowing multiple tags and constants to be summed in a single statement. This is extremely useful in real-time PLC logic where multiple sensor readings, constants, or processed values need to be aggregated efficiently.
In the example shown above, multiple addition operations are performed using different variables and constant values. For instance, the expression total_2_add := var_1 + var_2 + var_3 + var_4 + 12.22; demonstrates how multiple variables and a constant can be added in a single statement. It’s important to note that the data type of the result tag (e.g., total_2_add) directly affects the precision of the outcome. For example, if var_1 and var_2 are of type REAL and var_3 and var_4 are DINT, with values like var_1 = 12.3, var_2 = 10.8, var_3 = 4, and var_4 = 2, then the total sum is 29.1. However, if total_2_add is declared as DINT, the result will be automatically converted to 29 by truncating the decimal.
This behavior highlights the importance of selecting the correct data type when using arithmetic operations in Structured Text. Using REAL ensures floating-point precision, whereas using INT or DINT may lead to loss of decimal accuracy. When combining different data types in expressions, the PLC implicitly applies type conversion rules, which should always be accounted for to avoid unexpected outcomes in control logic or reporting.
The Modulo Divide operation in Structured Text uses the MOD operator to find the remainder when one number is divided by another. This arithmetic function is useful for tasks such as checking if a number is even or odd. The syntax is: result := value1 MOD value2;
In the example shown above, the program checks if the value of Var_1 is even using the MOD operator. If the remainder of Var_1 MOD 2 is zero, it sets the Boolean tag value_even to 1 (TRUE) and value_odd to 0 (FALSE). Otherwise, it sets value_even to 0 and value_odd to 1. This is a simple and effective way to categorize even and odd numbers in Structured Text.
The multiplication operator in Structured Text is used to multiply values together. The symbol "*" is used to perform the multiplication operation in PLC programming. It supports both constant and variable inputs, including integer and real data types.
The image above shows examples of Structured Text multiplication operations. You can multiply two or more values, including real numbers and constants. Multiplication follows standard arithmetic rules, and the result is stored in the corresponding tag or variable.
The division arithmetic operator in Structured Text is used to divide one value by another. The symbol "/" is used to perform division operations. It works with both constants and variables in PLC programming.
The image above shows several examples of Structured Text division operations. In these examples, constant values are divided from left to right, and the result is stored in the assigned tag. Division follows the standard mathematical order, so in a chain of values, the operation proceeds sequentially from left to right.
Exponent arithmetic operators in Structured Text are used to raise a number to a specific power. The syntax follows the format A**n, which means A is multiplied by itself n times. The "**" symbol is used for exponentiation. If the exponent (n) is negative, the result is the reciprocal of A raised to the absolute value of n. If n is 0, the result is always 1 regardless of the base A.
The image above shows multiple examples of exponent operations in Structured Text. For instance, 2**4 equals 16 (i.e., 2×2×2×2). In 2**-4, the result is 1/(2**4) which equals 0.0625. Exponents can also be used to calculate square roots or fractional powers like 3**0.5 which results in approximately 1.732 — the square root of 3. These expressions are especially useful in control algorithms and complex calculations inside PLC programs.
Arithmetic operators in Structured Text (ST) are essential for performing numerical calculations within PLC programs. These operations allow automation engineers to manipulate values from sensors, user inputs, or internal tags to implement effective and intelligent control logic.
Structured Text supports standard operators such as + (addition), - (subtraction), * (multiplication), / (division), ** (exponentiation), and MOD (modulo). These operators follow the BODMAS rule, ensuring correct order of operations in complex expressions.
By effectively using arithmetic operators in ST, programmers can create more accurate, flexible, and optimized PLC applications for industrial automation tasks.