Article translated with the assistance of AI tools. Images and parts of the content will still be reviewed.
In this tutorial, you will learn the guidelines and procedures to simulate a traffic light in Ladder and represent it on Webvisu, a feature of the XP340.
Components
Software: MasterTool IEC XE 3.40
PLC: XP340
Tutorial Sections
1. ARCHITECTURE
2. DEVELOPMENT
2.1. Creating a new project in Mastertool
2.2. Naming the digital inputs and outputs in Integrated I/O
2.3. Building the logic
2.4. Inserting the utility library in Library Manager
2.5. Adding the Webserver to the project
2.6. Configuring the screen in Webvisu
2.7. Simulating the application
1. ARCHITECTURE
2. DEVELOPMENT
When the switch is ON, the logic will start with the red lamp, after 3 seconds it will turn off and turn on the green lamp, after 4 seconds it will turn off and go to the yellow state, and after 2 seconds it will restart going back to the red state; When the switch is OFF, the yellow lamp will keep blinking.
The project simulation can be accessed through the link below:
https://drive.google.com/file/d/1kI7Qc8yTGfhitk1AaGQuUUUMsKnNZzy2/view?usp=sharing
2.1. Creating a new project in Mastertool
Create a new project by clicking on "New Project", enter the name and the folder path where you want to save it.
For this simulation with mastertool and webvisu, we will use the XP 340 and the programming language in LADDER. Click next, making sure all languages are set to ladder until "FINISH" appears, and then the program will open.
2.2. Naming the digital inputs and outputs in Integrated I/O
We will map the inputs and outputs; in Integrated I/O we will name the digital inputs and outputs to make programming easier.
2.3. Building the logic
In UserPrg, select the network (line) and click on the normally open contact to start our logic (this step will be repeated several times during the program).
After inserting the contact, select an empty box and drag it to the logic.
Inside this empty box, type "TON" to instantiate the timer block. Double-click the Enter key and declare it as "TEMPO_VM", because this will be the red lamp timer.
The parameterization of the "TON" function block is done as follows:
Inputs:
IN: Condition that activates the block's counting
PT: Pre-set time for triggering the timer output.
Outputs:
Q: Output bit that is activated at the end of the time set in PT.
ET: Shows the current value of the count on the timer.
In our project, we will define the block input as "CHAVE_ON_OFF" which, as described in section 2.2 of this tutorial, corresponds to digital input I0.
After defining this block input parameter, we will set the time that the red lamp will stay active and erase the question marks that are at the ET output. This step will be repeated for all timers.
Add a new network to start the logic of the outputs that will activate the lamps.
To create the logic that will turn on the red lamp, we will have a normally open contact (1), a normally closed contact (2), and a coil for the lamp (3).
Name the contacts: the first contact will confirm that the switch is on, the second is confirmation that the red lamp's time has not finished counting, and finally, the red lamp coil will be placed.
Logic explanation: With confirmation that the switch is on and confirmation that the time has not yet finished counting, the lamp will stay on. When the time is up or the switch changes state to OFF, the lamp will turn off.
This step will be repeated several times, only increasing the time for turning off the lamp, so the logic is common for all lamp activations in the traffic light.
Add a new line above the last one and then repeat the logic as shown in the image below.
When the "Q" output of the "TEMPO_VM" timer is activated, the green lamp timer will start counting and will activate the green lamp when the "Q" output of the "TEMPO_VD" timer is activated.
Add a line below the last output line and create the logic to turn the green lamp on and off as shown above. In this line, the logic is that the switch is ON and the Tempo_vm has already been counted (so the red lamp has already turned on and off), and when the Tempo_VD is counted, it will open the contact, turning off the green lamp.
Repeat the same sequence for activating the yellow lamp, with the difference that the timer for this lamp will be activated by the green lamp timer, the last lamp active before it.
In this line, the logic is that the switch is ON, the Tempo_vm has already been counted (so the red lamp has already turned on and off), the Tempo_VD has also been counted (the green lamp has already turned on and off), and when the Tempo_Am is counted, the normally closed contact will open and turn off the yellow lamp.
To reset the cycle, select the line between the switch contact and the timer (network 1) and add a normally closed contact from the Tempo_AM output.
When the "Q" output of the "TEMPO_AM" timer is activated, it will turn off the lamp and reset the time memories that remained on, activating all timers during the process, allowing the cycle to restart.
To keep the yellow lamp blinking while the traffic light is inactive, you need to add an oscillator block named "BLINK". This can be used after adding the utility library to the Mastertool project.
2.4. Inserting the utility library in Library Manager
Open the Library manager, click on "Add library", go to Application > Common > Util.
To insert the "BLINK" block into the yellow lamp activation logic, select the first contact and, holding the "shift" key on the keyboard, select the last contact in the yellow lamp's command line. Then click to insert a parallel normally closed contact.
Select the part before the contact and insert an empty box. Then delete the normally open contact that appears at the box's enable input.
In the field inside the empty box, erase the question marks and type the word BLINK, then press ENTER twice. You can also click on the white rectangle to open the submenu Function blocks >> Util >> Signals >> double-click on Blink.
The parameterization of the "BLINK" function block is as follows:
Inputs:
ENABLE: Condition that enables the block
TIMELOW: Time off in time format. Ex: t#2s;
TIMEHIGH: Time on in time format. Ex: t#2s;
Outputs:
OUT: Boolean output that keeps oscillating.
After adding the blink block and deleting the normally open contact that appears with it, enter the time in the block and in the normally closed contact name it CHAVE ON/OFF because when the switch is off the block will be active and the lamp will blink.
2.5. Adding the Webserver to the project
To add the Webserver, right-click on Application > Add object > Visualization.
It is possible to change the name of the visualization. It is important to activate VisuSymbols (System) with the checkbox above. After the visualization is added, you can choose the styles of the pre-defined components in Visualization Manager.
In WebVisu, click on the "..." and a tab will open where you should select the screen where the graphical visualization will be built. Then click OK as shown below.
In the tab that opens, click on categories >> project visualization >> Visualization (or the name you gave the screen) >> OK.
Returning to the Visualization screen, click on the Visualization toolbox, open the Lamp/Switches/Bitmaps tab, add an "On/Off" switch and drag it to the screen.
,
The Button configuration is done in the Properties tab at the bottom right of the screen, then click on variable and type the name of the variable CHAVE_ON_OFF.
When typing the variable name CHAVE_ON_OFF, select it and press ENTER twice, or you can click on the "..." next to the input box and navigate to find the variable.
To insert an image in the visualization screen, right-click on Application >> add object >> Image table. A window will open, click on add.
After adding the image table, go to the tab, then click below the "file name" field, choose the option "include in project" and in the "...", enter the path of the image you want. Finally, click ok.
In the "Visualization" tab, click on "Visualization toolbox", click on the "Image Pool" option. This option will open the images that have been added to the project, finally select the image and drag it to the screen.
After inserting the image, in the Properties >> Position tab, you can change the position and size of the image.
Still in the Visualization tab, click on Visualization ToolBox >> Lamps/switches/Bitmaps >> select Lamp 1, and drag it to the screen, overlaying the image of one of the traffic light lamps.
Repeat the process for the three traffic light lamps.
Change the color of the lamps to the respective color of the traffic light in Properties > Background. Repeat the process for each object.
To associate them with a variable, go to Properties > Position > Variable. Repeat the process for all traffic light lamps.
To check the operation, just select the simulation option in Communication > Simulation and then log in at Communication > Login.
As designed, if the digital input I0 is not activated or is false indicating that the process has been turned off, the yellow lamp blinks due to the Blink block. If the input is activated, the lamps transition as in a real traffic light: Red > Green > Yellow > Red.
IMPORTANT: For the attached files to work properly, it is essential to download all of them to the same folder before extracting the main file (ZIP).
Comments
0 comments
Please sign in to leave a comment.