4-bit CPU from COMPLETE SCRATCH banner

4-bit CPU from COMPLETE SCRATCH

25 devlogs
34h 0m 17s

I have always been dreaming of building a CPU from scratch, which means only transistors, resistors, and capacitors are allowed!!!

Demo Repository

Loading README...

Hung-Chi Wang

Shipped this project!

Ik this project might look a little intimidating at first, and thus I reshipped this because I believe it deserves a better payout………
I polished the repo and demo, and hopefully people can learn more about how challenging it is to build even an adder from complete scratch using discrete transistors

Hung-Chi Wang

Spent some time updating readme and release!!
This is really the best project i’ve ever made, even though it might look a little intimidating!!!!
*** Btw i also rendered this, and this is exactly how the final product will look like

Attachment
0
Hung-Chi Wang

Shipped this project!

Hours: 33.59
Cookies: 🍪 528
Multiplier: 15.71 cookies/hr

When I first told my friends about this project, they laughed at me cuz they didn’t believe how building this was even possible. This is a very huge milestone as I finally understood how computers work! I learned many things including the basics like logic gates, transistors, and fan-out (this was obnoxious)
btw XOR caused TONS OF TROUBLES and almost killed my interest lol (btw there were two types and the one failed was the one driving two bases)

Hung-Chi Wang

Tested out my XOR gate (the first version) but unfortunately it didn’t work as well as expected

  • 4.7k ohm for base resistors
  • 1k ohm for pull-up
    *** I did this 2 days ago but I just forgot to log it
0
Hung-Chi Wang

Ok so I finalized my schematic after postponing for a month particularly cuz got a little lazy
Next up imma start routing the full-adder and order it
I also tested out all different cases to make sure I get it right the first shot

Attachment
0
Hung-Chi Wang

I spent some time on soldering the logic gates, including AND, OR, NAND, and NOR gates. However, because I forgot to cut the wires before turning them on, I accidentally burnt the OR and NOR gates……DAMN
Overall, the AND and NAND gates worked pretty well:

  • 10k resistors for the base
  • Diodes to prevent current from leaking
Attachment
0
Hung-Chi Wang

Time to test out all my logic gates!!! For the past hour I was learning how to use V-Cut for my PCBs as they’re all very small so it’s not very wise to put them all on separate boards. Merging AND and OR gates is kinda tedious tbh

Attachment
Attachment
Attachment
0
Hung-Chi Wang

Here’s what I did for the past one and a half hours:

  • Learned and implemented another type of XOR gate (*This is better as one input can now supply one transistor instead of two)
  • Designed isolated AND gate schematic
  • Designed isolated OR gate schematic
  • Simulated ALU (Adder + Subtractor)
  • This time I included base resistors for all the transistors
Attachment
Attachment
Attachment
0
Hung-Chi Wang

I spent one and a half hours trying to figure out Subtractor and complete the entire ALU………BUT KICAD is acting so weird……..
4-bit adder acts perfectly but for some reason subtractor just doesn’t want to listen……..AHHHHHHHHH

Attachment
0
Hung-Chi Wang

(Troubleshooting) GUYS MY 4-BIT ADDER WORKS PERFECTLY!!!!!! Especially after I added buffers to each split!!!! W buffers
Btw I was fixing my 4-bit adder for the whole time cuz apparently Kicad spice doesn’t really recognize GND, so instead you gotta use 0V instead

Attachment
0
Hung-Chi Wang

I spent two hours and a little more learning negative numbers (subtraction) and SR latch (can be easily turned into D latch)
Lemme briefly explain why they’re important

  • Negative number (subtraction): I mean obviously subtraction is important lmao…….
  • SR latch/ D latch: SR is the acronym of Set and Reset, Set sets the state to 1 while Reset restores the state to 0. And this property can be used to store data!!!

BTW the image only shows how subtractor works, but i promise i’ll be demonstrating through videos of how registers work!!!

