The purpose of this tutorial is to explain how to insert and use the conversion operator that converts integer type variables to time type in a MasterTool X project.
Components
Equipment: 1 computer/laptop.
Software: MasterTool X
Tutorial Sections
- ARCHITECTURE
- DEVELOPMENT
1. ARCHITECTURE
A computer/laptop will be required to use MasterTool X.
Figure 1. Computer running MasterTool X
2. DEVELOPMENT
In various 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 transforming a value of a specific type into another compatible type, such as converting an integer (INT) into a time (TIME).
Inserting the operator into the logic
To insert a conversion operator in the Ladder program:
- Open the Toolbox.
- Navigate to: Other Operators → Conversion.
- Select the conversion operator.
- Click and drag the block into the Ladder logic.
After inserting the block into the network, it will be necessary to define which conversion will be performed by writing the function syntax inside the block.
Figure 2. Inserting the conversion operator into the code
Defining the conversion
Inside the block, the programmer must enter the name of the desired conversion function.
In this tutorial example, the conversion used will be:
INT_TO_TIME
This function converts a value of type INT to TIME.
How INT_TO_TIME works
The INT_TO_TIME operator receives an integer value as input and returns a corresponding time value.
In the controller, the TIME type is internally represented in milliseconds, so the converted value will be returned in ms.
Practical example:
Input (INT) = 3000
Output (TIME) = T#3s
In this case:
- 3000 represents 3000 milliseconds
- The converted value will be 3 seconds in TIME format
Parameterization of inputs and outputs
The block has two main fields:
Input
- Receives a variable or value of type INT
Output
- Must be a variable compatible with the resulting type of the conversion
- In the case of INT_TO_TIME, the output must be of type TIME
Example of variable declaration:
motor_time : TIME;
time_ms : INT;
Application in the block:
time_ms → INT_TO_TIME → converted_time
Figure 3. Parameterization of the INT_TO_TIME operator
Practical application
This type of conversion is very useful in situations such as:
- Timer parameterization with numeric values
- Time adjustment via HMI
- Dynamic control of process times
- Conversion of integer data for use in timer blocks
Conversion operators provide greater flexibility in data handling, allowing integration of different variable types within the controller logic.
Figure 4. Operation of the INT_TO_TIME operator
Comments
0 comments
Please sign in to leave a comment.