The objective of this tutorial is to demonstrate the declaration of local variables in a MasterTool X project and the manipulation of their values.
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 addition to variables mapped to the PLC's physical channels, MasterTool IEC XE allows the creation of local variables, used only within the program where they are declared, such as UserPrg.
Where to declare local variables
With UserPrg open, in the upper center of the screen, there is an area for declaring variables.
Local variables must be declared between the keywords:
VAR
END_VAR
Everything within this block will be recognized by the software as a local variable of UserPrg.
Declaration syntax
The declaration of a local variable follows the pattern:
Variable_Name : Type;
- Variable_Name: variable identifier
- Type: data type (e.g., BOOL, INT, REAL, etc.)
- The semicolon (;) indicates the end of the declaration
Example:
VAR
ON_BTN: BOOL;
Lamp: BOOL;
Count: INT;
END_VAR
Figure 2. Creating local variables using the text-based visualization environment
In addition to the text declaration between VAR and END_VAR, MasterTool IEC XE offers an alternative and visual way to create local variables, through the tabular view, located on the right side of the screen.
With UserPrg open, when accessing the tabular view of variables, the user can insert, edit, and organize variables in table format, filling in fields such as:
- Variable name
- Data type
- Comment (description)
Upon confirming the insertion via the table, the software automatically generates the corresponding text declaration within the VAR … END_VAR block. That is, both forms are equivalent and always remain synchronized.
Figure 3. Creating local variables using the tubular visualization environment
After creating the local variables, it is possible to use them directly in the Ladder logic and monitor their values during program execution.
1. Inserting a New Network (Line)
To create a new logic line (network), proceed in one of the following ways:
- Through the top menu, selecting the Insert Network option.
- Through the toolbox.
- By right-clicking in the logic area and selecting Insert Network.
- Using the keyboard shortcut Ctrl + L.
In MasterTool X, the term network is used to refer to each line of the Ladder logic.
Figure 4. Creating new lines of code
2. Inserting elements and linking variables
- In the newly created network, insert a normally open contact.
- Then, insert a coil.
- Associate the previously created variables with the contact and coil, typing their names directly into the logic elements.
3. Running the program
After assembling the logic:
- Log in to the project to download the application to the virtual PLC.
- Put the CPU in RUN mode, using the Debug menu or the shortcut available in the upper corner of the software.
4. Viewing the values of the variables
With the program running:
- The current values of the variables can be viewed in the upper central field of the screen.
- This field displays the real-time state of the variables used in the logic, allowing you to monitor the program's behavior during the simulation.
This procedure allows you to verify, in a practical way, how local variables are written, updated, and monitored during the execution of the Ladder logic.
Figure 5. Monitoring the online values of local variables
In addition to direct interaction through Ladder logic, MasterTool X allows you to write and force values directly through the variable table, which facilitates testing and diagnostics.
1. Preparing the value
- Open the UserPrg variable table.
- Locate the desired variable.
- In the Prepared Value column, enter the value that will be applied to the variable:
- For BOOL variables, use TRUE or FALSE.
- For other types, specify the corresponding value.
This step only prepares the value; that is, it has not yet been applied to the logic.
2. Applying the value
After preparing the value, the user must choose the desired action:
- Write value:
Applies the value to the variable, allowing the program logic to continue controlling its state.
- Force value:
Applies the value in a fixed way, preventing the logic from changing the variable while the forcing is active.
The application can be done:
- Through the Debug menu, selecting Write Value or Force Value.
- Or through the corresponding keyboard shortcuts.
Figure 6. Writing/Forcing values in local code variables
This procedure allows testing the program's behavior safely and in an organized manner, using the variable table as a support tool during the simulation.
Figure 7. Writing values in local code variables
3. Releasing forced values
When a value is forced, it remains fixed. Therefore, after testing, it is necessary to release the forcing, allowing the variable to be controlled by logic again.
The release can be done:
• Through the Debug menu, in the Release Values option.
• Or by using the shortcut Alt + F7.
Comments
0 comments
Please sign in to leave a comment.