How to make your own computer from electronic components

7th Oct 2012 | 07:00

How to make your own computer from electronic components

The electronic building blocks that make your PC tick

Making your own computer

Have you ever stopped to wonder, 'how do computers work?' Think about it for a moment. Computers are just another electrical device, like a light bulb, made of inert bits of metal and silicon.

Yet, when put together in the right way, these tiny components can store and manipulate information, and they can even have an impact on the real world.

We stopped to wonder, and we decided to find out. In this article, we'll share everything we discovered. And with the aid of a piece of free software called KTechlab, we'll show you how you can put all this knowledge into practice and create your very own, crude, computing (well, adding) device.

If you want to go on and build your own computer from these designs, all you'll need is a bread board and a few components. Maplin, for example, has a comprehensive electronics catalogue.



Let's start by thinking about the light bulb. It's a simple device - you flick a switch, and it turns on. Flick the switch the other way, and it turns off. Each time you flick the switch, what you're doing is making and breaking an electrical circuit - you're controlling the flow of electricity.

This is all that really happens inside a computer, too. Lots and lots (billions) of tiny switches are controlling the flow of electricity. What makes these switches different to your light is that they're not mechanical switches controlled by people, but electrical switches that are controlled by electricity! It's a strange idea, but you can see the principle illustrated in a device called a relay, shown above.

In this electrical circuit, there's a light bulb attached to a battery. In between the bulb and the battery is a switch. While it's open, the circuit is broken and the light bulb turned off.

Underneath the switch, however, is an electromagnet. This is a device that becomes magnetic when an electrical current flows through it. When the electromagnet is switched on, the light bulb's switch is pulled downwards by the magnetic field and the light comes on. When the electromagnet is switched off, the switch swings open again and the bulb goes off.

OK, so at this point you're thinking 'somebody has still got to switch the electromagnet on'. True. We'll cross that bridge later, but for now just see how it's possible for a switch to operate based on whether there's a current flowing into it or not.

Electrical switches can be made in many different ways. Relays are one possible technique, vacuum tubes another, and then there's the transistor. Transistors are much smaller than the other two switches, and they're the switch used in modern computers.

We won't explain how they work, since this would see us sidetracked into the weird world of physics; but we will explain how to use them, since they'll form the heart of the circuits we make in the rest of this article.

Transistor as switch

Transistor switch

To demonstrate how to use a transistor, we'll show you how to use it as a simple switch.

Take a look at Figure 2. Here, you can see that the circuit is almost identical to the relay example. The relay, however, has been replaced by the transistor.

Two of the transistor's legs are connected to the same wires as the relay's internal switch was, while the third is connected to the controlling wire. When a small current is applied to the third leg (called the base), a large current is able to flow almost uninhibited across the other two legs (the one with the arrow is known as the emitter, the other the collector). If there's no current flowing into the base, then no current can flow from the collector to the emitter.

Boolean logic

Great! Now you know how to use a transistor, but how does that help us?

To explain this, we need to step back and think a bit about boolean logic. Boolean logic is a system for determining the value of various statements, a bit like ordinary mathematics. The difference is that in the boolean system, there are only two possible values for every statement: 1 or 0 - true or false.

For instance, you can use boolean logic to evaluate the sentence 'My hands are cold'. If my hands are cold, then the boolean result of this statement is true. If they're not, it's false.

Boolean logic isn't restricted to evaluating a single statement at a time, however, since it also has operators, just like in normal maths. 'My hands are cold AND my feet are warm' is only true if both halves of the statement are true; 'My hands are cold OR my feet are warm' is true if either one, or both, of these statements are true. These kinds of statements are often summarised in truth tables, and below are the truth tables for the two operations we've seen so far:

table 1

There's one other key operation that we'll come across, called NOT. It interprets only a single statement, and inverts its value. The truth table is as follows:

table 2

Logic and transistors

AND gate

