The objective of this tutorial is to explain how to insert and use the conversion operator that converts variables of type time to integer type 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
In many programming situations, it is necessary to convert one data type to another, whether to perform calculations, comparisons, or to make data compatible between blocks that work with different types. For this, MasterTool IEC XE provides type conversion operators.
These operators allow you to transform a value of a specific type into another compatible type, such as converting a time (TIME) to an integer (INT).
Inserting the Operator into the Logic
To insert a conversion operator in the Ladder program:
- Open the Toolbox.
- Access the path: Other Operators → Conversion.
- Select the conversion operator.
- Click and drag the block to the Ladder logic.
After inserting the block into the network, it will be necessary to define which conversion will be performed, writing the function syntax inside the block.
Figure 2. Inserting the conversion operator into the code
Defining the conversion
Within the block, the programmer must insert the name of the desired conversion function.
In the example of this tutorial, the conversion used will be:
TIME_TO_INTThis function converts a value of type TIME to INT.
How TIME_TO_INT works
The TIME_TO_INT operator receives a time value as input and returns a corresponding integer value.
In the controller, the TIME type is internally represented in milliseconds, therefore the converted value will be returned in ms.
Practical Example:
Input (TIME) = T#3s
Output (INT) = 3000In this case:
- T#3s represents 3 seconds
- The converted value will be 3000 milliseconds
Parameterization of inputs and outputs
The block has two main fields:
Input
- Receives a variable or value of type TIME
Output
- Must be a variable compatible with the resulting type of the conversion
- In the case of TIME_TO_INT, the output must be of type INT
Example of variable declaration:
motor_time : TIME;
time_ms : INT;Application in the block:
motor_time → TIME_TO_INT → time_msFigure 3. Parameterization of the MOVE operator
Practical application
This type of conversion is very useful in situations such as:
- Using timer values in mathematical calculations
- Comparing times with integer values
- Sending time data to graphical interfaces or supervisory systems
- Adapting data for other blocks that work only with integers
Conversion operators ensure greater flexibility in data handling, allowing the integration of different types of variables within the controller logic.
Figure 4. Operation of the MOVE operator
Comments
0 comments
Please sign in to leave a comment.