{"id":984,"date":"2020-11-18T23:43:36","date_gmt":"2020-11-18T22:43:36","guid":{"rendered":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/?p=984"},"modified":"2021-06-30T07:53:49","modified_gmt":"2021-06-30T06:53:49","slug":"the-basics-of-logic-circuits-part-1","status":"publish","type":"post","link":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/?p=984","title":{"rendered":"The Basics of Logic Circuits &#8211; Part 1"},"content":{"rendered":"\n<h2>The Basics of Logic Circuits &#8211; Part 1<\/h2>\n\n\n\n<h4>An Introduction<\/h4>\n\n\n\n<p>As\na child I had an interest in electronics. I took options at school\nwhich taught me the basics, but found that a few small details were\nomitted which made it slightly more difficult to move from theory to\npractice. Following a recent discussion with my brother about how we\nthought it would be best to introduce electronics to a beginner and\nmove through to designing and building your own circuits, I decided\nto write something to hopefully help other people in the same\nposition as my 15 year old self.<\/p>\n\n\n\n<h4>Useful\nParts for the Following<\/h4>\n\n\n\n<ul><li>74HC00 \u2013 Quad 2-input NAND gate<\/li><li>74HC04 \u2013 Hex inverter gate (NOT)<\/li><li>74HC32 \u2013 Quad 2-input OR gate<\/li><li>74HC08 \u2013 Quad 2-input AND gate<\/li><li>2N7000 \u2013 MOSFET<\/li><li>Pushbutton<\/li><li>LED<\/li><li>220R Resistor<\/li><li>Breadboard<\/li><li>Power source?<\/li><\/ul>\n\n\n\n<h4>Basic\nBoolean Logic<\/h4>\n\n\n\n<p>As\na tool for introducing electronics in more general terms, I\u2019m going\nto introduce logic and logic chips. In electronics, logic is usually\nbased on the theory of using voltages to represent two states, \u201cTRUE\u201d\nor \u201cFALSE\u201d, sometimes called \u201cHIGH\u201d and \u201cLOW\u201d (in\nreference to the voltage). When the voltage is high, and the signal\nis considered to be present, this is a TRUE. Multiple TRUE and FALSE\nsignals can be used together representing a set of inputs to be\nanalysed to give specific outcomes in specific input scenarios by\napplying various logic operations. Even\nwith basic logic rules, complex systems can be built.<\/p>\n\n\n\n<p>The three most basic logic operations commonly seen in electronics are \u201cAND\u201d, \u201cOR\u201d and \u201cNOT\u201d. These are implemented physically as \u201cgates\u201d (e.g. \u201cyou need an AND Gate in your circuit\u201d), which it is common to find several of in one microchip. The most conceptually simple gate is the NOT gate, which takes an input signal, and inverts it before outputting it. This means that when applying a logic TRUE to a NOT gate, it will produce a logic FALSE at the output pin and vice versa. The OR gate provides a logic TRUE when either one, the other, or both of its inputs are TRUE. Finally, the AND gate produces a logic TRUE only when both inputs are TRUE. Any time the output is not TRUE for any of these gates, it will be FALSE. The following table shows all combinations for two inputs named Input A and Input B. It is possible to have AND and OR gates with more inputs, although the same result can be achieved by using multiple gates consecutively and feeding the output of one into the input of another. Note that as shown in the following table, the NOT gate has a single input. Within the table, the NOT gate has been assumed to be connected to Input A (and duplicate second rows have been omitted for clarity).<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong> Input A <\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong> Input B <\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong> AND <\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong> OR <\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong> NOT <\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"> <em>FALSE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\"> <em>FALSE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tFALSE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tFALSE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tTRUE\n\t\t<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"> <em>FALSE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\"> <em>TRUE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tFALSE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tTRUE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\t<br>\n\n\t\t\t\n\t\t<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"> <em>TRUE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\"> <em>FALSE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tFALSE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tTRUE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tFALSE\n\t\t<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"> <em>TRUE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\"> <em>TRUE<\/em> <\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tTRUE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\tTRUE\n\t\t<\/td><td class=\"has-text-align-center\" data-align=\"center\">\n\t\t\t<br>\n\n\t\t\t\n\t\t<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4>Equivalent\nCircuits<\/h4>\n\n\n\n<p>The\nvarious logic circuits can be considered as behaving in a similar\nmanner to the following conventional electrical equivalents. These\nequivalents use switches to achieve the same behaviour, where the\nbulb represents the output.<\/p>\n\n\n\n<p><strong>AND &#8211; Two Switches in a Row<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"448\" height=\"255\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalAND.png\" alt=\"\" class=\"wp-image-985\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalAND.png 448w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalAND-300x171.png 300w\" sizes=\"(max-width: 448px) 100vw, 448px\" \/><\/figure><\/div>\n\n\n\n<p><strong> OR &#8211; Two Switches in Parallel<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"456\" height=\"287\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalOR.png\" alt=\"\" class=\"wp-image-986\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalOR.png 456w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalOR-300x189.png 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/figure><\/div>\n\n\n\n<p><strong>NOT &#8211; A switch in Parallel with the Load<\/strong><\/p>\n\n\n\n<p>When\nthe switch is pressed, the load is bypassed as the path of least\nresistance is through the closed switch. This means that when\nthe switch is closed (TRUE), the\nLED is off (FALSE) and\nvice versa. The resistor\nR1 is included so that the switch is not a dead short over the\nbattery. The battery voltage was increased to 5V to make the circuit\nmore realistic in that the LED would be dim (or\ngo out) if the 2V supply\nfrom the two previous circuits was used.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"436\" height=\"211\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalNOT.png\" alt=\"\" class=\"wp-image-987\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalNOT.png 436w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ElectricalNOT-300x145.png 300w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/figure><\/div>\n\n\n\n<p>If you are unsure why this circuit acts as a NOT, consider that the resistance of a typical 10cm wire and switch might be 0.0005 ohm. Current follows alternative paths inversely proportionally to the resistance. If two paths are of equal resistance, the current will divide equally between both routes. If one resistance is 10 time greater than the other, 10 times more current will flow through the LOWER resistance path. As the LED has an effective resistance tens of thousands of times greater than the wire (if not more) effectively all the available current will go through the wire and switch rather than the LED. When the switch is released (goes open) the resistance of that path becomes huge (it might as well be infinite) and so all available current goes through the LED as it is now the path of least resistance. Much more detail can be given regarding how the resistance of an LED changes depending on voltage, about the resistance of the circuit and about the resistance of individual parts of the circuit etc. but very quickly this gets too detailed and distracts from the purpose of this example!<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p><font color=\"red\">Just Draft Notes from here on in. Also, check that a 1k resistor is suitable for the circuit I drew. OK &#8211; I&#8217;ve checked the 1k and it looks OK (but I&#8217;d prefer to test the circuit) It results in less than 1.4mA current in the LED and not more than 5mA into the Base? something like that. A bigger resistor might be better, say 2 or even 3k.<\/font><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4>Using Transistors Instead of Switches<\/h4>\n\n\n\n<p>There are two main types of Transistors, NPN and PNP. Effectively, the NPN produces switches on when a current is provided to the Base pin, while a PNP switches off when a current is provided to the Base pin. I remember the difference between the two symbols by telling myself that NPN stands for &#8220;Not Pointing iN&#8221;, with reference to the arrow in the symbol. The two symbols are as follows.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"308\" height=\"199\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/NPNPNP.png\" alt=\"\" class=\"wp-image-998\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/NPNPNP.png 308w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/NPNPNP-300x194.png 300w\" sizes=\"(max-width: 308px) 100vw, 308px\" \/><\/figure><\/div>\n\n\n\n<p><strong>AND &#8211; Using Two NPN Transistors<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"415\" height=\"406\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorAND-1.png\" alt=\"\" class=\"wp-image-1002\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorAND-1.png 415w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorAND-1-300x293.png 300w\" sizes=\"(max-width: 415px) 100vw, 415px\" \/><\/figure><\/div>\n\n\n\n<p>In the preceding example the Base pins on the transistors are shown with  the Base pins protected by 1k current limiting resistors (R1 and R2). In a real application, these inputs would be connected to something like the output pins of a microcontroller. The LED is also in line with a 220R current limiting resistor. To implement this circuit, you might use the common BC547 NPN transistor. This would be suitable for use with, for example, a 5V Arduino Uno. The following schematic shows how this might be implemented. Similar methods can be used for the OR and NOT implementations which follow, but this post does not go into detail regarding using transistors as the primary intention is to explain the use of Logic chips. I might return to the subject of transistors at a later date.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"825\" height=\"589\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ArduinoAND.png\" alt=\"\" class=\"wp-image-994\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ArduinoAND.png 825w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/ArduinoAND-300x214.png 300w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure><\/div>\n\n\n\n<p><strong>OR &#8211; Using NPN Transistors<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"341\" height=\"515\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorOR.png\" alt=\"\" class=\"wp-image-1006\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorOR.png 341w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorOR-199x300.png 199w\" sizes=\"(max-width: 341px) 100vw, 341px\" \/><\/figure><\/div>\n\n\n\n<p>Supplying current to either (or both) Input A or B will provide a current path from the LED to ground, completing the circuit and implementing our OR logic.<\/p>\n\n\n\n<p><strong>NOT &#8211; Using a PNP Transistor<\/strong><\/p>\n\n\n\n<p>To implement the NOT logic using a transistor, the easiest solution is to use a PNP transistor instead of the NPN used in the previous two examples. As noted, this type of transistor <em>closes<\/em> when current is provided to the Base. Note the different location of the arrow within the transistor&#8217;s symbol. The common PNP equivalent of the BC547 is the BC557.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"389\" height=\"297\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorNOT.png\" alt=\"\" class=\"wp-image-1012\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorNOT.png 389w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TransistorNOT-300x229.png 300w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><\/figure><\/div>\n\n\n\n<p>In reality, within integrated circuits, the logic implementations are more complex to allow greater flexibility and a more well rounded product. The following is an extract from a Texas Instruments datasheet for the 7408, showing the individual transistors within each gate of the logic chip. The design is beyond me&#8230; especially as I&#8217;ve never seen a transistor with 4 legs.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"384\" height=\"265\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TI_AND_Gate.png\" alt=\"\" class=\"wp-image-1024\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TI_AND_Gate.png 384w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/TI_AND_Gate-300x207.png 300w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/figure><\/div>\n\n\n\n<p>Additionally, it is also possible to implement logic using &#8220;Relay Logic&#8221;, but that is a topic for another day.<\/p>\n\n\n\n<h4>Symbols<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"498\" height=\"129\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/Symbols.png\" alt=\"\" class=\"wp-image-1015\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/Symbols.png 498w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/Symbols-300x78.png 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/figure><\/div>\n\n\n\n<p>The symbols for the AND, OR and NOT gates are shown above. Note the small dot on the NOT gate &#8211; without the dot the triangular symbol would represent a buffer, which does not modify the output logic and simply passes the input signal to the output. The dot symbolises that the output should be inverted. This dot can be also added to other gates to mean that the output should be inverted. In the case of the AND and OR gates, this produces the NAND and NOR gates.<\/p>\n\n\n\n<p><em>Note that schematics within this post were drawn using Fritzing &#8211; a free circuit designing program for Linux, MacOS and Windows.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Basics of Logic Circuits &#8211; Part 1 An Introduction As a child I had an interest in electronics. I took options at school which taught me the basics, but found that a few small details were omitted which made it slightly more difficult to move from theory to practice. Following a recent discussion with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":910,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[24,13,42,12],"tags":[255,254,256,253],"jetpack_featured_media_url":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2019\/07\/EPROM_Chip_27128.jpg","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7g9vY-fS","_links":{"self":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/984"}],"collection":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=984"}],"version-history":[{"count":39,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/984\/revisions"}],"predecessor-version":[{"id":1327,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/984\/revisions\/1327"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/media\/910"}],"wp:attachment":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}