Mechanical Engineer
Pocket sized logic gate 8 bit ALU
If you have spent any amount of time on my website, you have most likely seen my original PCB business card. While it was a great conversation starter, it had a couple of issues. The main one for me was size: the height and width were that of a regular business card, but the battery holder on the back made it much too bulky to conveniently fit anywhere. The second is that a business card sized game console just isn't that new anymore. I have seen countless projects (like this one) that absolutely blow mine out of the water in terms of looks and performance. Because of this, I decided to go back to the drawing board and make something I have never seen done before in a business card format.
An ALU (Arithmetic Logic Unit) is the beating heart of any processor and is responsible for arithmetic like addition and subtraction. If you are familiar with Ben Eater's wonderful breadboard 8 bit computer project, you have seen this type of ALU in use before.
I have always had an interest in logic gate computers and thought one would make for a very unique business card. I could have just added a 4 or 8 bit adder chip (like the popular 74LS283) and called it a day, but I decided to limit myself to only basic logic gates. (Maybe one day this could be done entirely with transistors, but that is a project for another day.) Due to the limited space on a business card sized PCB, and wanting to keep the price below 5 dollars, I fought back the urge to keep adding features and settled on an 8 bit adder with the option to do subtraction as well.
I started the project with a basic one bit ALU:
A1─────┬──►│XOR
│ │XOR───┬────►│XOR
B1───┬─┼──►│XOR │ │XOR────►SUM
│ │ ┌─│────►│XOR
C────│─│────────┤ │
│ │ │ └►│&&
│ │ │ │&&───►│OR
│ └──►│&& └──►│&& │OR──►Carry Out
│ │&&────────────►│OR
└────►│&&
This may look complex at first glance, but when you break it down into its individual paths it begins to make more sense. A1 and B1 are the two main inputs, along with C, the carry input from the previous ALU. If only one input is active, the output (SUM) should be active. If both A1 and B1 are active, SUM should be off and Carry Out should be active instead. The last XOR gate at the top handles the carry in bit from the previous ALU, so when A1, B1 and C are all active, both SUM and Carry Out should be active.
Let's start with a simple example. Imagine an input of:
A1 | 1
B1 | 0
C | 0
The first XOR gate gets a 1 and a 0, resulting in a 1.
A1(1)────►│XOR
│XOR──►(1)
B1(0)────►│XOR
With no carry bit, the second XOR gate also gets a 1 and a 0, so SUM is 1.
A1(1)─────►│XOR
│XOR───(1)──►│XOR
B1(0)─────►│XOR │XOR────►SUM(1)
C (0)─────────────(0)──►│XOR
Now let's look at an example that activates the carry bit, with both A1 and B1 set to 1:
A1 | 1
B1 | 1
C | 0
The first XOR gate results in 0, but the AND gate below it outputs a 1.
A1(1)──┬──►│XOR
│ │XOR─►(0)
B1(1)┬─┼──►│XOR
│ │
│ └(1)►│&&
│ │&&─►(1)
└──(1)►│&&
That 1 from the AND gate goes on to the OR gate, where it passes straight through and sets Carry Out to 1.
A1(1)──┬──►│XOR
│ │XOR───┬─(0)►│XOR
B1(1)┬─┼──►│XOR │ │XOR────►SUM(0)
│ │ ┌─│─(0)►│XOR
C(0)─│─│────────┤ │
│ │ │ └(0)►│&&
│ │ │ │&&─(0)►│OR
│ └(1)►│&& └──(0)►│&& │OR──►Carry Out(1)
│ │&&(1)─────────(1)►│OR
└──(1)►│&&
Now for a more complicated situation. Imagine an input of:
A1 | 1
B1 | 0
C | 1
This is a case we haven't seen yet. We know this should result in a high Carry Out, but let's look at which logic gates make that happen.
A1(1)──┬──►│XOR
│ │XOR───┬─(1)►│XOR
B1(0)┬─┼──►│XOR │ │XOR────►SUM(0)
│ │ ┌─│─(1)►│XOR
C(1)─│─│────────┤ │
│ │ │ └(1)►│&&
│ │ │ │&&─(1)►│OR
│ └(1)►│&& └──(1)►│&& │OR──►Carry Out(1)
│ │&&(0)─────────(0)►│OR
└──(0)►│&&
When these ALU modules are chained together, with each Carry Out linked to the Carry In of the next module, the result is a scalable adder. Eight of these modules make up the ALU on my business card, and by adding an XOR gate on each B input, a switch can be added to allow for subtraction as well.
Below is an interactive ALU demo. Try out the examples above, or put in any combination of inputs you want!
A1(0)──┬──►│XOR │ │XOR───┬─(0)►│XOR B1(0)┬─┼──►│XOR │ │XOR────►SUM(0) │ │ ┌─│─(0)►│XOR C(0)─│─│────────┤ │ │ │ │ └(0)►│&& │ │ │ │&&─(0)►│OR │ └(0)►│&& └──(0)►│&& │OR──►Carry Out(0) │ │&&(0)────────────►│OR └──(0)►│&&
One of the biggest inspirations that made this project possible was finding this super smart, low profile CR2032 battery holder, which uses parts of a paper clip and a unique footprint to hold the coin cell inside the PCB. This massively cuts down on the thickness of the finished board and improves the look a lot. The next challenge was finding low profile SMD switches. I settled on C2681568 from LCSC: at 1.4 mm tall above the PCB, it was the lowest profile option I could find, and at only 3 cents each the price made them an easy choice. I went through many design revisions for the switch layout and eventually settled on the following.
With switches on both sides of the PCB, the total thickness comes to around 4.6 mm on a 1.8 mm board (IMO the sweet spot for nice feeling PCBs). The rest of the board was fairly easy to lay out, although the limited size did make some of the routing a little tricky.
This write-up is still a work in progress.