How do logic gates calculate their output?

2.73K views

[ad_1]

Do transistors calculate the output? If so, wouldn’t transistors be the most fundamental logic of computers?

Thanks.

In: Technology
[ad_2]

If you’re interested, I highly recommend trying this online game: http://nandgame.com/

You start with a nand gate, and combine them for form new gates, and eventually create a basic working CPU (in a digital sandbox).

Yes, transistors are the building blocks of logic gates, which are the building blocks of computers. But they don’t really ‘calculate’ their output: they’re too simple for that.

At its most basic, a transistor is a switch that lets electricity flow through it when it receives electricity from a “control” input. So for example:

`power`

`|`

`T —-A`

`|`

`output`

The transistor is labeled “T”. If electricity is put in on input “A”, electricity will flow from the power supply to the output. If “A” is off, nothing will flow to the output. So if we hook two transistors up in a chain:

`power`

`|`

`T—-A`

`|`

`T—-B`

`|`

`output`

electricity will only flow all the way to the output if there’s electricity coming in on both input A **and** input B. This is an “AND” gate.

But if we create two parallel paths like two lanes of a highway, and have A and B each control one “lane”, then electricity will flow through if either A **OR** B is on. This is an OR gate.

(Unfortunately I can’t draw this with ascii art on Reddit.)

… and that’s the starting point for all of computers.

To understand computers you have to understand that everything is built upon layers and layers (and layers and layers) of abstraction. Just like a computer language like C is an abstraction of a more low level form like Assembly (which is itself an abstraction of the pure binary), logic gates are an abstraction of groups of transistors that together do a simple operation.

So, if I’m going to design a circuit that adds two numbers together, yes I could go down to the very lowest level and map out every circuit and transistor involved, but doing so would be complicated and difficult to troubleshoot. Sticking an abstraction layer of logic gates in there makes it a much more human tractable problem.

In reality a ton of chip design is done by computers these days with even higher level abstractions on top for human readability and input. Verilog for instance more closely resembles computer code than what you might expect chip design to look like.

But none of that is a very good ELI5, so let me try again.

Logic gates are like Lego blocks, the simple old fashioned ones. You **could** build the exact same models out of only flat Lego pieces and not using blocks at all, just stick the flat plates together until you get the shape of the larger blocks. But no one would want to do that, it would be tedious and you’d likely mess it up somewhere along the line. If you really had to build a whole set out of only flat pieces, you’d probably start by putting flat pieces together into the shape of the larger more friendly blocks that the instructions actually call for.

Transistors are the flat pieces, by themselves it doesn’t look possible to make much interesting out of them. But when you think about a collection of flat pieces as a bigger block it’s easier to imagine making a huge castle from them.

So what’s more fundamental, the shapes that people build with every day or the shapes that deep down make up those shapes? It’s just a matter of semantics.

Let’s define a transistor as a 3 pin device that uses a signal at one pin to control the current flowing between the other two pins. In digital electronics that control signal would either be 1 or 0. With multiple transistors we can connect the transistors in such a way that only certain combinations of inputs at the control pins will allow current to flow through the load. I recommend looking up CMOS gate circuits to get a better picture of how this works.

You can make some gates with just diodes, but you’d need a transistor to get the voltage back up near the input voltage.

For example diodes in parallel, plus a resistor can make an OR gate or an AND gate. A transistor and a resistor can make an inverter. An AND gate and an inverter is a NAND gate. NAND gates can be used to make all the other gates.

A transistor basically has three connections. Input. Control. Output. (This isnt totally correct but works for this purpose)

The input can be a very large amount of electrons compared to the control. So the control is used to tell the transistor that it is ok to switch on and pass that high power from the input to the output.
They can also take that control input and instead use the transistor to amplify and output the amplified control signal. By varying how they are used and connected you can create very complicated computational “chips.”

A transistor needs to have an input in able to produce an output.

In the old days you needed almost 5 volts for the transistors to switch. Now I’m sure that is much smaller. But that’s there 1 and 0 came from 1 being on or 5 volts and 0 being off or anything below 5 volts.

