Difference between revisions of "OpenPLC-version1-with-LDmicro/C2/Implementing-OR-and-XOR-logic-gates/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(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...")
 
 
(2 intermediate revisions by one other user not shown)
Line 16: Line 16:
 
* XOR
 
* XOR
  
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will implement '''OR & XOR '''logic gates in '''LDmicro'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will implement '''OR & XOR logic gates''' in '''LDmicro'''.
  
 
|-
 
|-
Line 45: Line 45:
 
* Negated Contact and Coil
 
* Negated Contact and Coil
  
If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]
 
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
* To follow this tutorial, you should know the working of  
 
* To follow this tutorial, you should know the working of  
 
 
# '''Normal Contact''' and '''Coil'''
 
# '''Normal Contact''' and '''Coil'''
 
# '''Negated Contact''' and '''Coil'''
 
# '''Negated Contact''' and '''Coil'''
Line 65: Line 63:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
| style="border:1pt solid #000000;padding:0.176cm;"| First we will see how to implement OR gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| First we will see how to implement '''OR gate'''.
  
 
|-
 
|-
Line 71: Line 69:
  
 
'''OR''' gate outputs 0 only when all of its inputs are 0
 
'''OR''' gate outputs 0 only when all of its inputs are 0
| style="border:1pt solid #000000;padding:0.176cm;"| We know that '''OR''' gate outputs 0 only when all of its inputs are 0.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We know that '''OR gate''' outputs 0 only when all of its inputs are 0.
  
 
|-
 
|-
Line 80: Line 78:
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Instructions -> Insert Contact
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Instructions -> Insert Contact
  
Place the cursor to the right of Xnew >> Click Instructions -> Insert Coil
+
Place the cursor to the right of Xnew >>  
 +
Click Instructions -> Insert Coil
 
| style="border:1pt solid #000000;padding:0.176cm;"| Insert a '''Contact''' and a '''Coil''' as shown.
 
| style="border:1pt solid #000000;padding:0.176cm;"| Insert a '''Contact''' and a '''Coil''' as shown.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xnew >> Type ‘switch1’ in the name box >> Click OK button  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xnew
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the Contact as '''‘switch1’.'''
+
>> Type ‘switch1’ in the name box  
 
+
>> Click OK button  
 +
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the '''Contact''' as '''‘switch1’.'''
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Ynew >> Type ‘LED’ in the name box >> Click OK button  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Ynew  
| style="border:1pt solid #000000;padding:0.176cm;"| Then, rename the Coil as '''‘LED’.'''
+
>> Type ‘LED’ in the name box  
 +
>> Click OK button  
 +
| style="border:1pt solid #000000;padding:0.176cm;"| Then, rename the '''Coil''' as '''‘LED’.'''
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the below Xswitch1 >> Click Instructions -> Insert Contact
+
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the below Xswitch1
| style="border:1pt solid #000000;padding:0.176cm;"| Now place the cursor below '''Xswitch1 '''and insert a Contact.
+
>> Click Instructions -> Insert Contact
 +
| style="border:1pt solid #000000;padding:0.176cm;"| Now place the cursor below '''Xswitch1 '''and insert a '''Contact'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xnew >> Type ‘switch2’ in the name box >> Click OK button
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xnew  
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the new Contact as '''’switch2’'''.
+
>> Type ‘switch2’ in the name box  
 +
>> Click OK button
 +
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the new '''Contact''' as '''’switch2’'''.
  
 
|-
 
|-
 
| 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'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Simulation mode >> Click Simulate -> Real-time simulation
+
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Simulation mode  
| style="border:1pt solid #000000;padding:0.176cm;"| Let us turn on the simulation mode.
+
>> Click Simulate -> Real-time simulation
 +
| 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.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight the state of Xswitch and YLED
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight the state of Xswitch and YLED
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the states of both the Contacts and Coil are 0.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the states of both the '''Contacts''' and '''Coil''' are 0.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1 >> Highlight the state of the ‘YLED' >> Double-click on Xswitch1  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1 >> Highlight the state of the ‘YLED'
 +
>> Double-click on Xswitch1  
 
| style="border:1pt solid #000000;padding:0.176cm;"| Change the state of '''Xswitch1''' to 1.
 
| style="border:1pt solid #000000;padding:0.176cm;"| Change the state of '''Xswitch1''' to 1.
  
