Sequential Circuits & Memory Elements

Latches, flip-flops, registers and counters; clocks and timing; and finite state machines — how hardware remembers.

Intermediate 3 min readLesson 2 of 15

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
00Q (hold)
101
010
11invalid

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.

t0t1t2t3t4t5clkDQ↑↑↑011001001100
Q changes only at rising edges (↑): it samples D at t2 (1) and t4 (0), ignoring D's changes in between.

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.

timertimertimerGREENYELLOWRED
TypeOutputs depend onNote
MooreState onlyOutputs change only at clock edges; simpler timing
MealyState and inputsOften 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

SRAMDRAM
Cell6 transistors (a latch)1 transistor + 1 capacitor
SpeedFast (around 1 ns)Slower (tens of ns)
Density / costLow density, expensiveHigh density, cheap
RefreshNot neededMust be refreshed every ~64 ms (capacitors leak)
Used forCPU caches, register filesMain memory (RAM)

That trade-off — small and fast vs large and cheap — is the reason for the memory hierarchy.

Key takeaways
  • 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.