SEARCH
TOOLBOX
LANGUAGES
modified on 22 December 2010 at 19:23 ••• 104,195 views

4-Bit Computer

From WFFwiki

Jump to: navigation, search

If you’ve ever wondered how electronic devices like computers can count, this article gives a simple introduction to binary and logic and shows how they are tied together with electronics to make both simple and complex computers.

Please note: There are a couple of mistakes on the slides in the youtube video which are shown corrected below. Thanks to reader [Veini] for taking the time to review the logic diagrams!


Contents

Fundamentals of binary counting

To begin with let’s have a look at some fundamentals. Since digital computers can only represent two states, on and off or zero and one, there are only two numbers available; therefore they have to count in base 2, not base 10 as we would do. However, it’s very similar, instead of ones, tens, hundreds and thousands, base 2 counts in ones, twos, fours, eights and so on. So, for example 2 in base 10 is one- zero in base 2.

Slide 1 - Counting in Binary

When we add numbers in base ten we carry over any digits which are greater than 9 into the next magnitude of units, so nine plus one equals zero carry one, or ten.

Slide 2 - Addition in Base 10

Binary works exactly the same, however you carry over if the result is greater than 1, so one plus one equals one-zero.

Slide 3 - Addition in Base 2

This means that if you have two single-figure binary numbers and you add them together there are only 4 possible results.

Slide 4 - 4 Possible results

It is useful to represent this in what’s known as a truth table. Here you can see the 4 possible values of the inputs A and B, and the four possible outputs represented by Sum and Carry.

Slide 5 - 4 Possible results

In order to represent the ‘logic’ required to get from the possible range of inputs to the desired outputs we use Boolean operations, or as they are more commonly called in electronics, logic gates.

Logic Gates

Here are the three basic types of logic gates which I’ve chosen because they are the simplest gates to make from transistors. You can make all other types of gates by combining these three.

Slide 6 - Basic Boolean operations

An AND gate outputs one only when both its inputs are one. An OR gate outputs one when either input is one. Finally a NOT gate (or inverter as it is sometimes called) outputs the opposite of its input, so if the input is one the output is zero and vice-versa.

So, going back to our truth table, let’s look at the logic required to get ‘Sum’ based on the inputs A and B. Here we want the logic to output one only when one input is one and not the other, this is known as an exclusive OR gate. We can do this by simply using two AND gates with NOT gates on opposing inputs. If either gate outputs a 1 the result is 1 via the final OR gate.

Slide 7 - 4 possible results

The carry output is even simpler, we want the carry to be 1 if both A and B is one, so we use an AND gate.

Slide 8 - 4 possible results

To get the whole truth table we simply add the two logic circuits together. This logic is called a ‘half-adder’ due to the fact that it is only capable of working on single bit numbers, since you cannot input the carry bit, you can’t cascade them together to work on larger binary numbers.

Slide 9 - The half-adder

To solve this we combine two half-adders together to make a full-adder. This logic takes A, B and a carry as input and outputs the sum and carry. If you followed along with the half adder it’s pretty easy to see how this works from the logic diagram.

Slide 10 - The full-adder

Now the simple full-adder logic circuits can be combined to allow bigger binary numbers to be added together. This picture shows a four bit adder, in fact, due to the way the carry bit ‘ripples’ down, this is known as a ripple carry adder. Since both the A and B inputs are now 4 bits we can add together 1111 and 1111 or 15 plus 15 in base 10 to get a five bit result.

Slide 11 - A 4-bit adder

Building logic gates from transistors

Now let’s take a quick look at how we build logic gates using transistors. First up is the NOT gate. Here if the input is 1 it causes the electricity to flow from the collector to the emitter (top to bottom). Since the electricity will always follow the path of least resistance the output will be zero. If the input is zero, the transistor prevents the flow from collector to emitter, so the electricity flows out of the output causing it to be one.

Slide 12 - Transistor NOT gate

Next up is the AND gate. This requires two transistors, the inputs are on the bases and only if both inputs are one can the electricity flow to the output, making it a one also.

Slide 13 - Transistor AND gate

The OR gate is similar but has two possible paths for the electricity, so if one base or the other is one, electricity flows to the output.

Slide 14 - Transistor OR gate

Building a full-adder

Once you have these basic building blocks you can combine them together using the logic diagram for a full adder, which gives us this circuit diagram:

Full-adder circuit schematic

Here you can see a picture of a completed full-adder, the A, B and carry inputs are on the left and the sum and carry outputs are on the right. By making more of these it is possible to build adders capable of dealing with bigger and bigger numbers.

Picture of a full-adder circuit

Building a computer

So with all the theory out of the way, let’s look at a real 4-bit computer built from discrete transistor gates. This circuit has 4 switches for each input (A and B) and a simple five LED output showing the result. Note that both the inputs and the output are little-endian meaning the smallest binary value is on the right, just like in base 10. You can clearly see the 4 full-adder circuits which perform the processing.

A 4-bit computer made from transistors

The computer is made by combining 4 full adder circuits (as shown above) and some extra circuitry which drives the inputs to the adders and displays the output:

4-bit computer input and output circuit schematics

Conclusion

And there you have it, how a simple transistor can be made to count. Whilst this ‘computer’ is a very basic one, you can easily see why modern processors contain hundreds of millions of transistors which enable modern computers to perform so much logic at such amazing speeds.

Build your own computer

If you're crazy enough to want to build you own computer from scratch (well, I was!) you can download the schematics and the PCB artwork used in this article from here.



Donate to waitingforfriday.com:

If you like this site and want to help support future projects, or you just want to show appreciation for a project you built, used or enjoyed, please consider leaving a PayPal donation. It's quick, secure and helps us to run the site and fund future projects!


PayPal, fast, easy and secure




Join the EFF:

Join the Electronic Frontier Foundation


The owner of this site is a member of the EFF and you should be a member too! The EFF protects the rights of open-source, open-hardware authors all over the world.



Most popular pages:

  1. Building a PIC18F USB device ‎(252,920 views)
  2. Home ‎(238,401 views)
  3. 4-Bit Computer ‎(104,195 views)
  4. Projects ‎(103,464 views)
  5. Open Source Framework for USB Generic HID devices based on the PIC18F and Windows ‎(103,333 views)
  6. Open Source Visual C++ Class for USB Generic HID Communication ‎(62,760 views)
  7. Real-Time Audio Spectrum Analyser ‎(60,998 views)
  8. Controlling LED brightness using PWM ‎(51,233 views)
  9. USB RGB LED VU Meter ‎(49,637 views)
  10. PIC USB Development Board ‎(48,666 views)
  11. 16x8 LED Matrix Display ‎(43,962 views)
  12. C64 VICE Front-End ‎(36,611 views)
  13. USB Performance Monitor ‎(33,205 views)
  14. PC Case USB LCD ‎(30,049 views)
  15. Rotary Encoder Demonstration ‎(28,174 views)
  16. Commodore SID 6581 Datasheet ‎(26,967 views)
  17. Reverse engineering an MB Electronic Simon game ‎(24,029 views)
  18. Retro Computing ‎(22,929 views)
  19. LED Colour Organ ‎(22,797 views)
  20. Vetinari's Clock ‎(18,592 views)

more >>