Here’s the steps to convert a positive number to a negative number

  • Step 1: Invert all the digits (e.g. 7 represented by 0111 becomes 1000)
  • Step 2: Add one to the inverse (e.g. 1000 + 1 = 1001)
    AND BOOOM 1001 represents -7, just look at the image
Attachment
Attachment
Attachment
0
Hung-Chi Wang

Finished routing the PCB!!! OMG I really really can’t believe how compact this can be……..Cuz it’s so tiny compared to the prototype on breadboards!!!!!!

PS: This is a Full Adder btw

Attachment
Attachment
Attachment
0
Hung-Chi Wang

For the past one and a half hour I have been building a 4-bit adder…….but fan-out is definitely my enemy!!!!
As you can see the 5V drops to 4.53V bc of the transistors!!! I was trying to implement two inverters at the end but still didn’t help…….

Attachment
Attachment
0
Hung-Chi Wang

I finally found out the issue!!!
The issue was that I forgot to add resistors to the base of each transistor. I only added resistors directly after A, B, and Cin, but the bases of transistors in each sheet don’t have their own resistors, so that’s a big issue as they will burn out.

W Resistors :)

Attachment
0
Hung-Chi Wang

Fixed and tested out all the truth tables for my schematic, and not all of them worked……
Even though it seemed like only one of them didn’t work (the one with only Cin on), but for some reason no current was passing through one of the transistors in the XOR gate!!!

SO I gotta spend some time investigate……

PS: All the images are different cases even though they look similar!

Attachment
Attachment
Attachment
Attachment
Attachment
Attachment
Attachment
Attachment
0
Hung-Chi Wang

Completed the FULL ADDER schematic!!!!!! Btw here’s some of the things I changed:

  • Added an inverter to each gate for output
  • Added diodes (tbh Im still not sure whether I should use diodes or resistors…….
  • Created hierarchy sheets for AND, OR, and XOR gates (SUPER SUPER USEFUL
Attachment
Attachment
Attachment
Attachment
2

Comments

Hung-Chi Wang
Hung-Chi Wang 3 months ago

Go to the last page to see the full schematic!!!

khmaissilahcen
khmaissilahcen 3 months ago

that’s awesome

Hung-Chi Wang

Completed the PCB design of XOR gate!! I tried to make it as compact as possible

GUESS WHATTT, IT’S TIME TO BUILD A FULL ADDER!!!!!!!!

Attachment
Attachment
0
Hung-Chi Wang

Finally completed the schematic for an XOR gate. Despite building it on the breadboard, I still struggled with whether I should place a diode or a resistor…….But after doing some research I decided to go with a diode, and here’s the reasons:

  • Resistor regulates the current indeed, but it’s based on R=V/I, so the voltage drop is not fixed
  • Diode, on the other hand, ensures a 0.7V voltage threshold, preventing current from leaking
Attachment
0
Hung-Chi Wang

Completed schematic for AND, OR, NAND, and NOR gates!!!! Can’t believe I proceeded that fast lol, but Kicad still made it way easier than prototyping on breadboard trusttt

Attachment
0
Hung-Chi Wang

OMG THIS IS SOOOOO FRUSTRATING…………but I finally completed my breadboard prototype for AND and OR gate, btw this is my first time using transistors so it took me quite a fair amount of time

Here are just some things to watch out for:

  • Remember to put LED and resistors on the connector side, both to pull up and avoid current not flowing from the base to emitter!!!!
  • Remember to put resistors for both transistors and the buttons, I just burnt two of them :(
Attachment
1

Comments

bgtulk
bgtulk 3 months ago

Nice job!

Hung-Chi Wang

OK I finally began my journey towards building a fully functional CPU!!!!!
First up ADDER:

  • A design that can add two numbers
  • How binary is used
  • How logic gates are built are used, including AND, OR, NAND, NOR, and XOR
Attachment
0