Difference between revisions of "OpenPLC-version1-with-LDmicro/C3/Compare-Instructions/English"
(Created page with " {| style="border-spacing:0;" | style="border:1pt solid #000000;padding:0.176cm;"| <center>'''Visual Cue'''</center> | style="border:1pt solid #000000;padding:0.176cm;"| <cent...") |
Nancyvarkey (Talk | contribs) |
||
Line 13: | Line 13: | ||
* Compare instructions | * Compare instructions | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn about working of | + | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn about working of '''Compare''' instructions |
− | + | ||
− | + | ||
|- | |- | ||
Line 72: | Line 70: | ||
They are | They are | ||
− | # Equals | + | # '''Equals''' |
− | # not equals | + | # '''not equals''' |
− | # less than | + | # '''less than''' |
− | # less than or equal | + | # '''less than or equal''' |
− | # greater than | + | # '''greater than''' |
− | # greater than or equal. | + | # '''greater than or equal'''. |
|- | |- | ||
Line 89: | Line 87: | ||
* Working of these instructions will be similar | * Working of these instructions will be similar | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| These instructions can be used to compare a variable to another variable. | + | | style="border:1pt solid #000000;padding:0.176cm;"| These instructions can be used to compare a '''variable''' to another '''variable'''. |
− | Also when we want to compare a variable to a 16-bit signed constant. | + | Also when we want to compare a '''variable''' to a '''16-bit''' signed '''constant'''. |
Working of these compare instructions will be similar. | Working of these compare instructions will be similar. | ||
− | But the functioning will be according to their names. | + | But the '''functioning''' will be according to their names. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial we’ll learn about compare for equals instruction in detail. | + | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial we’ll learn about '''compare for equals''' instruction in detail. |
|- | |- | ||
Line 107: | Line 105: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We will create a virtual circular counter using a compare for equals instruction. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We will create a '''virtual circular counter''' using a '''compare for equals''' instruction. |
|- | |- | ||
Line 119: | Line 117: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the contact >> Type switch in the name box >> Click OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the contact >> Type switch in the name box >> Click OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Rename the Contact as '''‘switch’'''. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Rename the '''Contact''' as '''‘switch’'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Double click on ADD | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on ADD | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on the '''ADD''' instruction. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the '''ADD''' instruction. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Type in the destination and ‘is set as := ‘ columns ‘vcounter’ | | style="border:1pt solid #000000;padding:0.176cm;"| Type in the destination and ‘is set as := ‘ columns ‘vcounter’ | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Set the destination and first operand to ‘'''vcounter’''' meaning virtual counter. | + | | style="border:1pt solid #000000;padding:0.176cm;"| '''Set''' the destination and first '''operand''' to ‘'''vcounter’''' meaning '''virtual counter'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click the OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Click the OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Second operand is by default 1. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Second '''operand''' is by default 1. |
Don’t change that. | Don’t change that. | ||
− | Click the OK button | + | Click the '''OK''' button |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click Edit -> Insert Rung after | | style="border:1pt solid #000000;padding:0.176cm;"| Click Edit -> Insert Rung after | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Insert a rung below as shown. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Insert a '''rung''' below as shown. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We will insert '''Compare for equals''' and '''Move''' instruction in the new rung. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We will insert '''Compare for equals''' and '''Move''' instruction in the new '''rung'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU >> place the cursor to the right of the contact >> Click Instructions -> Insert MOV | | style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU >> place the cursor to the right of the contact >> Click Instructions -> Insert MOV | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new rung . | + | | style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new '''rung'''. |
Click on '''Instructions''' and then '''Comparison operators.''' | Click on '''Instructions''' and then '''Comparison operators.''' | ||
Line 153: | Line 151: | ||
Select '''Insert EQU.''' | Select '''Insert EQU.''' | ||
− | Next place the cursor to the right of the compare for equals instruction. | + | Next place the cursor to the right of the '''compare for equals''' instruction. |
Click on '''Instructions''' and then select '''Insert MOV.''' | Click on '''Instructions''' and then select '''Insert MOV.''' | ||
Line 159: | Line 157: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Double click on Compare for equals >> Set the first column to vcounter >> Set the second column to 0 >> Click the OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on Compare for equals >> Set the first column to vcounter >> Set the second column to 0 >> Click the OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on '''Compare for equals.''' | + | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on '''Compare for equals.''' |
− | Compare the ‘'''vcounter’''' | + | Compare the ‘'''vcounter’ variable''' with 4. |
That is, set the first column to '''‘vcounter’''' and the second one to 4. | That is, set the first column to '''‘vcounter’''' and the second one to 4. | ||
− | Click on the OK button. | + | Click on the '''OK''' button. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the MOV instruction >> Type vcounter in the destination column >> Type 0 in the source column >> Click the OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the MOV instruction >> Type vcounter in the destination column >> Type 0 in the source column >> Click the OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on the '''Move''' instruction. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the '''Move''' instruction. |
− | Set the '''Destination''' | + | Set the '''Destination variable''' as '''‘vcounter’''' and '''Source variable''' as 0. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We will now check the working of this logic. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We will now check the working of this '''logic'''. |
|- | |- | ||
Line 181: | Line 179: | ||
Click Simulate -> Real-time simulation | Click Simulate -> Real-time simulation | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Let us turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| Let us turn '''ON''' the '''simulation mode'''. |
For that, click '''Simulate''' and then on '''Simulation mode.''' | For that, click '''Simulate''' and then on '''Simulation mode.''' | ||
− | Next, start real-time simulation as shown. | + | Next, start '''real-time simulation''' as shown. |
|- | |- | ||
Line 210: | Line 208: | ||
We can observe '''vcounter''' takes values 0, 1, 2, 3 and then goes back to 0. | We can observe '''vcounter''' takes values 0, 1, 2, 3 and then goes back to 0. | ||
− | That is like a circular counter with count 3. | + | That is like a '''circular counter''' with count 3. |
|- | |- | ||
Line 216: | Line 214: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| For visualization purpose we will glow a LED whenever the '''vcounter''' value is 0. | + | | style="border:1pt solid #000000;padding:0.176cm;"| For visualization purpose we will glow a '''LED''' whenever the '''vcounter''' value is 0. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click on Simulate >> Click Halt Simulation >> Click Simulation Mode | | style="border:1pt solid #000000;padding:0.176cm;"| Click on Simulate >> Click Halt Simulation >> Click Simulation Mode | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Now, turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| Now, turn '''OFF''' the '''simulation mode'''. |
For that, click '''Simulate''' and then on '''Halt Simulation.''' | For that, click '''Simulate''' and then on '''Halt Simulation.''' | ||
Line 230: | Line 228: | ||
Click Edit -> Insert rung after | Click Edit -> Insert rung after | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Insert a rung below the second rung. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Insert a '''rung''' below the second '''rung'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new rung >> Click on Instructions -> Comparison Operators -> Insert EQU >> Place the cursor to the right of EQU >> Click on Instructions -> Insert Coil | | style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor in the new rung >> Click on Instructions -> Comparison Operators -> Insert EQU >> Place the cursor to the right of EQU >> Click on Instructions -> Insert Coil | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Place a '''Compare for equals''' and a '''Coil''' in the new rung. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Place a '''Compare for equals''' and a '''Coil''' in the new '''rung'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on EQU instruction >> Type vcounter in the first box >> Type 0 in the second box >> Click OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on EQU instruction >> Type vcounter in the first box >> Type 0 in the second box >> Click OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on Compare for equals. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on '''Compare for equals'''. |
− | Compare the ‘'''vcounter’''' | + | Compare the ‘'''vcounter’ variable''' with 0. |
That is, set the first column to '''‘vcounter’''' and the second one to 0. | That is, set the first column to '''‘vcounter’''' and the second one to 0. | ||
− | Click on the OK button. | + | Click on the '''OK''' button. |
|- | |- | ||
Line 256: | Line 254: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Now let us compile the logic. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Now let us '''compile''' the '''logic'''. |
− | The detailed steps on how to compile and save the logic are explained in the earlier tutorials. | + | The detailed steps on how to '''compile''' and save the '''logic''' are explained in the earlier tutorials. |
|- | |- | ||
Line 264: | Line 262: | ||
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16 | Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16 | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Click on '''Settings''' and select the | + | | style="border:1pt solid #000000;padding:0.176cm;"| Click on '''Settings''' and select the '''microcontroller AVR ATmega16 40-PDIP.''' |
− | Adjust its parameters as shown here. | + | Adjust its '''parameters''' as shown here. |
|- | |- | ||
Line 272: | Line 270: | ||
Double-click on YLED in I/O list >> Select PA0 >> Click OK button | Double-click on YLED in I/O list >> Select PA0 >> Click OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Assign | + | | style="border:1pt solid #000000;padding:0.176cm;"| Assign '''pin PC0''' to '''Xswitch''' and '''PA0''' to '''YLED'''. |
|- | |- | ||
Line 278: | Line 276: | ||
Click OK button | Click OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Compile the logic as '''‘compareequals.hex’.''' | + | | style="border:1pt solid #000000;padding:0.176cm;"| '''Compile''' the '''logic''' as '''‘compareequals.hex’.''' |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘compareequals.ld’ >> Click on Save | | style="border:1pt solid #000000;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘compareequals.ld’ >> Click on Save | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Then save the ladder diagram as '''‘compareequals.ld’.''' | + | | style="border:1pt solid #000000;padding:0.176cm;"| Then save the '''ladder diagram''' as '''‘compareequals.ld’.''' |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We will now see the working of this logic on hardware. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We will now see the working of this '''logic''' on hardware. |
|- | |- | ||
Line 295: | Line 293: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Connect the '''Mainboard''' to your laptop using '''USBasp'''. | | style="border:1pt solid #000000;padding:0.176cm;"| Connect the '''Mainboard''' to your laptop using '''USBasp'''. | ||
− | Turn | + | Turn '''ON''' the '''power supply'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘'''avrdude -c usbasp -p m16 -U flash:w:compareequals.hex’ '''>> Press ENTER | | style="border:1pt solid #000000;padding:0.176cm;"| Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘'''avrdude -c usbasp -p m16 -U flash:w:compareequals.hex’ '''>> Press ENTER | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Open the Terminal by pressing '''CTRL+ALT+T''' keys simultaneously. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Open the '''Terminal''' by pressing '''CTRL+ALT+T''' keys simultaneously. |
− | Go to the folder where you have saved the hex file. | + | Go to the folder where you have saved the '''hex file'''. |
− | Type the command as shown to upload the hex file to the '''Mainboard'''. | + | Type the '''command''' as shown to upload the '''hex file''' to the '''Mainboard'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Remove the '''USBasp''' connection from the laptop. | | style="border:1pt solid #000000;padding:0.176cm;"| Remove the '''USBasp''' connection from the laptop. | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| Turn '''OFF''' the '''power supply'''. |
Remove the '''USBasp''' connection from the laptop. | Remove the '''USBasp''' connection from the laptop. | ||
Line 325: | Line 323: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| compareequals.png | | style="border:1pt solid #000000;padding:0.176cm;"| compareequals.png | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Connect '''GND''' and 5V of '''Switchboard''' to GND and 5V of the '''Mainboard''' respectively. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Connect '''GND''' and '''5V''' of '''Switchboard''' to GND and 5V of the '''Mainboard''' respectively. |
Then connect '''NO1''' of the '''Switchboard''' to '''PC0''' of the '''Mainboard'''. | Then connect '''NO1''' of the '''Switchboard''' to '''PC0''' of the '''Mainboard'''. | ||
Line 333: | Line 331: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| After making all the connections properly, turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| After making all the connections properly, turn '''ON''' the '''power supply'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We can observe that the LED will be glowing initially. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We can observe that the '''LED''' will be glowing initially. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| It will turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| It will turn '''OFF''' once the '''NO1''' is pressed. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| The red LED will glow again after pressing '''NO1''' for 3 more times. | + | | style="border:1pt solid #000000;padding:0.176cm;"| The red '''LED''' will glow again after pressing '''NO1''' for 3 more times. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Thus LED glow indicates that the count value of the counter is 0. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Thus '''LED''' glow indicates that the count value of the counter is 0. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Turn | + | | style="border:1pt solid #000000;padding:0.176cm;"| Turn '''OFF''' the '''power supply'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Try out the remaining Compare instructions on your own. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Try out the remaining '''Compare''' instructions on your own. |
|- | |- | ||
Line 372: | Line 370: | ||
* Compare instructions | * Compare instructions | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we learnt about | + | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we learnt about '''Compare''' instructions |
− | + | ||
− | + | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 8: Assignment | | style="border:1pt solid #000000;padding:0.176cm;"| Slide 8: Assignment | ||
Line 380: | Line 376: | ||
Try to | Try to | ||
− | # Turn | + | # Turn '''ON''' a '''LED''' whenever the '''count process''' is '''ON''' and |
− | # Turn | + | # Turn '''OFF''' when count value becomes zero |
− | Hint: Use '''‘greater than’ ''' | + | Hint: Use '''‘greater than’ compare''' instruction to turn '''ON''' the '''LED'''. |
| style="border:1pt solid #000000;padding:0.176cm;"| As an assignment, try to | | style="border:1pt solid #000000;padding:0.176cm;"| As an assignment, try to | ||
− | # Turn | + | # Turn '''ON''' a '''LED''' whenever the '''count process''' is '''ON''' and |
− | # Turn | + | # Turn '''OFF''' when count value becomes zero |
− | Hint: Use '''‘greater than’ ''' | + | Hint: Use '''‘greater than’ compare''' instruction to turn '''ON''' the '''LED'''. |
|- | |- |
Latest revision as of 13:46, 3 December 2020
|
|
Slide 1: | Welcome to the spoken tutorial on Compare instructions. |
Slide 2: Learning Objectives
|
In this tutorial, we will learn about working of Compare instructions |
Slide 3: System Requirements
|
To record this tutorial I am using:
|
Slide 4: Pre-requisites
|
|
Slide 5: Prerequisites - Hardware setup
hardware-prerequisite.jpg |
Connect SMPS and USBasp to the Mainboard as shown in the picture.
Keep these connections throughout this tutorial. |
Slide 6a: Compare instructions
Six types of compare instructions
|
In LDmicro we have six types of compare instructions.
They are
|
Slide 6b: Compare instructions
|
These instructions can be used to compare a variable to another variable.
Also when we want to compare a variable to a 16-bit signed constant. Working of these compare instructions will be similar. But the functioning will be according to their names. |
In this tutorial we’ll learn about compare for equals instruction in detail. | |
Open LDmicro | Let us open LDmicro. |
We will create a virtual circular counter using a compare for equals instruction. | |
Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click instructions -> Insert OSR >> Place the cursor to the right of OSR >> Click Instructions -> Arithmetic instructions -> Insert ADD | Insert a Contact.
To the right of it insert an OSR To the right of OSR insert an ADD instruction as shown here. |
Double-click on the contact >> Type switch in the name box >> Click OK button | Rename the Contact as ‘switch’. |
Double click on ADD | Double-click on the ADD instruction. |
Type in the destination and ‘is set as := ‘ columns ‘vcounter’ | Set the destination and first operand to ‘vcounter’ meaning virtual counter. |
Click the OK button | Second operand is by default 1.
Don’t change that. Click the OK button |
Click Edit -> Insert Rung after | Insert a rung below as shown. |
We will insert Compare for equals and Move instruction in the new rung. | |
Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU >> place the cursor to the right of the contact >> Click Instructions -> Insert MOV | Place the cursor in the new rung.
Click on Instructions and then Comparison operators. Select Insert EQU. Next place the cursor to the right of the compare for equals instruction. Click on Instructions and then select Insert MOV. |
Double click on Compare for equals >> Set the first column to vcounter >> Set the second column to 0 >> Click the OK button | Double-click on Compare for equals.
Compare the ‘vcounter’ variable with 4. That is, set the first column to ‘vcounter’ and the second one to 4. Click on the OK button. |
Double-click on the MOV instruction >> Type vcounter in the destination column >> Type 0 in the source column >> Click the OK button | Double-click on the Move instruction.
Set the Destination variable as ‘vcounter’ and Source variable as 0. |
We will now check the working of this logic. | |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Let us turn ON the simulation mode.
For that, click Simulate and then on Simulation mode. Next, start real-time simulation as shown. |
Highlight the state of Xswitch and counter in the I/O list | Initially, the state of Xswitch and vcounter are 0. |
Double-click on ‘Xswitch’ | Change the state of Xswitch to 1. |
Highlight the state of vcounter | We can observe the state of vcounter changes to 1.
The state of vcounter increases by 1 every time there is a high to low transition in Xswitch. |
Double-click on ‘Xswitch’ for 5 more times
Highlight the state of vcounter. |
Keep changing the state of Xswitch from 0 to 1 and back to 0.
We can observe vcounter takes values 0, 1, 2, 3 and then goes back to 0. That is like a circular counter with count 3. |
For visualization purpose we will glow a LED whenever the vcounter value is 0. | |
Click on Simulate >> Click Halt Simulation >> Click Simulation Mode | Now, turn OFF the simulation mode.
For that, click Simulate and then on Halt Simulation. Then click Simulate and Simulation Mode. |
Visual cue
Click Edit -> Insert rung after |
Insert a rung below the second rung. |
Place the cursor in the new rung >> Click on Instructions -> Comparison Operators -> Insert EQU >> Place the cursor to the right of EQU >> Click on Instructions -> Insert Coil | Place a Compare for equals and a Coil in the new rung. |
Double-click on EQU instruction >> Type vcounter in the first box >> Type 0 in the second box >> Click OK button | Double-click on Compare for equals.
Compare the ‘vcounter’ variable with 0. That is, set the first column to ‘vcounter’ and the second one to 0. Click on the OK button. |
Double-click on Ynew >> Type LED in the name box >> Select SET-only option >> Click OK button | Rename the Coil as LED. |
Highlight the third rung | Thus this will energise the YLED whenever the vcounter value is 0. |
Now let us compile the logic.
The detailed steps on how to compile and save the logic are explained in the earlier tutorials. | |
Click on Settings >> Click on Microcontroller >> Select AVR ATmega16 40-PDIP
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16 |
Click on Settings and select the microcontroller AVR ATmega16 40-PDIP.
Adjust its parameters as shown here. |
Double-click on Xswitch in I/O list >> Select PC0 >> Click OK button
Double-click on YLED in I/O list >> Select PA0 >> Click OK button |
Assign pin PC0 to Xswitch and PA0 to YLED. |
Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘compareequals.hex’ >> Click on Save.
Click OK button |
Compile the logic as ‘compareequals.hex’. |
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘compareequals.ld’ >> Click on Save | Then save the ladder diagram as ‘compareequals.ld’. |
We will now see the working of this logic on hardware. | |
Connect Mainboard to PC using USBasp
laptop-usbasp.jpg |
Connect the Mainboard to your laptop using USBasp.
Turn ON the power supply. |
Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘avrdude -c usbasp -p m16 -U flash:w:compareequals.hex’ >> Press ENTER | Open the Terminal by pressing CTRL+ALT+T keys simultaneously.
Go to the folder where you have saved the hex file. Type the command as shown to upload the hex file to the Mainboard. |
Remove the USBasp connection from the laptop. | Turn OFF the power supply.
Remove the USBasp connection from the laptop. This will prevent any hardware damage. |
compareequals.png | Let us see the connection details now. |
compareequals.png | Connect GND pin of the red LED of Traffic Light module to GND of the Mainboard.
Then connect +5V pin of the red LED to PA0 pin of the Mainboard. |
compareequals.png | Connect GND and 5V of Switchboard to GND and 5V of the Mainboard respectively.
Then connect NO1 of the Switchboard to PC0 of the Mainboard. Make the connections as shown in the picture. |
After making all the connections properly, turn ON the power supply. | |
We can observe that the LED will be glowing initially. | |
It will turn OFF once the NO1 is pressed. | |
The red LED will glow again after pressing NO1 for 3 more times. | |
Thus LED glow indicates that the count value of the counter is 0. | |
Turn OFF the power supply. | |
Try out the remaining Compare instructions on your own. | |
This brings us to the end of this tutorial.
Let us summarize. | |
Slide 7: Summary
In this tutorial, we learnt about
|
In this tutorial, we learnt about Compare instructions |
Slide 8: Assignment
Try to
Hint: Use ‘greater than’ compare instruction to turn ON the LED. |
As an assignment, try to
Hint: Use ‘greater than’ compare instruction to turn ON the LED. |
Slide 9:
About Spoken Tutorial project |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
Slide 10:
Spoken Tutorial workshops |
The Spoken Tutorial Project team:
For more details, please write to us |
Slide 11:
Forum for specific questions: |
|
Slide 12:
Forum for specific questions: |
Do you have any general / technical questions on OpenPLC?
Please visit the FOSSEE forum and post your question. |
Slide 13:
Acknowledgement |
Spoken Tutorial Project is funded by MHRD, Government of India |
Slide 14:
Thank you slide |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
And this is Harsha Priyanka from FOSSEE team, signing off. Thanks for watching. |