Being able to evaluate whether or not a statement is true or false, with the help of operations such as AND, OR and NOT, turns out to be the basis for all computer operations. How this is so will become clear later, but for now let's look at how the humble transistor enables us to evaluate boolean statements.

The first point to note is that, whereas above we were dealing with English language statements, when it comes to electrical circuits the only tool we have at our disposal is whether a circuit is on or off, just like the lightbulb. Fortunately, boolean logic deals with precisely two values.

From now on then, 1 (on) will represent true, and 0 (off) will represent false. Let's start by creating what's known as an AND Gate, the electrical equivalent of the boolean AND operation.

Take a look at Figure 3. Here, you can see a circuit. This time there's no battery, but a fixed power source instead. To complete the circuit, we need a ground connection, which acts like the opposite side of the battery. If there's any break between the power source and the ground connection, then no electricity will flow in the circuit.

LED and transistors

You'll also need to note that the LED (light) is being used to represent the result of our boolean operation, and that the two resistors (small components used to reduce the flow of electricity - you could also turn down the voltage of the power source) are being used to protect the transistors. Without them, the transistors would operate strangely!

Now, look at the transistors. They're being used as switches, just like we did earlier. What's interesting is that they're both sat between the LED and the ground source. For the circuit to be complete (and for the LED to be on, and our result 'true') both transistors have to be conducting electricity from the collector to the emitter. If either one of them is open, no electricity flows and we get a false result.

If you want to experiment with this circuit yourself, and confirm that it really does recreate the truth table for AND, you can install KTechlab. You can drag and drop components from the left-hand side, drag wires around, and then toggle switches to see the results. Every circuit we create from now on can be recreated with KTechlab, and you can find the .circuit files on this month's DVD.

Two more gates

OR and NOT gates

Before moving on, let's look quickly at how to make OR and NOT gates from transistors, too, since from these three components everything else can be built. Both circuits can be seen in the diagram above.

We'll start with the OR gate, since that's easiest. It's almost identical to the AND gate, but rather than placing the transistors inline, they're both connected to the power source and ground separately. This way, if both are off no electricity will flow, but if either one is on electricity will flow and the light come on.

The NOT gate is a bit more complicated. The light is on by default, since it's connected directly to both the power source and ground. That accomplishes the first part of our truth table. But why does the light switch off when we connect the transistor? Surely the light is still connected directly to the power source and the ground?

The reason is that in a parallel circuit such as this one, the electrical current gets divided between each branch (in this case, the transistor and the LED) in proportion to their resistance. Since the transistor has such low resistance, almost all the current goes through it and not the LED.

Of course, it's not perfect, and to ensure that the current going to the LED is low enough for it to not turn on, we introduced a resistor to reduce the current further.

Simpler symbols

XOR gate

That's all the basic components we need to build from their transistor building blocks. Out of these, an entire computer can be built! Pretty incredible.

Building more complex circuit diagrams on top of these will start to look messy, but fortunately KTechlab provides premade AND, OR and NOT gates, with reasonably sized and distinct symbols that will make them easier to work with. We'll be using these from now on.

Each gate's symbol is alongside the circuits we made in each figure. To show you how these can be plumbed together, take a look at Figure 5. In this figure, we've made an XOR (Exclusive-OR - true only when either input is true, not both) gate out of the other gates we constructed. We'll be making use of this in what follows, too, so note that it also has a built-in symbol, included in Figure 5.

Making your own computer

Binary maths

OK, we're almost ready to make our adding machine, but before we do that you need to know about the binary number system. Numbers can be represented in many different ways.

In our day-to-day lives, we most often interact with the decimal system. In this system, we have ten symbols, the value of which depends on its place, with each place having a value of ten times that of the place to its right.

In the number 133, for example, the 3 on the far right is simply worth 3. The second 3, however, indicates 30, and the 1 on the left-hand side indicates 100. The value of the number as a whole is the sum of all three places.

Binary is a bit different. Instead of having ten symbols, it has only two: 0 and 1. Because there are only two symbols, each place in a binary number is worth twice that of the number to its right, not ten times.

