Sequential Circuits & Memory Elements
Latches, flip-flops, registers and counters; clocks and timing; and finite state machines — how hardware remembers.
A combinational circuit forgets everything as soon as its inputs change. To build a computer you also need state: registers that hold values, a program counter, memory. Sequential circuits have outputs that depend on their inputs and their stored state.
Feedback creates memory
Wire two NOR gates so each one's output feeds the other's input and you get an SR latch: a circuit with two stable states. It holds one bit for as long as it has power.
| S (set) | R (reset) | Q next |
|---|---|---|
| 0 | 0 | Q (hold) |
| 1 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 1 | invalid |
A D latch removes the invalid case: when the enable signal is high, Q follows the data input D; when it's low, Q holds its value.
Flip-flops and the clock
Latches are transparent while enabled, so a value can race through several of them in one cycle. A D flip-flop captures D only at the edge of the clock (usually the rising edge) and holds it for the whole cycle.
Every register in a CPU is made of flip-flops sharing a clock. On each tick, all of them capture their inputs at the same moment. Between ticks, the combinational logic computes the next values. That gives the whole chip a single, predictable rhythm.
Registers, shift registers and counters
- Register — n flip-flops sharing a clock, holding an n-bit word. A register file is an array of registers with read and write ports (typically 2 reads and 1 write per cycle).
- Shift register — each flip-flop feeds the next; used for serial ↔ parallel conversion (UART, SPI).
- Counter — a register plus an incrementer. The program counter is a counter that can also be loaded with a jump target.
Finite state machines
A finite state machine (FSM) is a state register plus combinational logic that computes the next state (and the outputs) from the current state and inputs. Traffic lights, vending machines, network protocol handlers and a CPU's control unit are all FSMs.
| Type | Outputs depend on | Note |
|---|---|---|
| Moore | State only | Outputs change only at clock edges; simpler timing |
| Mealy | State and inputs | Often fewer states; outputs react within the cycle |
The same idea shows up in software: parsers, regex engines and protocol implementations are FSMs too. See Automata.
Memory cells: SRAM and DRAM
| SRAM | DRAM | |
|---|---|---|
| Cell | 6 transistors (a latch) | 1 transistor + 1 capacitor |
| Speed | Fast (around 1 ns) | Slower (tens of ns) |
| Density / cost | Low density, expensive | High density, cheap |
| Refresh | Not needed | Must be refreshed every ~64 ms (capacitors leak) |
| Used for | CPU caches, register files | Main memory (RAM) |
That trade-off — small and fast vs large and cheap — is the reason for the memory hierarchy.
- Sequential circuits have state; feedback loops (latches) store bits.
- Flip-flops capture input on a clock edge; registers are groups of flip-flops.
- Clock period ≥ the critical path delay plus setup time.
- An FSM is a state register plus next-state logic; a CPU's control unit is one.
- SRAM (6T, fast) for caches; DRAM (1T1C, dense, needs refresh) for main memory.