Line 125: Line 132:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch2 >> Highlight the state of the ‘YLED'
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch2  
 +
>> Highlight the state of the ‘YLED'
 
| style="border:1pt solid #000000;padding:0.176cm;"| Now, change the state of '''Xswitch2''' to 1.
 
| style="border:1pt solid #000000;padding:0.176cm;"| Now, change the state of '''Xswitch2''' to 1.
  
Line 131: Line 139:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1 >> Highlight the state of the ‘YLED'
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1
 +
>> Highlight the state of the ‘YLED'
 
| style="border:1pt solid #000000;padding:0.176cm;"| Now again change the state of '''Xswitch1''' to 1.
 
| style="border:1pt solid #000000;padding:0.176cm;"| Now again change the state of '''Xswitch1''' to 1.
  
Line 140: Line 149:
 
| style="border:1pt solid #000000;padding:0.176cm;"| That is, output state is 0 only when both the inputs states are 0.
 
| style="border:1pt solid #000000;padding:0.176cm;"| That is, output state is 0 only when both the inputs states are 0.
  
Thus, resembling the truth table of an '''OR''' gate.
+
Thus, resembling the '''truth table''' of an '''OR gate'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode
+
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Halt Simulation
| style="border:1pt solid #000000;padding:0.176cm;"| Now, turn off the simulation mode.
+
>> Click Simulate -> Simulation Mode
 +
| 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 152: Line 162:
 
|-
 
|-
 
| 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.  
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Click on Settings >> Click on Microcontroller >> Select AVR ATmega16 40-PDIP  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Click on Settings >> Click on Microcontroller
 +
>> Select AVR ATmega16 40-PDIP  
  
 +
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 '''microcontroller AVR ATmega16 40-PDIP.'''
  
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16
+
Adjust its '''parameters''' as shown here.
| 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.
+
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1 in the I/O list>> Select PC0 >> Click OK button
+
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Xswitch1 in the I/O list>> Select PC0
 
+
>> Click OK button
 
+
Double-click on Xswitch2 in the I/O list  
Double-click on Xswitch2 in the I/O list >> Select PC1 >> Click OK button
+
>> Select PC1 >> Click OK button
  
  
 
Double-click on YLED in the I/O list>> Select PA0 >> Click OK button
 
Double-click on YLED in the I/O list>> Select PA0 >> Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Assign pin '''PC0''' to '''Xswitch1''' and '''PC1''' to '''Xswitch2'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Assign '''pin PC0''' to '''Xswitch1''' and '''PC1''' to '''Xswitch2'''.
  
 
Assign '''PA0''' to '''YLED.'''
 
Assign '''PA0''' to '''YLED.'''
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Compile
| style="border:1pt solid #000000;padding:0.176cm;"| Compile the logic as '''‘orgate.hex’'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| '''Compile''' the '''logic''' as '''‘orgate.hex’'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Save the file
 
| style="border:1pt solid #000000;padding:0.176cm;"| Save the file as '''‘orgate.ld’''' as shown.
 
| style="border:1pt solid #000000;padding:0.176cm;"| Save the file as '''‘orgate.ld’''' 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;"| Now we will see the working of this logic on hardware.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Now we will see the working of this '''logic''' on hardware.
  
 
|-
 
|-
Line 197: Line 209:
 
| 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 on the power supply.
+
Turn '''on''' the '''power supply'''.
  
 
|-
 
|-
Line 204: Line 216:
  
 
type ‘'''avrdude -c usbasp -p m16 -U flash:w:orgate.hex’ '''>> Press ENTER
 
type ‘'''avrdude -c usbasp -p m16 -U flash:w:orgate.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 off the power supply.
+
| 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 219: Line 231:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| orgate.png
+
| style="border:1pt solid #000000;padding:0.176cm;"| Display the image orgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| Let us see the connection details now.  
 
| style="border:1pt solid #000000;padding:0.176cm;"| Let us see the connection details now.  
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| orgate.png
+
| style="border:1pt solid #000000;padding:0.176cm;"| Display the image orgate.png
| style="border:1pt solid #000000;padding:0.176cm;"| Connect '''GND pin''' of the red LED of '''Traffic Light module''' to '''GND''' pin of the '''Mainboard'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Connect '''GND pin''' of the red '''LED''' of '''Traffic Light module''' to '''GND pin''' of the '''Mainboard'''.
  
Then connect the '''+5V''' pin of the red LED to '''PA0''' pin of the '''Mainboard'''.
+
Then connect the '''+5V pin''' of the red '''LED''' to '''PA0 pin''' of the '''Mainboard'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| orgate.png
+
| style="border:1pt solid #000000;padding:0.176cm;"| Display the image orgate.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.
  
 
Connect '''NO1''' to '''PC0''' of the '''Mainboard'''.
 