In electronics when we used to troubleshoot at board level we would have a schematic that we could follow and understand. Using calculations and by measuring various points for the high and low we could find the problem if say a 1 bit was only 3.2 volts.

Once you understand the basics of electronics, computer programming becomes a hell of a lot easier and makes sense.

[I can’t believe this hasn’t been posted yet. It is Matt Parker(not South Park) showing logic gates with dominoes.](https://youtu.be/lNuPy-r1GuQ)

I would highly recommend checking out Ben Eater’s channel on YouTube. He has great videos that explain how computer hardware works, and he does so by building them out on a breadboard, accompanied by diagrams, etc.

For your particular question, his 13 minute video ‘Making Logic Gates From Transistors’ (https://youtu.be/sTu3LwpF6XI) takes you through each logic gate in a simple to follow format, and he builds them out with transistors.

Other videos of his include building a basic 8-bit computer, RAM modules, and even a video card from scratch with explanations. He’s also now selling kits so you can follow along with his builds.

Transistors do ultimately calculate the output. It would be fair to say they are the most fundamental logic element in a computer.

Using methods described by other people ITT you can build basic gates like OR, AND, NOR, NAND, XOR, etc. The next step is to chain multiple gates together to come up with something more useful. You can implement a lot of surprisingly complex calculations by doing this. Addition, subtraction, multiplication, and a lot more are possible using only basic logic gates. This is called combinational logic.

To take it to the next level you need *sequential* logic. You use a *flip flop* (which itself can be implemented using transistors) to store the output of one calculation. Then you can feed that output into another combinational circuit to do the next step of your calculation. This allows you to chain multiple calculations together. That’s essentially what a program is. A list of operations which are calculated sequentially.

I would say yes, transistors are the **most basic** fundamental building blocks of electronics.

They are usually constructed of pure silicon or a mix with germanium, both with semiconductor properties. A semiconductor is a material that has conductive properties between those of a conductor and an insulator. This means that regions of a semiconductor material can be “doped” — the creation of impurities in the silicon wafer.

In short, adjacent differently-doped regions can form “p-n junctions” (p for positive, n for negative). The positive side will lack electrons (as electrons are negative, an absence is represented as positive), while the negative side will have an abundance of electrons. Because of the potential to fill the empty electron positions in the positive side, electrons flow from the negative to the positive side — one direction only. This is, essentially, a diode. A common transistor consists of either a PNP or NPN junction.

A transistor is simply a “digital switch”. They have “terminals” for power (think of a battery) and one input. If this input is used, electricity will flow. Otherwise, the internal circuit will not complete, and no electricity will be outputted.

To create logic gates, the outputs of some transistors are tied to the inputs/power of others.

It’s like playing red rover and keeping score. When a player breaks through, it’s a 1. When a player doesn’t, it’s still 0. Each turn you add up the score and that’s your output.

Transistors have no logic though. They’re simply in a simple state of yes, no, or maybe. They *enable* logic by storing states, but they themselves are simply flag posts: the CPU turns it into logic via binary and higher level code.

Compute is probably the wrong word at the level of a transistor. At this level you’re just describing components. Transistors don’t compute as they alone don’t allow you to recognize any mathematical output for a given input. They simply control the flow of electricity. You need wires, at least two transistors, a voltage source, and a voltage drain to create a unit of computation called a gate. A gate is a configuration of electrical components, that’s flow of current represents a mathematical computation on some input to derive an output; it only means something because it can be interpreted by a human. A gate is the smallest unit of computation because nothing smaller actually computes anything, whereas a transistor, like a wire or a voltage source, cannot represent any mathematical process. The two fundamental gates are NOT and NAND (or NOR) and all other computations can be generated from configurations of these gates.

Edit: I want to say there *is* a trivial computation that can be performed by just a single wire: the identity function, f(A) = A. This is computed by simply connecting an input pin to an output pin. This is not very interesting and it can’t be used to construct more interesting computation so it’s not really fair to call a wire the basic unit of computation.