Circuit lab 05 · Intermediate · about 40 minutes
Digital logic lab
From single gates to circuits that add, remember and count. Each step builds on the one before: gates make adders, gates wired in a loop make memory, and memory plus a clock makes a counter. That is most of what a computer is.
1 · Logic gates
In digital circuits a wire is either 1 (high, near the supply voltage) or 0 (low, near 0 V). A gate looks at its inputs and sets its output by a fixed rule. Flip the inputs and watch the truth table.
Logic levels: a 74HC chip on 5 V reads below about 1.5 V as 0 and above about 3.5 V as 1. Between those, the result is not guaranteed, which is why digital inputs must never be left floating: use a pull-up or pull-down resistor (see Embedded). Inside, each gate is a handful of transistors used as switches, like the transistor switch.
2 · Everything from NAND
NAND is called a universal gate: with enough of them you can build any other gate, and so any digital circuit. Try each construction; its output always matches the real gate.
3 · Adding binary numbers
Adding two single bits gives a sum and a carry, exactly like adding digits by hand: 1 + 1 = 10 in binary (“0, carry 1”).
- The sum is XOR of the bits (1 when they differ).
- The carry is AND of the bits (1 when both are 1).
That pair of gates is a half adder. A full adder also takes the carry from the column to its right. Chain four and you can add two 4-bit numbers: the carry “ripples” from right to left.
A
B
Carries
Sum
4 · Memory: latches and flip-flops
SR latch
Two NOR gates, each feeding the other. Press Set and Q becomes 1; let go and it stays 1, because the loop holds it. Reset makes it 0. That loop is one bit of memory.
D flip-flop
Copies its D input to Q only at the instant the clock rises from 0 to 1, and ignores D the rest of the time. Every register in a processor is built from these.
5 · Counting
Four flip-flops, each wired to flip when the one before it falls from 1 to 0, count clock pulses in binary. Watch how each stage runs at half the speed of the one before: that is also how a quartz watch divides 32 768 Hz down to one tick per second.
In a real ripple counter each stage switches a few nanoseconds after the one before, so for a moment the outputs show wrong values. Faster “synchronous” counters clock every stage together. The 74HC393 is a real 4-bit ripple counter; the 74HC390 counts in tens.