Connect '''NO1''' to '''PC0''' of the '''Mainboard'''.
Line 239: Line 251:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Switch on the power
| style="border:1pt solid #000000;padding:0.176cm;"| Turn on the power supply.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''on''' the '''power supply'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Point to red LED
| style="border:1pt solid #000000;padding:0.176cm;"| We can see that the red LED is off initially.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We can see that the red '''LED''' is '''off''' initially.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Press any one switch
| style="border:1pt solid #000000;padding:0.176cm;"| It will start glowing when either one of the switches is pressed.
+
  
It will also glow when both of the switches are pressed at the same time.
+
Press both the switches
 +
| style="border:1pt solid #000000;padding:0.176cm;"| It will start glowing when either one of the '''switches''' is pressed.
 +
 
 +
It will also glow when both of the '''switches''' are pressed at the same time.
  
 
|-
 
|-
 
| 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, for an '''OR''' gate the inputs i.e. Contacts should be parallel to each other.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Thus, for an '''OR gate''' the inputs i.e. '''Contacts''' should be parallel to each other.
  
The output i.e. Coil should be in series with both the inputs.
+
The output i.e. '''Coil''' should be in series with both the inputs.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Switch off the power
| style="border:1pt solid #000000;padding:0.176cm;"| Turn off the power supply.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''off''' the '''power supply'''.
  
 
Remove the connections made for this example.
 
Remove the connections made for this example.
Line 266: Line 280:
 
|-
 
|-
 
| 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 learn about '''XOR''' gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We will now learn about '''XOR gate'''.
  
 
|-
 
|-
Line 273: Line 287:
 
Boolean equation:
 
Boolean equation:
  
A’B+A’B - (('''NOT''' A) '''AND''' B) '''OR''' (A '''AND''' ('''NOT''' B))
+
*A’B+A’B - (('''NOT''' A) '''AND''' B) '''OR''' (A '''AND''' ('''NOT''' B))
  
It is a combination of NOT, AND and OR gates
+
*It is a combination of NOT, AND and OR gates
| style="border:1pt solid #000000;padding:0.176cm;"| We know the boolean equation of an '''XOR''' gate with inputs A and B will be AB’+A’B.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We know the '''boolean''' equation of an '''XOR gate''' with inputs '''A''' and '''B''' will be '''AB’+A’B'''.
  
Thus it is a combination of '''NOT''', '''AND''' and '''OR''' gates.
+
Thus it is a combination of '''NOT''', '''AND''' and '''OR gates'''.
  
 
|-
 
|-
Line 302: Line 316:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Place cursor to the right of Xswitch2 >> Click Instructions -> Insert Contact >> Double-click on Xnew >> Check the Negated box >> Type switch1 in the name box >> Click OK button
 
| style="border:1pt solid #000000;padding:0.176cm;"| Place cursor to the right of Xswitch2 >> Click Instructions -> Insert Contact >> Double-click on Xnew >> Check the Negated box >> Type switch1 in the name box >> Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Then insert a Contact to the right of '''Xswitch2 '''which is in the parallel rung.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Then insert a '''Contact''' to the right of '''Xswitch2 '''which is in the parallel rung.
  
 
Configure it as '''Negated''' and rename it as '''switch1''' as shown.
 
Configure it as '''Negated''' and rename it as '''switch1''' as shown.
Line 308: Line 322:
 
|-
 
|-
 
| 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'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Simulation mode >> Click Simulate -> Real-time simulation
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Simulation mode >> Click Simulate -> Real-time simulation
| style="border:1pt solid #000000;padding:0.176cm;"| Start real-time simulation as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Start '''real-time simulation''' as shown.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight the state of Xswitch and YLED
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight the state of Xswitch and YLED
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the state of both the Contacts and Coil are 0.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the state of both the '''Contacts''' and '''Coil''' are 0.
  
 
|-
 
|-
Line 342: Line 356:
 
| style="border:1pt solid #000000;padding:0.176cm;"| That is the output state is 0 when both the inputs have the same state.
 
| style="border:1pt solid #000000;padding:0.176cm;"| That is the output state is 0 when both the inputs have the same state.
  
Thus, resembling the truth table of an '''XOR''' gate.
+
Thus, resembling the '''truth table''' of an '''XOR gate'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode
| style="border:1pt solid #000000;padding:0.176cm;"| Turn off the simulation mode as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''off''' the '''simulation mode''' 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;"| Now let us compile the logic.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Now let us '''compile''' the '''logic'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight I/O list and status bar
 
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight I/O list and status bar
| style="border:1pt solid #000000;padding:0.176cm;"| We can observe that the microcontroller and its parameters are already set.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We can observe that the '''microcontroller''' and its '''parameters''' are already set.
  
