Difference between revisions of "OpenPLC-version1-with-LDmicro/C2/Implementing-NOT-and-AND-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...")
 
 
Line 6: Line 6:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 1:  
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 1:  
| style="border:1pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on '''Implementing NOT & AND logic gates'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on '''Implementing NOT and AND logic gates'''.
  
 
|-
 
|-
Line 12: Line 12:
  
 
How to implement logic gates
 
How to implement logic gates
 
 
* NOT
 
* NOT
 
* AND
 
* AND
  
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will implement '''NOT & AND '''logic gates in '''LDmicro'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will implement '''NOT''' and '''AND logic gates''' in '''LDmicro'''.
  
 
|-
 
|-
Line 35: Line 34:
 
* '''OpenPLC version1 Mainboard'''
 
* '''OpenPLC version1 Mainboard'''
 
* '''24V, 2A SMPS'''
 
* '''24V, 2A SMPS'''
* '''USBasp''' programmer
+
* '''USBasp programmer'''
* '''Traffic Light''' module
+
* '''Traffic Light module'''
* '''Switchboard''' module
+
* '''Switchboard module'''
  
 
|-
 
|-
Line 46: Line 45:
  
 
If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]
 
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;"| * To follow this tutorial, you should know the working of  
+
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
+
* 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 63: Line 62:
 
|-
 
|-
 
| 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 implement a '''NOT''' gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| First we will implement a '''NOT gate'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 5: '''NOT gate'''
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 5: '''NOT gate'''
  
For a '''NOT''' gate the output boolean is inverse of the input
+
For a '''NOT gate''' the '''output boolean''' is inverse of the '''input'''
| style="border:1pt solid #000000;padding:0.176cm;"| We know that for a '''NOT''' gate the output boolean is inverse of the input.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We know that for a '''NOT gate''' the '''output boolean''' is inverse of the '''input'''.
  
 
|-
 
|-
Line 77: Line 76:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Insert Coil’
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Insert Coil’
| style="border:1pt solid #000000;padding:0.176cm;"| Insert a Contact as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Insert a '''Contact''' as shown.
  
Place the cursor to the right of the Contact and insert a Coil.
+
Place the cursor to the right of the '''Contact''' and insert a '''Coil'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on contact >> Type switch in name box >> Click OK button
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on contact >> Type switch in name box >> Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the Contact as '''‘switch’ '''as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the '''Contact''' as '''‘switch’ '''as shown.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on coil >> Select ‘Negated’ option >> Type LED in name box >>Click OK button
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on coil >> Select ‘Negated’ option >> Type LED in name box >>Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Next configure the Coil as '''Negated''' and rename it as '''LED'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Next configure the '''Coil''' as '''Negated''' and rename it as '''LED'''.
  
 
|-
 
|-
 
| 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 check the working of this logic.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Now we will 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;"| Let us turn on the simulation mode.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Let us turn '''on''' the '''simulation mode'''.
  
For that, click '''Simulate''' and then on S'''imulation 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 113: Line 112:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
| style="border:1pt solid #000000;padding:0.176cm;"| That is resembling the truth table of a '''NOT''' gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| That is resembling the '''truth table''' of a '''NOT 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;"| Now, turn off the 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 127: Line 126:
  
 
Double-click on coil >> Select ‘Normal’ option >> Click OK button
 
Double-click on coil >> Select ‘Normal’ option >> Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Configure the Contact as '''Negated''' and Coil as '''Normal'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Configure the '''Contact''' as '''Negated''' and '''Coil''' as '''Normal'''.
  
 
|-
 
|-
 
| 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;"| Now again start real-time simulation.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Now again start real-time '''simulation'''.
  
 
|-
 
|-
Line 145: Line 144:
 
|-
 
|-
 
| 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 either input or output being negated works as a NOT gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Thus either '''input''' or '''output''' being negated, works as a '''NOT gate'''.
  
Note: Both input and output shouldn’t be negated at the same time for NOT gate.
+
Note: Both '''input''' and '''output''' shouldn’t be negated at the same time for '''NOT 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'''.
  
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 163: Line 162:
  
 
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 microcontroller '''AVR ATmega16 40-PDIP.'''  
+
| 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 171: Line 170:
  
 
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 pin '''PC0''' to '''Xswitch''' and '''PA0''' to '''YLED'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Assign '''pin PC0''' to '''Xswitch''' and '''PA0''' to '''YLED'''.
  
 
|-
 
|-
Line 177: Line 176:
  
 
Click OK button
 
Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Compile the logic as '''notgate.hex'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| '''Compile''' the '''logic''' as '''notgate.hex'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘notgate.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 ‘notgate.ld’ >> Click on Save
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the ladder diagram as '''‘notgate.ld’''' as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the '''ladder diagram''' as '''‘notgate.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 194: Line 193:
 
| 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'''.
  
 
|-
 
