The objective of this tutorial is to explain how to use the addition and subtraction blocks within the context of arithmetic operations in a MasterTool X project.
Components
Equipment: 1 computer/notebook.
Software: MasterTool X
Tutorial Sections
- ARCHITECTURE
- DEVELOPMENT
1. ARCHITECTURE
A computer/notebook will be required to use MasterTool X.
Figure 1. Computer running MasterTool X
2. DEVELOPMENT
The ADD (addition) and SUB (subtraction) operators are used to perform basic mathematical operations within Ladder logic, allowing you to add or subtract values from variables or constants.
They are widely used in:
- Increments and decrements of values
- Setpoint adjustments
- Intermediate calculations
- Numerical control processes
Operators
🔹 ADD (Addition)
Performs the sum between two values:
- Result = First parameter + Second parameter
🔹 SUB (Subtraction)
Performs the subtraction between two values:
- Result = First parameter − Second parameter
Important:
The order of the parameters matters.
The operator always executes the operation of the first parameter in relation to the second.
Inserting operators into logic
The ADD and SUB operators are not function blocks, but mathematical operators.
To add them to the logic:
- Open the Toolbox.
- Access Mathematical Operators.
- Select ADD or SUB.
- Click and drag the operator to the Ladder logic.
Figure 2. Insertion of the mathematical operators ADD and SUB
Input and output parameters
Inputs
- Can receive:
- Variables
- Numeric constants
Output (mandatory)
Since ADD and SUB are not function blocks, the output must be associated with a previously declared variable.
Unlike function blocks, it is not possible to simply view the result in the block without declaring an output variable.
Data types and important considerations
It is essential to ensure the compatibility of the data types used:
- INT / DINT
- Work only with integers
- Do not accept decimal places
- REAL
- Allows numbers with decimal places
Best practices:
- Avoid mixing INT with REAL in the same operator.
- If necessary, use type conversions.
- The output variable must be of the same type as the inputs.
Using Variables or Constants
- Constants: Suitable for fixed values (e.g., add 1, subtract 10).
- Variables: Allow dynamic calculations during program execution.
Both can be freely used in the operator inputs.
Figure 3. Insertion of variables for the ADD and SUB mathematical operators
Operation Execution
The PLC executes the mathematical operation in each scan cycle, following this order:
- Reading the first parameter
- Reading the second parameter
- Applying the mathematical operation
- Writing the result to the output variable
Practical Application
After inserting the ADD or SUB operator:
- Declare the output variable.
- Associate variables or constants with the inputs.
- Download the application.
- Put the CPU in RUN mode.
- Observe the value of the output variable being updated as the inputs change.
The ADD and SUB operators are essential for creating simple and efficient mathematical logic, provided the programmer correctly declares the output variable, ensuring clarity and proper program operation.
Figure 4. Operation of the ADD and SUB mathematical operators
Comments
0 comments
Please sign in to leave a comment.