Note #10
Building the Cambridge-1: A 4-bit homebrew 7400 based CPU

With a handful of 7400 series ICs and an appreciation of the fetch-decode-execute cycle, it's possible to build a simple digital computer in less than 30 days.

I have, for quite a while, had some ideas swirling around in my head to build a 4-bit 7400 series based CPU. And like all good ideas they seemed to be caught up in a never-ending purgatory - never seeing the light of day because ‘life’ gets in the way. However, last month I finally bit the bullet and decided to actually build this imagined machine and I had the perfect excuse - the Retro Computer Festival was just around the corner.

For the uninitiated, the Retro Computer Festival is now a yearly event hosted at the Centre for Computing History in Cambridge, England. It is not only a great exhibition of fantastic retro machines, but an opportunity for a like minded community of computing enthusiasts and makers to get together and share super cool stuff.

In this spirit, I decided to finally build my imagined 4-bit machine and set myself a challenge: what was the simplest computer I could build in 30 days? This question became the genesis of the Cambridge-1 CPU.

Cambridge-1 CPU

But, before I carry on, I should preamble the meat of this post with what I mean by a CPU (Central Processing Unit). Or, more generally, what I mean by a computer… I’m not going to get to pedantic by talking about Universal Turing machines or the history of CPUs, suffice to say I’m generally referring to a basic “digital computer” and using the term CPU somewhat interchangeably.

My definition of a digital computer is a machine which stores binary instructions in a memory store and contains the mechanisms to fetch, decode and execute these instructions to perform some kind of computation. These processes are done in a sequential and repetitive fashion - a machine ruthlessly following the cold logic - with no magic or mechanically induced self-doubt allowed.

Fetch Decode Execute Cycle
High level diagram of the fetch-decode-execute cycle

So, sermon over, what can you actually build in 30 days? Well, with a bit of patience and determination, a nice little digital computer. The Cambridge-1 features a 4-bit word size, blinkenlights-a-plenty, and some (slightly naughty) Arduino based cheating to virtualise the control unit (more on this later). It also contains an 8-bit data and address path with some instruction set tricks to perform 8-bit operations as well. All this at a whopping clock speed of 40Hz too.

Cambridge-1 CPU
The Cambridge-1 CPU

From the image above you can see the main parts of the computer - the neat-ish wiring (grey = datapath; blue = controlpath), the groups of 4-bit LEDs representing the binary information and the 7400 series ICs (integrated circuits) which process the binary information.

These ICs perform various tasks: the registers (74HC273) store bits of information used during computations; the counters (74HC193) keep track of where the machine is in the current program; the buffers (74HC125 & 74HC244) make sure nothing is writing to the buses when it shouldn’t be and the remaining ICs do the actual maths. This includes a 4-bit adder (74HC283) for the binary addition and a 4-bit (74HC85) comparator to generate the flags for jump instructions. And, before I forget, there’s a (non-7400 series) SRAM chip to store the software!

The machine operates from a simple Instruction Set - comprising of 16 instructions (defined by a 4-bit word) and the basic functions you’d expect: binary arithmetic (adding and subtracting), memory manipulation, jump instructions, IO functions etc.

An introduction to the Cambridge-1

Of course, this all sounds relatively impressive but building this machine caused quite as few headaches. Turns out that wiring something like this is very laborious and easily derailed by a lack of concentration. Breadboards don’t seem to like to dissipate power nicely, so you can end up with strange voltage drops and raised gnd levels to contend with, and debugging it was a nightmare. In the end, however, a bit of engineering instinct and stubborn perseverance helped to overcome these hurdles.

Perhaps though, the most novel part of this machine is the use of the Arduino Micro. Now, homebrew purists reading this may at this point be thinking “that’s cheating!” (and I totally agree) but sometimes pragmatism really does trump theory - it has been rather useful. It’s first job is to write the C-1 instructions to RAM. This means that I can write some instructions in my Arduino Sketch program, compile it and then automatically load the C-1’s RAM with instructions when the Arduino fires up. It’s second job (and perhaps the most important) is as a ‘virtual control unit’...

If I wanted to be a strict purist with the control unit I’d get some EPROMs, hook them up to a sequencer, the instruction register and a clock, and then program this all through the EPROMs to generate the machine’s control signals. However, this would come at a cost - doing so isn’t an entirely flexible thing to do - especially as I was making up the ISA (instruction set architecture) as I went along. The use of the Arduino, along with some ‘595 shift registers to serially generate the control line signals, afforded me the opportunity to change the control logic on-the-fly. This meant I could easily update the ISA, experiment with ideas and also control the clock without carving these mechanisms in stone.

Arduino and '595 shift registers
The Arduino Micro and accompanying '595 shift registers

Eventually, I’d be much happier to get rid of the Arduino and replace it with as much 7400 series logic as I can, but for now, the plucky Arduino Micro is paying out dividends.

So after around 28 days I’d managed to pull this all together and have a working machine. This was great, but it has not left me much time to write the software. Over the next few weeks and months I’m hoping to write some less trivial programs - and to make this easier I’ve already started planning a simulator, assembler and a SD-card add-on to the Cambridge-1 so I have a simple toolchain.

However, I’m not going to completely polish the Cambridge-1 so it resembles something like a contemporary computer, because the real joy of retro-esque computing is the archaic beauty of the machines we build and preserve. They lay bare the real mechanics of computing - the simple, cold and logical processes that expose the primordial DNA of computing.

So next time Amazon’s algorithms try to sell you stuff you don’t need, or Instagram warns you that you’re not giving your selfie friends enough attention, just remember that your behaviors are being controlled by the same simple principles that govern the Cambridge-1.

And that’s important, because occasionally remembering these things might just stop us from sleepwalking into a very strange future indeed. That is, of course, if we’re not already there...

You can follow the latest project updates via ARITH-MATIC on Twitter.

Note by: Richard.
Founder of ARITH-MATIC.
September 2019.

You might also like:
Explore our DIY Electronic Kits: