OpenPLC-with-LDmicro/C2/Implementing-NOT-and-AND-logic-gates/English

From Script | Spoken-Tutorial
Revision as of 18:38, 30 June 2021 by Nirmala Venkat (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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 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 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

Nirmala Venkat