Logic Gates
Motivation
Since having an amazing, when sometimes troubling physics teacher in high school, I wanted to build a small computer from the ground up. Understanding how these machines we use daily work, and not only on an abstract level but on the hands on, is one of the obligations I set myself back then. Here I could now write some more about how a curious mind should try to understand the tools he uses on a daily basis from the ground up, but this would end up too much as a moral lecture and not a fun blog article, so I push this to another time. So the goal of this series of blogs is to build a computer, starting with the basic components like resistors, capacitors, transistors etc. I want to build every thing I later use as an integrated circuit before with these simple components. If I want to use a 555 IC later, I should build it myself on a breadboard before. With this, I would like to work myself up to a full functioning small computer with a CPU, memory and maybe even a graphical output. Later I may be looking in to ways of building my own transistor, I found some interesting ways to do so using a diode, but for now, I will assume that transistors are of the same basic-ness as resistors, capacitors and wires.
Right now I heavily rely on the amazing work that Ben Eater did over the course of the years, to get in to the topic. He has an outstanding teaching style and will be the basis at least for the first few sections of this blog.
Logic Gates
The basic building blocks of any computational device we use today are the so-called logic gates. They implement the logical operators we know from math or spoken language (with some imprecision) like AND
, OR
or XOR
.
The goal here is to implement them in an electronic circuit, where the inputs are switches and the output is an LED. For this we use transistors. Their working mechanism is explained in a different blog post.
Inverter
We start with the most simple gates, the inversion. This turns a 1 in to a 0 and vice verca. When the switch is open, there is a voltage between points A and B. The LED is on and the output is therefore 1. Closing the switch we connect the points A and B via the transistor. Therefore there is no voltage over the LED and it stays of. The output is 0. With this we build an inverter.
AND Gate
We want a gate that has two inputs and one output. If both inputs are 1, we want the output to be 1 and in all other cases, we want the output to be zero. When we have a positive input on A and B, the current can flow from the 5V rail down to ground, lighting up the LED. If only one of the inputs are on, there is no current flowing, since the second transistor is acting as a blockage. Therefore the LED stays of. The same happens when both inputs are low.
OR Gate
We want a gate that has two inputs and one output. If either A or B, or both A and B are high, we want the output to be high. Only if both inputs are low, we want the output also to be low. The idea is to have a parallel circuit, where opening one arm, lights up the LED. Pressing either of the switches, we open the corresponding transistor, letting current flow from the 5V rail to the ground. If we press both buttons, more current can flow, but since we anyway just have to trigger a certain level to light up the LED, this does not bother us. The LED is on, and the task fulfilled. If both switches are open, no current flows through the transistors and the LED stays off.