Pin assignment is also already done.
+
'''Pin''' assignment is also already done.
  
 
|-
 
|-
Line 365: Line 379:
  
 
Click OK button
 
Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Compile the logic as '''xorgate.hex '''using '''‘Compile As’''' option.
+
| style="border:1pt solid #000000;padding:0.176cm;"| '''Compile''' the '''logic''' as '''xorgate.hex '''using '''‘Compile As’''' option.
  
 
|-
 
|-
Line 371: Line 385:
  
 
Rename it as ‘xorgate.ld’ >> Click on Save
 
Rename it as ‘xorgate.ld’ >> Click on Save
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the ladder diagram as '''‘xorgate.ld’''' using''' '''the '''‘Save As’ '''option.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the '''ladder diagram''' as '''‘xorgate.ld’''' using the '''‘Save As’ '''option.
  
 
|-
 
|-
 
| 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 we will see the working of this logic on hardware.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Now we will see the working of this '''logic''' on hardware.
  
 
|-
 
|-
Line 385: Line 399:
 
| 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 on the power supply.
+
Turn '''on''' the '''power supply'''.
  
 
|-
 
|-
Line 392: Line 406:
  
 
type ‘'''avrdude -c usbasp -p m16 -U flash:w:xorgate.hex’ '''>> Press ENTER
 
type ‘'''avrdude -c usbasp -p m16 -U flash:w:xorgate.hex’ '''>> Press ENTER
| style="border:1pt solid #000000;padding:0.176cm;"| Switch back to the terminal.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Switch back to the '''terminal'''.
  
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 off the power supply.
+
| 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 405: Line 419:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| xorgate.png
+
| style="border:1pt solid #000000;padding:0.176cm;"| Display the image xorgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| Let us see the connection details now.  
 
| style="border:1pt solid #000000;padding:0.176cm;"| Let us see the connection details now.  
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| xorgate.png
+
| style="border:1pt solid #000000;padding:0.176cm;"| Display the image xorgate.png
  
 +
Switch on the power
  
 +
| style="border:1pt solid #000000;padding:0.176cm;"| The connections will be same as in the '''OR gate '''example.
  
| style="border:1pt solid #000000;padding:0.176cm;"| The connections will be same as in the '''OR''' '''gate '''example.
+
Turn '''on''' the '''power supply'''.
 
+
Turn on the power supply.
+
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Point to red LED
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the red LED is off.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Initially the red '''LED''' is '''off'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Press any one switch >> Press both the switches
| style="border:1pt solid #000000;padding:0.176cm;"| It will start glowing only when either of the switches are pressed, but not both.
+
| style="border:1pt solid #000000;padding:0.176cm;"| It will start glowing only when either of the '''switches''' are pressed, but not both.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Switch off the power
| style="border:1pt solid #000000;padding:0.176cm;"| Turn off the power supply.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''off''' the '''power supply'''.
  
 
|-
 
|-
Line 443: Line 457:
 
* XOR  
 
* XOR  
  
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial we learnt to implement logic gates  
+
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial we learnt to implement '''logic gates'''
  
* OR and
+
* '''OR''' and
* XOR
+
* '''XOR'''
  
 
|-
 
|-
Line 452: Line 466:
  
 
Implement 2 input XNOR logic gate
 
Implement 2 input XNOR logic gate
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| As an assignment, try to implement 2 input '''XNOR''' logic gate.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| As an assignment, try to implement 2 input '''XNOR logic gate'''.
  
Truth table of XNOR gate is shown here
+
'''Truth table''' of '''XNOR gate''' is shown here.
  
 
|-
 
