Digital8 hours total3.5 h on the project

Sequential Logic and State Machines

Design clocked systems: flip-flops, registers, counters and finite state machines, with correct reset, no metastability hazards, and verified state coverage.

Learning material0/21
Project0/15
Competence checklist0/7

Two ways in. Work the material, or if you already know this, go straight to the project and prove it.

How this skill is structured

  1. 1. Concepts — the ideas stated plainly, with the equations worth memorising.
  2. 2. Worked example — one real problem solved end to end, numbers included.
  3. 3. Tool demonstration — do the thing in a real open-source tool.
  4. 4. Resources — the specific free readings and videos, and what part of each to use.
  5. 5. Project — built alone, producing something a reviewer can check.
  6. 6. Competence checklist — what you must be able to do. This is also the audit rubric.

1. Concepts

Read these first. Tick each one when you could explain it to someone else without notes.

0/8

2. Worked example

Designing a debounced button-press FSM the right way

ProblemA mechanical button feeds a 50 MHz synchronous system. Design an FSM that produces a single-cycle pulse per press, ignoring bounce up to 10 ms, and handles the fact that the button is asynchronous.

  1. 1
    Step 1 - synchronise. The button is asynchronous, so it must pass through a two-flip-flop synchroniser before touching any logic. btn_sync = second flip-flop output. This is non-negotiable and is where most beginner designs fail.
  2. 2
    Step 2 - size the debounce counter. 10 ms at 50 MHz is 500,000 clock cycles. That needs ceil(log2(500000)) = 19 bits.
  3. 3
    Step 3 - define states. IDLE (waiting for a press), COUNT_PRESS (input has gone active, waiting for stability), PRESSED (pulse emitted, waiting for release), COUNT_RELEASE (input has gone inactive, waiting for stability).
  4. 4
    Step 4 - transitions. IDLE: if btn_sync asserted, clear counter and go to COUNT_PRESS. COUNT_PRESS: increment counter; if btn_sync de-asserts, return to IDLE (it was a bounce); if counter reaches 500000, go to PRESSED. PRESSED: emit the pulse for one cycle, then wait for btn_sync to de-assert, then go to COUNT_RELEASE. COUNT_RELEASE: mirror of COUNT_PRESS.
  5. 5
    Step 5 - output style. The single-cycle pulse should be a Moore output asserted only in a dedicated one-cycle state, so it is glitch-free and exactly one cycle wide. A Mealy output here would be a combinational function of btn_sync and could glitch.
  6. 6
    Step 6 - encoding. Four states, so 2 bits binary or 4 bits one-hot. At 50 MHz with trivial next-state logic, binary is fine. Define the two unused binary codes to transition to IDLE, so a corrupted state recovers.
  7. 7
    Step 7 - reset. Asynchronous assert so the FSM is in IDLE the instant power comes up; synchronous de-assert via a reset synchroniser so all flip-flops leave reset on the same edge.
  8. 8
    Step 8 - timing check. The critical path is the 19-bit counter's comparator to the next-state logic to the state register's D input. At 50 MHz the budget is 20 ns. A 19-bit magnitude comparison against a constant is cheap (compare only the bits that are 1 in the constant), so this passes easily. If it did not, the fix would be to compare against a power of two and use the carry-out.
  9. 9
    Step 9 - verification plan. Test vectors must include: a clean press, a press with 20 bounce transitions, a press shorter than 10 ms (must be rejected), a press held for 10 seconds (must produce exactly one pulse), and a release with bounce.

AnswerTwo-flip-flop synchroniser, a 19-bit debounce counter, a four-state Moore FSM with a dedicated one-cycle pulse state, binary encoding with unused states routed to IDLE, and asynchronous-assert/synchronous-de-assert reset. The synchroniser and the Moore output style are the two decisions that separate a working design from an intermittent one.

3. Tool demonstration

Build the FSM, watch the state register on a waveform, and prove bounce rejection with automated test vectors.

0/9

Tool: Digital (hneemann) sequential simulation with a clock and measurement graph

4. Resources

Free and, wherever possible, openly licensed. The note tells you which part to actually use — do not read them cover to cover.

0/4

5. Project — build this on your own

About 3.5 hours. This is the artifact that proves the skill. Work it without a walkthrough.

0/15

Design and verify a synchronous controller with at least six states that interacts with the asynchronous outside world — for example a traffic light with a pedestrian request button, a vending machine coin controller, or a stepper motor sequencer with limit switches.

Deliverables

Acceptance criteria — how you know it is good enough

If you want to push further

  • Add a second clock domain and design a correct handshake (or a small asynchronous FIFO) to move data across it. Explain why a single synchroniser on a multi-bit bus is insufficient.
  • Compute the metastability MTBF for your synchroniser using the standard formula and typical flip-flop parameters, and state how many years it corresponds to.

6. Competence checklist

Tick these honestly. If you are auditing this skill, this is your rubric — you should be able to demonstrate every line from the project you just built.

0/7
Tick every line above first — 7 remaining.