|-
 
| 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:notgate.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:notgate.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 218:
 
| style="border:1pt solid #000000;padding:0.176cm;"| notgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| notgate.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 +5V pin of the red LED to '''PA0''' pin of the '''Mainboard'''.
+
Then connect '''+5V pin''' of the red '''LED''' to '''PA0 pin''' of the '''Mainboard'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| notgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| notgate.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 233: Line 232:
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''on''' the '''power supply'''.
| 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;"| 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;"| Red LED glows
| style="border:1pt solid #000000;padding:0.176cm;"| We can see that the red LED is glowing initially.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We can see that the red '''LED''' is glowing initially.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| NO1 pressed >> Red LED stops glowing
| style="border:1pt solid #000000;padding:0.176cm;"| It will go off whenever the '''NO1''' is pressed.
+
| style="border:1pt solid #000000;padding:0.176cm;"| It will go '''off''' whenever 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;"| This shows the working of a NOT gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| This shows the working of a '''NOT gate'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| hardware-prerequisite.jpg
+
| style="border:1pt solid #000000;padding:0.176cm;"| Show image of power supply off
| 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 256: Line 255:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
| style="border:1pt solid #000000;padding:0.176cm;"| Next we will now see how to implement an '''AND''' gate in '''LDmicro'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Next we will now see how to implement an '''AND gate''' in '''LDmicro'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 6: AND gate
 
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 6: AND gate
  
* '''AND''' gate output state is 1 only when all of its input states are 1
+
* '''AND gate output''' state is 1 only when all of its '''input''' states are 1
  
| style="border:1pt solid #000000;padding:0.176cm;"| We know that '''AND''' gate output state is 1 only when all of its input states are 1.
+
| style="border:1pt solid #000000;padding:0.176cm;"| We know that '''AND gate output''' state is 1 only when all of its '''input''' states are 1.
  
 
|-
 
|-
Line 277: Line 276:
  
 
Place the cursor to the right of Xnew >> Click Instructions -> Insert Contact
 
Place the cursor to the right of Xnew >> Click Instructions -> Insert Contact
| style="border:1pt solid #000000;padding:0.176cm;"| Here we will implement a two-input '''AND''' gate.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Here we will implement a '''two-input AND gate'''.
  
 
Insert two '''Contacts '''as shown here.
 
Insert two '''Contacts '''as shown here.
Line 285: Line 284:
  
 
Double-click on Xnew >> Type switch2 in the name box >> Click the OK button
 
Double-click on Xnew >> Type switch2 in the name box >> Click the OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the first Contact as '''‘switch1’''' and second Contact as '''‘switch2’.'''
+
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the first '''Contact''' as '''‘switch1’''' and second '''Contact''' as '''‘switch2’.'''
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the right of Xswitch2 >> Click Instructions -> Insert Coil
 
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the right of Xswitch2 >> Click Instructions -> Insert Coil
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the right of '''Xswitch2''' and insert a Coil.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Place the cursor to the right of '''Xswitch2''' and insert a '''Coil'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Ynew >> Type LED in the name box >> Click the OK button
 
| style="border:1pt solid #000000;padding:0.176cm;"| Double-click on Ynew >> Type LED in the name box >> Click the OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the Coil as '''‘LED’'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Rename the '''Coil''' as '''‘LED’'''.
  
 
|-
 
|-
 
| 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.
  
 
|-
 
|-
Line 329: Line 328:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
 
| style="border:1pt solid #000000;padding:0.176cm;"|  
| style="border:1pt solid #000000;padding:0.176cm;"| That is, output state is 1 only when both the inputs states are 1.
+
| style="border:1pt solid #000000;padding:0.176cm;"| That is, '''output''' state is 1 only when both the '''input''' states are 1.
  
Thus, resembling the truth table of a '''AND''' gate.
+
Thus, resembling the '''truth table''' of a '''AND 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'''.
  
 
|-
 
|-
Line 345: Line 344:
  
 
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 microcontroller '''AVR ATmega16 40-PDIP.'''  
+
| 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 353: Line 352:
  
 
Double-click on Xswitch2 in I/O list >> Select PC1 >> Click OK button
 
Double-click on Xswitch2 in I/O list >> Select PC1 >> 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'''.
  
 
|-
 
|-
Line 359: Line 358:
  
 
Click OK button
 
Click OK button
| style="border:1pt solid #000000;padding:0.176cm;"| Compile the logic as '''andgate.hex'''.
+
| style="border:1pt solid #000000;padding:0.176cm;"| '''Compile''' the '''logic''' as '''andgate.hex'''.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘andgate.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 ‘andgate.ld’ >> Click on Save
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the ladder diagram as '''‘andgate.ld’''' as shown.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Then save the '''ladder diagram''' as '''‘andgate.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 376: Line 375:
 
| 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'''.
  
 
|-
 
|-
 
| 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:andgate.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:andgate.hex’ '''>> Press ENTER
| style="border:1pt solid #000000;padding:0.176cm;"| Open the terminal.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Open 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 398: Line 397:
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.176cm;"| andgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| andgate.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;"| andgate.png
 
| style="border:1pt solid #000000;padding:0.176cm;"| andgate.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''' and connect '''NO2''' to '''PC1''' of the '''Mainboard'''.
+
Connect '''NO1''' to '''PC0''' of the '''Mainboard'''.
 +
 
 +
And connect '''NO2''' to '''PC1''' of the '''Mainboard'''.
  
 
Make the connections as shown in the picture.
 
Make the connections as shown in the picture.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| 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;"| Turn '''on''' the '''power supply'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| style="border:1pt solid #000000;padding:0.176cm;"| Red LED not glowing
| 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;"| NO1 & NO2 pressed simultaneously >> Red LED glows
 
| style="border:1pt solid #000000;padding:0.176cm;"| It will glow only when both '''NO1''' and '''NO2''' are pressed simultaneously.
 
| style="border:1pt solid #000000;padding:0.176cm;"| It will glow only when both '''NO1''' and '''NO2''' are pressed simultaneously.
  
 
|-
 
|-
 
| 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 '''AND''' gate both the inputs i.e. Contacts should be in series.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Thus, for '''AND gate''' both the '''inputs''' i.e. '''Contacts''' should be in '''series'''.
  
The output i.e. Coil should also be in series with the inputs.
+
The '''output''' i.e. '''Coil''' should also be in '''series''' with the '''inputs'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"|  
+
| 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.
+
| style="border:1pt solid #000000;padding:0.176cm;"| Turn '''off''' the '''power supply'''.
  
 
|-
 
|-
Line 442: Line 443:
  
 
We learnt to implement logic gates
 
We learnt to implement logic gates
 
 
* NOT
 
* NOT
 
* AND
 
* AND
 
+
| 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  
+
* '''NOT''' and
 
+
* '''AND'''
* NOT and
+
* AND
+
  
 
|-
 
|-
Line 455: Line 453:
  
 
Implement 2 input NAND logic gate
 
Implement 2 input NAND 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 '''NAND''' logic gates.
+
| 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 NAND logic gates'''.
  
Truth table of the '''NAND''' gate is shown here.
+
'''Truth table''' of the '''NAND gate''' is shown here.
  
 
|-
 
|-
Line 471: Line 469:
  
 
Spoken Tutorial workshops
 
Spoken Tutorial workshops
| style="border:1pt solid #000000;padding:0.176cm;"| The''' Spoken Tutorial Project''' team:
+
| style="border:1pt solid #000000;padding:0.176cm;"| The''' Spoken Tutorial Project''' team conducts workshops and gives certificates on passing online tests.
 
+
* conducts workshops and
+
* gives certificates on passing online tests.
+
  
For more details, please write to us
+
For more details, please write to us.
  
 
|-
 
|-
Line 482: Line 477:
  
 
Forum for specific questions:
 
Forum for specific questions:
| style="border:1pt solid #000000;padding:0.176cm;"| Please post your timed queries in this forum
+
| style="border:1pt solid #000000;padding:0.176cm;"| Please post your timed queries in this forum.
  
 
|-
 
|-

Latest revision as of 10:12, 20 October 2020

Visual Cue
Narration
Slide 1: Welcome to the spoken tutorial on Implementing NOT and AND logic gates.
Slide 2: Learning Objectives

How to implement logic gates

  • NOT
  • AND
In this tutorial, we will implement NOT and AND 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
  • Switchboard module
Slide 4: Pre-requisites
  • Normal Contact and Coil
  • Negated Contact and Coil

If not, please refer to the relevant tutorials from Home | spoken-tutorial.org

  • 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 implement a NOT gate.
Slide 5: NOT gate

For a NOT gate the output boolean is inverse of the input

We know that for a NOT gate the output boolean is inverse of the input.
Open LDmicro Let us open LDmicro.
Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Insert Coil’ Insert a Contact as shown.

Place the cursor to the right of the Contact and insert a Coil.