|-
Line 479: Line 493:
  
 
Forum for specific questions:
 
Forum for specific questions:
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Please post your timed queries in this forum
* Please post your timed queries in this forum
+
 
+
 
+
  
 
|-
 
|-
Line 488: Line 499:
  
 
Forum for specific questions:
 
Forum for specific questions:
| style="border:1pt solid #000000;padding:0.176cm;"| Do you have any general / technical questions on OpenPLC?
+
| style="border:1pt solid #000000;padding:0.176cm;"|  
 +
*Do you have any general / technical questions on OpenPLC?
  
Please visit the FOSSEE forum and post your question.
+
*Please visit the FOSSEE forum and post your question.
  
 
|-
 
|-

Latest revision as of 06:10, 30 October 2020

Visual Cue
Narration
Slide 1: Welcome to the spoken tutorial on Implementing OR & XOR logic gates.
Slide 2: Learning Objectives

How to implement logic gates

  • OR
  • XOR
In this tutorial, we will implement OR & XOR logic gates in LDmicro.
Slide 3: System Requirements
  • Ubuntu 18.04 OS
  • LDmicro
  • OpenPLC version 1 Mainboard
  • 24V, 2A SMPS
  • USBasp programmer
  • Traffic Light module
  • Switchboard module
To record this tutorial I am using:
  • Ubuntu Linux 18.04 operating system
  • LDmicro
  • OpenPLC version1 Mainboard
  • 24V, 2A SMPS
  • USBasp programmer
  • Traffic Light module and
  • Switchboard module
Slide 4: Pre-requisites
  • Normal Contact and Coil
  • Negated Contact and Coil
  • To follow this tutorial, you should know the working of
  1. Normal Contact and Coil
  2. Negated Contact and Coil
  • If not, please refer to the relevant tutorials in this series on this website.
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.

First we will see how to implement OR gate.
Slide 6: OR gate

OR gate outputs 0 only when all of its inputs are 0

We know that OR gate outputs 0 only when all of its inputs are 0.
Open LDmicro Let us open LDmicro.
Click Instructions -> Insert Contact

Place the cursor to the right of Xnew >> Click Instructions -> Insert Coil

Insert a Contact and a Coil as shown.
Double-click on Xnew

>> Type ‘switch1’ in the name box >> Click OK button

Rename the Contact as ‘switch1’.
Double-click on Ynew

>> Type ‘LED’ in the name box >> Click OK button

Then, rename the Coil as ‘LED’.
Place the cursor to the below Xswitch1

>> Click Instructions -> Insert Contact

Now place the cursor below Xswitch1 and insert a Contact.
Double-click on Xnew

>> Type ‘switch2’ in the name box >> Click OK button

Rename the new Contact as ’switch2’.
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 YLED Initially the states of both the Contacts and Coil are 0.
Double-click on Xswitch1 >> Highlight the state of the ‘YLED'

>> Double-click on Xswitch1

Change the state of Xswitch1 to 1.

We can observe the state of YLED is 1.

Change the state of Xswitch1 back to 0.

Double-click on Xswitch2

>> Highlight the state of the ‘YLED'

Now, change the state of Xswitch2 to 1.

We can observe the state of YLED is 1.

Double-click on Xswitch1

>> Highlight the state of the ‘YLED'

Now again change the state of Xswitch1 to 1.

We can observe that the state of YLED is 1.

That is, output state is 0 only when both the inputs states are 0.

Thus, resembling the truth table of an OR gate.

Click Simulate -> Halt Simulation

>> Click Simulate -> Simulation Mode

Now, turn off the simulation mode.

For that, click Simulate and then on Halt Simulation.

Then click Simulate and Simulation Mode.

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 Xswitch1 in the I/O list>> Select PC0

>> Click OK button Double-click on Xswitch2 in the I/O list >> Select PC1 >> Click OK button


Double-click on YLED in the I/O list>> Select PA0 >> Click OK button

Assign pin PC0 to Xswitch1 and PC1 to Xswitch2.

Assign PA0 to YLED.

Compile Compile the logic as ‘orgate.hex’.
Save the file Save the file as ‘orgate.ld’ as shown.
Now we will 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:orgate.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.

Display the image orgate.png Let us see the connection details now.
Display the image orgate.png Connect GND pin of the red LED of Traffic Light module to GND pin of the Mainboard.

