The Electronics Tales of an Ingenuous Geek

The Beginning

A few months ago, while I was enjoying breakfast with a friend of mine, we happened to talk about how it would be cool to build a video game console from scratch. He mentioned a book called “The Black Art of Video Game Console Design” and how much he enjoyed it during college. He also added that I should probably get it if I wanted to take on the challenge.

I still cannot explain to date why I did it. A few days later I purchased it while ingenuously looking forward to an easy and interesting reading.

The Mistake

When the three kilograms, one thousand pages book arrived I then realised the mistake I made. It was surely interesting…but not easy at all! It was all about electronics, circuit analysis, simulation and PCB design. In a nutshell what the title said: the art of building a console using electronics components. Only God knows what I was thinking and why I kept listening to my friends.

What do you think any sane person would have done? Thanking the 30 days return policy and give it back, right? No, I decided to keep it and to study it instead. I put aside Ghost of Tsushima, which had just been released, and I started an unexpected journey into something I didn’t see coming.

Very little I remembered from my undergraduate degree. Luckily the book starts easy, giving the reader some general notions: how electrons are moved by a potential difference, the difference between AC and DC, the definition of an Ampere, Coulomb, Joule, Volt and so on.

While I was progressing through the chapters, something about the subject struck a cord in ways I cannot explain. The more I learned the more I became eager to study.

Honestly, who does care nowadays how a transistor, a diode, a capacitor or a resistor work? And yet they are the building blocks of any CPU, video game console, mobile phone, TV and anything really these days.

Hello World!

With some initial and renewed knowledge I got a breadboard, a construction base for prototyping of electronics, a resistor and a light emitting diode or LED and did this:

The hardware equivalent of Hello World! Even if it was something simple I was so happy!

“I can do this” I thought. After that something changed. I was thrilled, excited and eager to discover, learn and experiment more. I kept on reading the book and when I completed the chapter about transistors and how to build simple gates I bought a bunch of them and tried myself!

The Inverter Gate

Getting how transistors work is easy. They are essentially a switch controlled by an input current. However setting them up and understanding their different properties and which one to use depending on the use case can take some time.

After some initial tinkering and trial-error I built my first inverter gate:

Pressing the tactile switch sinks the current to ground and the LED turns off.

The excitement took over this time. It was time to build something bigger and more challenging (very much like programming isn’t it 🙂 ). Space on a breadboard is limited and in order to build something more complex I needed to tackle the problem from a different angle. It was time to go back to reading mode!

The Answer

I found my answer after I finished the chapter about TTL (transistor-transistor logic) chips. An entire family of integrated circuits, called the 7400 series and introduced for the first time in the late 60s. It contains hundreds of devices that provide everything from basic logic gates, flip-flops, and counters, to special purpose bus transceivers and arithmetic logic unit. They were super expensive back then but now they are extremely cheap.

While I was surfing the web for for ideas on what to do with them I came across a cool and interesting video series made by Ben Eater on how to build an 8 bit CPU using breadboards only and the 7400 chips. Of course, building a CPU would be amazing!

And there I had it, the perfect project for my electronics needs.

The SAP 1

The CPU is based on the SAP 1 (simple as possible) as explained in Paul Malvino’s book called “Digital computer electronics” from 1976.

sap 1

In the first four videos Ben explains how to build a clock module. He’s really good at breaking down complex topics into something easy to understand. I’m not ashamed to say that I must have watched those four videos a hundred times. Despite them being easy to follow, there’s a lot of knowledge to be digested, especially for a beginner.

I didn’t just want to follow a guide on how to build a CPU step by step. I wanted to deeply understand it. Period. I needed to know where to place ICs, how to wire them and why.

The Clock Module

Many hours, videos and articles later I finished the clock module with some of my own modifications from Ben’s version.

The clock module

It felt fantastic. After all the effort and hard work the clock module was working. The only problem left was…well it was just a clock module! I actually needed others if I wanted to make something useful with it.

The Untold Truth

The real challenge though began when I added more modules to the build. I later found there’s an untold truth with this project: even if you follow exactly the videos and do what Ben does, you’re very likely going to bump into issues unique to your build, setup and components you use and of course mistake you make.

I built the registers A and B and eventually the instruction register. It was all good until I connected everything together. I turned it on and after a few seconds the LEDs, all of them, started flashing in a random order, very much like a Christmas tree. I triple checked that I connected pins correctly, and when I couldn’t find a solution I searched online.

Troubleshooting

This was my first lesson learned in the electronics world. Like in software, if you have a bug you don’t google the specific issue you’re having. You debug your code, you try to replicate or isolate the issue until you find and fix it. If you google: “My circuit flickers like a Christmas tree” I bet you won’t find many useful results (Disclaimer: I actually googled it)

At that stage I realised I was not able to troubleshoot/debug my circuit and I actually didn’t have any tools for it. In particular:

  • A multimeter: a nice tool to measure current and voltage.
  • An oscilloscope: a handy but expensive tool to graph the voltage change over time
  • A logic analyser: super handy and also very expensive tool to verify the logic of your circuit.

Buying all of them was too expensive and probably unnecessary. I bought a cheap multi-meter and I spent some time figuring out how to use it properly. YouTube helped a lot with that.

I troubleshooted module by module until I found the bug. I had inverted the connection to the +5V pin with the ground pin on one of the registers!

Troubleshooting in progress

With the instruction register finally working it was time to move on and build the ALU!

Along Came the ALU

It was fun building the ALU. I managed to complete it without watching the videos. I read about 2’s complement though in the book and also watched Ben videos on the topic.

And of course I was punished for not reading the datasheet correctly…I had inverted the connection of the least with the most significant bit. In fact the result was the reverse of what I would expect.

Well done me! Not only was it reversed but it was wrong too! 11 + 11 is actually 110 not 111.

I unplugged all the wires and started again from scratch. After some more tinkering I completed the ALU. This time it worked fine:

111 – 101 = 10

The Frequency Counter Module

With the clock module, the registers and the ALU working, I started putting together the RAM which is still a WIP. I have been working in parallel on another module to measure the clock module frequency. In the 90’s PCs had the two digits 7-segment display showing the CPU frequency in megahertz, and I thought it’d be cool to have something similar.

aaah the good ol’ days

This is what I came up with and guess what…it’s a flawed design (well done me again \o/ )

Unfortunately it’s not precise at all. I used the 555 timer instead of a quartz oscillator. A frequency of 1Hz is detected as 0 or even 3 hz which is pretty bad. As the frequency goes up the error increases thus the module is totally useless. I need to explore alternatives, but this is what happens when you don’t follow any guide, you mostly don’t know what you’re doing and you explore and play with electronics. But it’s fun nonetheless even if you don’t get it right the first time!

The Best Worst Mistake ever Made

I can’t believe I fell in love with electronics so much. Over the last few months I’ve learned a lot and I’m still doing so everyday. Buying that book about video game console design was the best worst mistake I’ve ever made 🙂

That’s it for now. When I finish building the RAM and the control unit I’ll write a follow up article. When I have time I’ll write another one with all the challenges and the technical pitfalls of this project.

I hope you enjoyed the article, see you soon!