Now it’s time for something completely different.

I know this website is mainly vehicle focused (hence the name “Motors” in the name), but like most people, I have another hobby – electronics. Now, sometimes these two hobbies intertwine, which will be the next post I make, but for this post… they don’t. So, hang in there and automotive content will return soon!

Since this post is obscenely long, go ahead and watch this video first to see where we’re headed.

Now, before I get too deep into what on Earth you’re looking at in that picture, go to Youtube and watch all of Ben Eater’s videos on building an 8-bit computer from scratch. The man is brilliant and one of the best teachers of electronics I have ever seen.

Ben Eater’s Youtube ChannelI’ve dabbled into and out of electronics ever since I was a kid, making radio kits then, and upgrading into BEAM robotics and desktop trinkets. BEAM is incredibly interesting because it’s robotics with no programming and usually solar powered, so the designs have to be incredibly efficient (and usually misuse components to get the job done).

But, the desire for more complexity leads to programming. Now, when we think of programming we often think of high-level programming. These are languages like C#, VisualBasic, Javascript, etc. However, those languages don’t really give you an insight into how exactly the machine works, and if you frequent this (rarely updated) site, you know that I like to know how things work. For this, you need to dabble into low-level programming, like Assembly, or ASM. However, if you dive straight into ASM, you’re very likely to get completely and totally lost. It actually makes more sense to go one step lower into how the actual machine works, without thinking about programming at all.

And that’s where this story begins.

The primary building block of any and all computers is binary. A “1” or a “0”. This is because binary can be represented as “on” or “off”, or more simply, 5 Volts or 0 Volts. One point that can be either 5 Volts or 0 Volts is what is called a “bit”. That bit can be on or off, or a 1 or 0. String eight bits together for something that looks like this “0011 0101”, and you’ve got yourself a “byte” of information. String together 1,000 of those and you’ve got a “kilobyte”. String together a thousand kilobytes and you’ve got a “megabyte”. A thousand megabytes, and you get a “gigabyte”. Then a “terabyte”, then a “petabyte”. As of writing this, petabytes of storage are slowly starting to become more commonplace and big server farms are actually pushing into “exabytes”, with Google supposedly having 10 to 15 exabytes of storage space.

Now, storage is one thing, but computers actually do stuff. And by stuff, I mean “math”. Everything is based around adding numbers. Even subtraction, multiplication, and division are all some derivation of addition. For, example, if I want to multiply 12 x 5, all I really do is just do 12 + 12 five times.

But remember, computers work in binary, so if we want to do 12 + 12, that’s actually 1100 + 1100. Now, that looks strange, but since binary can only be a 1 or a 0, we have to do a little mental math to figure out what number is represented by those four bits. Binary reads from right to left, like Japanese, with the right most bit being worth 1, the second most bit worth 2, the third most worth 4, the fourth most worth 8, and so on, doubling each time.

1100 is 8 + 4 + 0 + 0, which is twelve. 1111 is 8 + 4 + 2 + 1, which is 15. 0101 is 0 + 4 + 0 + 1, which is 5. You can see that with four bits, we can represent any number between 0 and 15. Now, how do we add two numbers together?

Like normal addition, you add the top number to the bottom number. And in normal addition, if the number is larger than 10, you write the first digit down below and “carry” the second digit over to the next column you’re adding together. The same principle applies here, but you carry a 1 if the number adds together to be larger than 1. If we add 1 + 1, the answer is two, which is 10 in binary. So, you write the 0, and carry the 1 to the next column. If you have a carry in your column already and you add 1 + 1, you have to add the carry as well, so that becomes 1 + 1 + 1. The answer is three, which is 11 in binary. Write the 1 and carry the 1 to the next digit.

Awesome, now we know how to add binary, it’s easy peasy from here, right? Not quite, 4-bits of binary is any number up to 15. If I want to add larger numbers, I need more bits. 8-bits of binary is any number up to 255, 16-bits any number up to 65,535, and so on. But wait a minute, there were tons of 8-bit and 16-bit systems and PCs, like the NES/Famicom, NEC-PC8001, TI-99/4A, etc. Being 8-bit meant it could only do math on 8-bits at a time. So, how did they do math on large numbers? Loops! That’s how. Instead of adding or subtracting the entire number at once, they break it up into 8-bit sections, and then loop through until they have the answer. Here’s an example with some random numbers:

3,692 + 4,503

3,692 in binary is 0000 1110 0110 1100

4,503 in binary is 0001 0001 1001 0111

Now, you just do the math on the first eight bits and then loop around and do the math on the second 8 bits. The first 8 bits of 3,692 are 0110 1100 and the first eight bits of 4,503 are 1001 0111.

0110 1100

1001 0111

From right to left adding the top number to the bottom number:

0+1 = 1