Then connect the +5V pin of the red LED to PA0 pin of the Mainboard.

Display the image orgate.png Connect GND and 5V of Switchboard to GND and 5V of the Mainboard respectively.

Connect NO1 to PC0 of the Mainboard.

Connect NO2 to PC1 of the Mainboard.

Make the connections as shown in the picture.

Switch on the power Turn on the power supply.
Point to red LED We can see that the red LED is off initially.
Press any one switch

Press both the switches

It will start glowing when either one of the switches is pressed.

It will also glow when both of the switches are pressed at the same time.

Thus, for an OR gate the inputs i.e. Contacts should be parallel to each other.

The output i.e. Coil should be in series with both the inputs.

Switch off the power Turn off the power supply.

Remove the connections made for this example.

We will now learn about XOR gate.
Slide 6: XOR gate

Boolean equation:

  • A’B+A’B - ((NOT A) AND B) OR (A AND (NOT B))
  • It is a combination of NOT, AND and OR gates
We know the boolean equation of an XOR gate with inputs A and B will be AB’+A’B.

Thus it is a combination of NOT, AND and OR gates.

We will now see how to implement it on LDmicro.
Switch back to LDmicro Switch back to LDmicro.
Instead of creating a new file, we will make changes in the previous file itself.
Place cursor to the right of Xswitch1 >> Click Instructions -> Insert Contact >> Double-click on Xnew >> Check the Negated box >> Type switch2 in the name box >> Click OK button Insert a Contact to the right of Xswitch1.

Configure it as Negated and rename it as switch2 as shown.

Place cursor to the right of Xswitch2 >> Click Instructions -> Insert Contact >> Double-click on Xnew >> Check the Negated box >> Type switch1 in the name box >> Click OK button Then insert a Contact to the right of Xswitch2 which is in the parallel rung.

Configure it as Negated and rename it as switch1 as shown.

We will now check the working of this logic.
Click Simulate -> Simulation mode >> Click Simulate -> Real-time simulation Start real-time simulation as shown.
Highlight the state of Xswitch and YLED Initially the state of both the Contacts and Coil are 0.
Double-click on Xswitch1 >> Highlight the state of the ‘YLED' >> Double-click on Xswitch1 Change the state of Xswitch1 to 1.

We can observe the state of YLED is 1.

Change the state of Xswitch1 back to 0.

Double-click on Xswitch2 >> Highlight the state of the ‘YLED' Now, change the state of Xswitch2 to 1.

We can observe the state of YLED is 1.

Double-click on Xswitch1 >> Highlight the state of the ‘YLED' Now again change the state of Xswitch1 to 1.

We can observe that the state of YLED changes to 0.

That is the output state is 0 when both the inputs have the same state.

Thus, resembling the truth table of an XOR gate.

Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode Turn off the simulation mode as shown.
Now let us compile the logic.
Highlight I/O list and status bar We can observe that the microcontroller and its parameters are already set.

Pin assignment is also already done.

Click on Compile >> Click on Compile As >> Go to Desktop/LDmicro folder >>


Rename it as ‘xorgate.hex’ >> Click on Save.

Click OK button

Compile the logic as xorgate.hex using ‘Compile As’ option.
Click on File >> Click on Save As >> Go to Desktop/LDmicro folder >>

Rename it as ‘xorgate.ld’ >> Click on Save

Then save the ladder diagram as ‘xorgate.ld’ using the ‘Save As’ option.
Now we will 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:xorgate.hex’ >> Press ENTER

Switch back to the terminal.

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.

Display the image xorgate.png Let us see the connection details now.
Display the image xorgate.png

Switch on the power

The connections will be same as in the OR gate example.

Turn on the power supply.

Point to red LED Initially the red LED is off.
Press any one switch >> Press both the switches It will start glowing only when either of the switches are pressed, but not both.
Switch off the power Turn off the power supply.
This brings us to the end of this tutorial.

Let us summarize.

Slide 7: Summary

How to implement logic gates

  • OR
  • XOR
In this tutorial we learnt to implement logic gates
  • OR and
  • XOR
Slide 8: Assignment:

Implement 2 input XNOR logic gate

As an assignment, try to implement 2 input XNOR logic gate.

Truth table of XNOR gate is shown here.

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:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.

For more details, please write to us.

Slide 11:

Forum for specific questions:

Please post your timed queries in this forum
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.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat, Priyanka.guntaka123