This page accumulates the show notes for each of the videos in the “Introduction to Digital Computer” series.
While putting together my video series on how digital computers work, I did a little basic research to verify my facts. And some of the pages I encountered are very interesting or very cool.
Part 1: Transistors
It’s worth noting there are many different types of transistors out there. The transistor I’m using in this series is a very common NPN transistor: specifically the 2N3904, which can be purchased (as of this writing) on Amazon for $5.90 for a set of 100.
The reason why I’m using this transistor is twofold. First, it’s a very common hobbyist transistor, whose characteristics are very well known. Second, it’s relatively inexpensive. One could easily follow along in the circuit diagrams to actually build the circuits I outline in the video. (In fact, I did, to make sure the circuits I was diagramming worked.) And this is important to me because later on I’d like to actually have circuit boards built which show each of the basic logic circuits in action–and even more complex circuits, such as a 1 bit adder.
Because I believe hands-on is extremely important. (Too often tutorials like this start at a very abstract level, like “this is a CMOS transistor, and an AND gate is made by blah blah blah”–all theoretical stuff. But if you start with NPN transistors, you can get a breadboard, some wires, some resistors–and actually build a working AND gate yourself.)
Sparkfun has a fantastic tutorial on transistors, which cover the basic NPN transistor, complete with equations. But one of the best explanations of how a transistor works can be found here: What is the difference between a transistor and a resistor? Frankly, this answer to the question is eye-opening, and at some point I may animate the steps shown, if only for my own edification. (With the author’s permission, of course.)
As to making gates, while the video itself should make it clear how gates can be made from NPN transistors, there is also an Indestructables tutorial on the subject. Of course when I built the circuits I made sure I had a current limiter resistor (330Ω) on my LEDs because I was using a 3V source and LEDs rated at 1.5V.
Further, I have a Quick Video which shows each of our five circuits constructed on a breadboard, with show notes giving complete circuit diagrams (including resistor values), as well as a list of parts and where they can be ordered from.
Ohm’s law.
Before I go further, it’s useful to dig a little deeper into Ohm’s law. From the fantastic description of the difference between a transistor and a resistor we have a brief discussion of ohm’s law. In the animation starting around 3:50 in the updated video, I show a graph with a variable resistor and a fixed resistor at top.
We can describe the actual relationship between the resistor at the bottom and the voltage with the following equations:
Now when we have two resistors (call the top one R1 and the bottom R2), since they’re in sequence resistances add–and we get:
Voltage through the system is constant–we only have one battery–and the current (I) is constant (think of it like the flow of water: the amount of water flowing past R1 and past R2 must be the same since the amount of water coming out the bottom is the same, right?), so that means the voltage drop across R1 and R2 must add up to the total voltage V.
That is we should see:
where
We can now solve for Vout, which is the same as V2, if we assume the values of R1 and V are known and constant. By observation our voltage V2 is
Rearranging the relationship between V, I and resistors R1 and R2 above, and substituting for I in the equation above we get:
As the resistance R2 goes to zero, the voltage V2 goes to zero:
And as R2 goes to infinity, the voltage V2 goes to V–which makes sense, since “resistance = infinity” also means “disconnecting the resistor”:
These equations (with a scaling equation to scale the resistance on the graph) are the equations used to calculate Vout on the animation above.
Encapsulation
I also want to touch a moment on encapsulation.
I think the importance of encapsulation in computer science and computer engineering is one of the most underrated concepts ever. Encapsulation–the idea that you build complex things by building them out of simple parts, each of which is made up of it’s own parts, and so on–is a very under-rated concept and an under-rated idea. Too often we see a lack of the ability of a software developer to abstract concepts through encapsulation–and it shows up in spaghetti code, confused engineers and over-constructed stuff.
It’s like if an architect was forced to build a skyscraper first by considering each and every nail they hammer into a board. No wonder if builders built buildings like programmers built programs, the first woodpecker to come along would destroy civilization.
We will be hitting the concept of encapsulation–including the idea that once you’ve built the black box, it doesn’t matter what is inside the black box so long as it works the same. This becomes important when we talk about exclusive-OR gates, adders, latches, and other components.
And being able to visualize what you are working on at a wide variety of levels of encapsulation–for a time consider an ALU, then visualize the gates inside the ALU, then visualize the ALU’s place inside a processor, for example–is a highly important skill to develop. It allows us to visualize things that may consist of millions of transistors without getting confused or going mad.
Part 2: Basic Math
While developing the video for this I discovered a mistake in the first video which required re-editing and uploading a new version of the video. All that is outlined in the video above.
Part 3: Flip Flops
One interesting thing I encountered while developing this series–and remember, it’s important to me that everything here can be built using NPN transistors and resistors and other discrete components–are the number of web sites which discuss flip flops which get things wrong.
I don’t mean “technically wrong” in the sense that their descriptions are bad or inaccurate. They’re not drawing a cat and calling it a data latch, for example.
But a number of them are drawing circuits using transistors that simply cannot work. For example, to get a J/K flip flop to work, you cannot use a simple set/reset flip flop and a handful of AND gates. The circuit below won’t work:
One site authoritatively describes the problem as a problem with “race” or a “race around” condition, as if a bunch of ones and zeros run around a track.
I see two problems with this. First, even if what was happening was a sort of “race around” condition, that means for the circuit above, setting both J and K then toggling C does not “toggle” our circuit, and you can’t cure that problem by using a “short enough” pulse on C. Meaning it’s not a true J/K flip flop.
Second, as I noted in the video, this is a case where encapsulation lies to you. That is, the authors who suggest there is some sort of race condition so you must flip C on ‘for as short a time as possible’ (How short? How do we determine this?) they’re still thinking of this circuit as a pure digital circuit, rather than as the collection of transistors this actually is.
And I’m sure if you were to build this circuit what you don’t get are a bunch of 1’s and 0’s outputted to Q and not Q. What you get is an intermediate voltage (as the transistors do what we showed when we loop one NOT gate to itself, or when both the set and reset lines of an SR flip flop are set), and then releasing the clock allows the circuit to settle to some random value depending on the imperfections in the silicon.
This is why, while encapsulation can be very important, you have to know when encapsulation lies to you.
And if you see something that you think is some sort of “race condition” in logic circuits, chances are, it’s not a bunch of 1’s and 0’s vibrating very quickly, chasing their tails. It’s a case where you need to stop thinking of your circuits as digital circuits and think of them instead as a bunch of transistors sitting at some intermediate value between 0 and 5 volts.
Now as you can see, I’ve taken to simulating everything using iCurcit to verify my thinking. The underlying simulation software this uses is MacSpice, and while Spice in general has its limitations, generally does a fairly good job simulating circuits.