Logic that depends on history

Sequential circuits are built from flip-flops connected with combinational logic, and their output depends on both current inputs and past state. This is what allows a system to "remember where it is" โ€” whether that's a counter tracking elapsed cycles, or a vending machine tracking how many coins you've inserted.

Formal definition: A sequential circuit's next state is a function of its current state AND current inputs: NextState = f(State, Inputs). This is the foundation of finite state machines.

Binary Counter โ€” Interactive Demo

A binary counter is a chain of flip-flops where each bit toggles based on the one before it. Click "Increment" to see a 4-bit counter count up in binary, wrapping back to 0000 after reaching 1111 (15).

๐Ÿ”ข 4-Bit Binary Counter

Decimal: 0

This is how a CPU's program counter works โ€” incrementing by one (or jumping) on every clock cycle to track which instruction comes next.

Finite State Machines

A Finite State Machine (FSM) is a circuit that exists in one of a finite number of states at any time, and moves between states based on inputs. There are two classic models:

Interactive: Traffic Light FSM

Click "Next" to advance this simple traffic light state machine through its cycle:

๐Ÿšฆ Traffic Light State Machine

GREEN
(go)
โ†’
YELLOW
(slow)
โ†’
RED
(stop)
โ†’

Currently: GREEN โ€” vehicles may proceed.

Timing Diagrams

A timing diagram shows how signals change over time, synchronized to the clock. Below is a simplified diagram showing a clock signal and a D flip-flop output that toggles every other clock cycle:

CLK Q edge edge edge edge

Notice Q only changes right at a rising clock edge โ€” never in between. This predictability is what lets engineers reason about circuits with millions of flip-flops.

Shift Registers

A shift register is a chain of flip-flops where data moves from one to the next on each clock pulse โ€” like a bucket brigade passing bits down the line. They're used for:

ApplicationHow it uses shift registers
Serial-to-parallel conversionBits arrive one at a time, shift register collects them into a byte
Parallel-to-serial conversionA byte is loaded, then shifted out one bit at a time (used in UART/SPI)
Delay linesEach stage delays the signal by one clock cycle
Pseudo-random number generationLinear feedback shift registers (LFSRs) generate pseudo-random sequences

From Here to a CPU

You now have every conceptual building block needed to understand a simple CPU:

  1. ALU โ€” combinational circuits (adders, comparators) perform arithmetic
  2. Registers โ€” flip-flops hold values between operations
  3. Program Counter โ€” a counter tracks the current instruction address
  4. Control Unit โ€” an FSM decodes instructions and sequences operations
  5. Clock โ€” synchronizes everything into discrete steps

Where to go next: If you want to build an actual CPU from these pieces, the "Nand to Tetris" project (linked in our Resources section) walks you through exactly that, gate by gate.