Take the binary 011, for example. The 1 on the far right is worth 1. The 1 next to that, however, is worth 2. Just as before, the value of the number as a whole is the sum of both places, so 011 in binary is 3 in decimal.

Note that binary might represent numbers differently, but it works in the same way. This means that all the usual tricks for adding, subtracting etc, still work.

Binary is important in computers because it's easy to manipulate and store via electronic mediums. A 1 in binary can be represented by the presence of electric flow (a closed switch) and a 0 by the absence of flow (an open switch).

Half adder

Half adder

If you're thinking that sounds like the kind of system we could work with using boolean logic, you're right. In what follows, we're going to combine everything we've learned so far to create a simple machine capable of adding two binary numbers together.

Let's start by thinking about what it would take to add two one-digit binary numbers together. Try writing out the binary sums for all the possible combinations of 0 and 1. You can use columns and carry numbers, just as you would with binary arithmetic. You should see that, because 1 + 1 requires us to carry a digit in binary to account for all possible one-digit additions, we'll need to provide for a two-digit outcome.

We can represent this in a truth table:

table 3

Look at each Output column in the truth table. The Carry column looks just like an AND gate's truth table, while the Sum column looks just like an XOR gate (not an OR gate, because the output shouldn't be 1 when both inputs are 1). Given that that's the case, we can make a circuit to represent this by connecting an AND gate and an XOR gate to the same inputs.

The output of the AND gate represents the carry, the second digit in the addition's result, and the XOR gate the sum, the first digit in the addition's result. You can see this circuit in the files on the disc.

Full adder

Full adder

This is what's known as a half adder. It's pretty cool, right? You've now seen how controlling the flow of electricity enables us to do real work - we've managed to perform a mathematical operation just by pointing electrons in different directions!

As cool as the half adder is, however, it doesn't get us very far. Because it supports only operations on one-digit numbers, we can't count to numbers greater than 11 (3 in decimal notation).

There is such a thing as a full adder, however, and as the name suggests, it's composed of two half adders (with a slight modification). Start in the same way as before, this time doing the addition for two two-digit binary numbers.

If you do the sums with columns, it's like doing two single-digit additions. You do the addition on one column, carry the result if necessary, and then do the sum on the second column, carrying the result if necessary. Adding an arbitrarily large number, then, is 'just' a case of stringing together lots of single-digit additions, lots of half adders.

We say 'just', because if you look at the second column, there are three inputs: A, B and the carry from the previous stage. To figure out how we can do this, let's draw another truth table:

table 4

Study this table carefully, looking first at what inputs are needed to arrive at the S column, and then which inputs are necessary to arrive at the Cout column. You should see that S = (A XOR B) XOR C and Cout = (A AND B) OR (Cin AND (A XOR B)).

If we map this onto a circuit diagram, as in Figure 6, you'll see that the result is two half adders, with an additional input, and their carry bits combined in an OR gate.

This is a full adder. Alone, it's capable of adding three single-digit numbers, but they can be 'cascaded' together, by plugging the Cout of one full adder into the Cin of another, to add any sized number. Each full adder is responsible for doing 'one column' of the final sum.

A long way off

That brings us to the end of this article. We've come a long way, progressing from basic electrical circuits all the way through to making an adding machine capable of summing arbitrarily large numbers. But we're still a long way off having a real computer.

What we've created in this article would be part of a computer's Arithmetic Logic Unit. In a real computer, the ALU would be capable of many other operations, too, including subtraction, multiplication, and plain logical operations such as AND, OR and shift left and right.

The ALU would be provided with numbers to operate on, and told which operation to carry out, by a device known as the Control Unit, which in turn would fetch the instructions and operands from memory. All of these other components, however, are also made from the same basic logic gates that we've used in this article, they're just put together in different ways.

computers processors logic gates electronics tutorial computingrecommended-en-gb computingrecommended-en-us computingrecommended-en-au
Share this Article

Most Popular

Edition: UK
TopView classic version