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
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:
- Moore Machine โ output depends only on the current state
- Mealy Machine โ output depends on current state AND current input
Interactive: Traffic Light FSM
Click "Next" to advance this simple traffic light state machine through its cycle:
๐ฆ Traffic Light State Machine
(go)
(slow)
(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:
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:
| Application | How it uses shift registers |
|---|---|
| Serial-to-parallel conversion | Bits arrive one at a time, shift register collects them into a byte |
| Parallel-to-serial conversion | A byte is loaded, then shifted out one bit at a time (used in UART/SPI) |
| Delay lines | Each stage delays the signal by one clock cycle |
| Pseudo-random number generation | Linear 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:
- ALU โ combinational circuits (adders, comparators) perform arithmetic
- Registers โ flip-flops hold values between operations
- Program Counter โ a counter tracks the current instruction address
- Control Unit โ an FSM decodes instructions and sequences operations
- 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.