The objective of this tutorial is to explain how to create program-type subroutines 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 use of subroutines (Program-type POUs) allows for better project organization, separation of functionalities, easier maintenance, and improved logic readability.
In this tutorial, a folder for subroutines will be created, a simple POU will be created, and finally, this subroutine will be called in UserPrg.
Creating a folder in the project tree
To organize the subroutines:
- In the project tree, locate the Application item.
- Right-click on Application.
- Select the Create Folder option.
- Name the folder Subroutines.
This folder will only be used for visual and logical organization of the project.
Figure 2. Creating a folder
Creating a subroutine (POU)
With the folder created:
- Right-click on the Subroutines folder.
- Select Add Object.
- Choose POU.
- In the Type field, select Program.
- Define a name for the subroutine (example: level_control).
- Select the desired implementation language (e.g., LD – Ladder Diagram).
- Confirm the creation.
After that, the new POU will open for editing.
Figure 3. Creating a Program-type POU
Developing the logic in the subroutine
Within the created subroutine:
- Develop simple logic, such as:
- A contact activating a coil
- A control condition
- This logic will be isolated, executing only when the subroutine is called.
The subroutine does not execute automatically — it needs to be called in the main program.
Figure 4. Reversing the code line view
Calling the subroutine in UserPrg
To execute the subroutine:
- Open UserPrg.
- Create a new network.
- Insert an Empty Box with EN/ENO:
- By right-clicking on the network
- Through the Toolbox → General → Box with EN/ENO
- Click inside the empty box.
- Type the name of the subroutine exactly as it is the name of the created POU.
- Confirm.
MasterTool will recognize the name and automatically link it to the subroutine.
How the call works
- When the UserPrg logic enables the EN (Entering) option in the box:
- The subroutine will be executed
- When EN is FALSE:
- The subroutine will not be executed
The subroutine becomes part of the PLC cycle only when called.
Figure 5. Subroutine call via UserPrg
Advantages of using subroutines
- Project organization
- Logic reuse
- Ease of maintenance
- Better code readability
- Separation of responsibilities (e.g., control, alarms, communication)
Finalization and testing
After completion:
- Download the application.
- Put the CPU in RUN mode.
- Activate the logic that enables the subroutine call.
- Observe the operation of the POU's internal logic.
The use of folders and subroutines (POUs) is an essential best practice in larger projects, making development more organized, professional, and scalable.
Figure 6. Subroutine Operation
Comments
0 comments
Please sign in to leave a comment.