Double-click on contact >> Type switch in name box >> Click OK button Rename the Contact as ‘switch’ as shown.
Double-click on coil >> Select ‘Negated’ option >> Type LED in name box >>Click OK button Next configure the Coil as Negated and rename it as LED.
Now we will 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 state of Xswitch is 0 and YLED is 1.
Double-click on Xswitch in the IO list >> Highlight the state of the ‘YLED’ Change the state of Xswitch to 1.

We can observe the state of YLED changes to 0.

That is resembling the truth table of a NOT 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.

Double-click on Xswitch >> Check the Negated box >> Click the OK button

Double-click on coil >> Select ‘Normal’ option >> Click OK button

Configure the Contact as Negated and Coil as Normal.
Click Simulate -> Simulation mode >> Click Simulate -> Real-time simulation Now again start real-time simulation.
Highlight the state of Xswitch and YLED Initially the state of Xswitch is 0 and YLED is 1.
Double-click on Xswitch in the IO list >> Highlight the state of the ‘YLED Change the state of Xswitch to 1.

We can observe the state of YLED is 0.

Thus either input or output being negated, works as a NOT gate.

Note: Both input and output shouldn’t be negated at the same time for NOT gate.

Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode Turn off the simulation mode as shown.
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 ‘notgate.hex’ >> Click on Save.

Click OK button

Compile the logic as notgate.hex.
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘notgate.ld’ >> Click on Save Then save the ladder diagram as ‘notgate.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:notgate.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.

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

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

notgate.png Connect GND and 5V of Switchboard to GND and 5V of the Mainboard respectively.

Connect NO1 to PC0 of the Mainboard.

Make the connections as shown in the picture.

Turn on the power supply. After making all the connections properly, turn on the power supply.
Red LED glows We can see that the red LED is glowing initially.
NO1 pressed >> Red LED stops glowing It will go off whenever the NO1 is pressed.
This shows the working of a NOT gate.
Show image of power supply off Turn off the power supply.

Remove the connections made for this example.

Next we will now see how to implement an AND gate in LDmicro.
Slide 6: AND gate
  • AND gate output state is 1 only when all of its input states are 1
We know that AND gate output state is 1 only when all of its input states are 1.
Switch back to LDmicro Switch back to LDmicro.
Click File -> New Open a new file.
Click Instructions -> Insert Contact

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

Here we will implement a two-input AND gate.

Insert two Contacts as shown here.

Double-click on Xnew >> Type switch1 in the name box >> Click the OK button

Double-click on Xnew >> Type switch2 in the name box >> Click the OK button

Rename the first Contact as ‘switch1’ and second Contact as ‘switch2’.
Place the cursor to the right of Xswitch2 >> Click Instructions -> Insert Coil Place the cursor to the right of Xswitch2 and insert a Coil.
Double-click on Ynew >> Type LED in the name box >> Click the OK button Rename the Coil as ‘LED’.
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 in the IO list >> Highlight the state of the ‘YLED' >> Double-click on Xswitch1 in the IO list Change the state of Xswitch1 to 1.

We can observe the state of YLED is still 0.

Change the state of Xswitch1 back to 0.

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

We can observe the state of YLED is still 0.

Double-click on Xswitch1 in the IO list >> 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 1 only when both the input states are 1.

Thus, resembling the truth table of a AND gate.

Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode Turn off the simulation mode as shown.
Now let us compile the logic.
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 I/O list >> Select PC0 >> Click OK button

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

Assign pin PC0 to Xswitch1 and PC1 to Xswitch2.
Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘andgate.hex’ >> Click on Save.

Click OK button

Compile the logic as andgate.hex.
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘andgate.ld’ >> Click on Save Then save the ladder diagram as ‘andgate.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:andgate.hex’ >> Press ENTER Open 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.

andgate.png Let us see the connection details now.
andgate.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.

andgate.png Connect GND and 5V of Switchboard to GND and 5V of the Mainboard respectively.

Connect NO1 to PC0 of the Mainboard.

And connect NO2 to PC1 of the Mainboard.

Make the connections as shown in the picture.

Turn on the power supply. Turn on the power supply.
Red LED not glowing We can see that the red LED is off initially.
NO1 & NO2 pressed simultaneously >> Red LED glows It will glow only when both NO1 and NO2 are pressed simultaneously.
Thus, for AND gate both the inputs i.e. Contacts should be in series.

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

Turn off the power supply. Turn off the power supply.
This brings us to the end of this tutorial.

Let us summarize.

Slide 7: Summary

We learnt to implement logic gates

  • NOT
  • AND
In this tutorial we learnt to implement logic gates
  • NOT and
  • AND
Slide 8: Assignment

Implement 2 input NAND logic gate

As an assignment, try to implement 2 input NAND logic gates.

Truth table of the NAND 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 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, Priyanka.guntaka123