0+1 = 1

1+1 = 0 (1) > The parenthesis is our carry

1+0+(1) = 0 (1)

0+1+(1) = 0 (1)

1+0+(1) = 0 (1)

1+0+(1) = 0 (1)

0+1+(1) = 0 (1)

So, the first 8 bits of our answer should be 0000 0011. In a computer, we’ll store this somewhere, like a Register, which is a temporary memory location. Then we do the same procedure for the second eight bits. The actual answer is 8,195, which is 0010 0000 0000 0011. You can see that the first eight bits (from right to left) are the same as those the we just figured out doing the math manually. Okay, that’s how addition in binary works. I won’t go into subtraction because it’s a little more complicated, but you get the idea.

Now we’re getting to the meat and potatoes of this (obscenely long) post. Like old cars, I’m fascinated with the technology of the 40s, 50s, 60s and 70s. For cars, more into the 60s and 70s, but for electronics and computer, more into the 40s and 50s. And, one of my ultimate goals is to someday create a relay computer, like those that were used before and in direct competition with vacuum tube computers. Yes, relays, like the click clack on/off type. I’m of course not the first person to ever think of this, relays are fantastic for making logic gates (AND, OR, NOT, NAND, NOR, XOR, and XNOR). Logic gates are another massive post, so I’ll just mention them here and if you’re really curious, check out the link below.

Wikipedia Entry on Logic Gates

This is the FACOM 128, a relay computer made by Fujitsu in 1956 that uses around 5,000 relays to do some pretty fantastic math.

Obviously, I have zero intention of buying 5,000 relays and trying to build something on that scale, but I think relays sound therapeutic and are fun. Also, obviously, relays do have their limitations. To make something 8-bits wide with relays is difficult. It takes a massive number of relays, which takes up a lot of space and money. 4-bits is much easier, but if we’re just doing simple math, as we saw earlier, all that means is we’re just doing loops. We can loop around as many times as we need, so what if we only did 1-bit? Sure, it’d be a lot slower, but the little Omron relays I’m using have a limit to how fast they can switch on and off, which means if I pushed them to their absolute maximum, I could almost get 1 KHz of processing speed. So, speed went out the window a long time ago.

Enter my idea for 10-bit addition/subtraction calculator that uses a 1-bit ALU (Arithmetic Logic Unit).

I started designing and came up with these six boards to achieve what I wanted:

Here’s how it should work.

You input your numbers in binary on the top two rows of the Input board (the first board). Each row supports up to 10-bits, which means any number from 0 to 1023. Then you press the little button and it spits out the answer on the bottom row of LEDs. There are 11 LEDs, so it’ll display an answer up to 2,047 (which is 1023+1023).

When you push the button, the Sequencer
(the 2^{nd} board) starts stepping through each of the 10 bits one by
one all the way to the end.

When the Sequencer steps through a bit, it sends 5V into the corresponding bit for the first and second number. If the switch is on, that 5V bit is sent to the 1-bit ALU (the last board).

The 1-bit ALU takes the input from the two numbers as well as a carry if there is one and outputs the sum into one of the two Sum Registers (the 3^{rd} or 4^{th} board) and outputs the carry into the Carry Register (the 5^{th} board) for use on the next bit. The LEDs on the bottom just show the contents of the two Sum Registers, which is subsequently, the answer to the math problem.

It sounds ridiculous and as you’ve already seen, it is completely ridiculous. So, where did the PCBs come from? Well, I made them! I drew up the design itself in a program called DesignSpark PCB. I then exported each board into a Gerber file. Those Gerber files were then imported into a program called FlatCam to create G-Code, which our old Bridgeport 3-axis CNC mill, which is massively oversized for this job, can run.

Once I had all the boards cut, I soldered on all the necessary components. In total: 90 relays, 96 diodes, 22 capacitors, 32 resistors, 32 LEDs, 21 switches and 1 button.

Then, it was just a matter of connecting them all together. I designed in a hole for a long piece of all-thread to go through with nuts, washers, lock washers and spacers to properly space the boards out and hold them in place. Then, I ran individual wires through each board to allow data to be sent back and forth from board to board. This is the result.

And here’s the video of me operating it one more time (so you don’t have to scroll back up to the top to watch it again).

Despite how long this post is, there’s actually a ton of fundamental stuff I left out regarding building computers and understanding how they work, but hopefully I can spark a little fire for knowledge in you and Ben Eater’s fantastic videos can help fan the flames!

Also, I’m still very much so a beginner at all this, so there are many inefficiencies and mistakes in my design. In actuality, I run into a bit of a power draw problem when I have certain numbers that require most of the LEDs to be illuminated, which causes some issues with the Sum Registers storing properly. So, it’s very much so a learning process for me as well!

Thanks for sticking with me through this non-automotive post!