3.5.3 · D3HDL & Digital Design Flow

Worked examples — Sequential logic and always blocks

2,703 words12 min readBack to topic

The scenario matrix

Think of every sequential-logic question as living in one of these boxes. If we work one example from each box, we've covered the whole space.

# Case-class What makes it distinct Covered by
A Pure capture (D→Q) one flop, no reset, <= Ex 1
B Blocking vs non-blocking order same code, two operators, different hardware Ex 2
C Async reset reset acts between edges Ex 3
D Sync reset reset waits for the edge Ex 4
E Enable / hold (degenerate: no change) edge arrives but value must not update Ex 5
F Counter with wrap (limiting value) max value overflows to zero Ex 6
G Combinational trap: inferred latch missing branch creates memory by accident Ex 7
H Real-world word problem traffic-light / debouncer style timing Ex 8
I Exam twist: read-then-write in same block <= self-reference confuses beginners Ex 9

The two axes underneath this table are: (1) does time matter? (async vs sync vs pure-comb) and (2) does update order matter? (= vs <=). Every row is one combination of those two questions.


Reading a timing diagram (build the picture first)

Before any example, here is the one picture everything below refers to. We draw the clock as a square wave, mark its rising edges (the jumps), and show that a flip-flop's output Q only steps at those rising edges.

Figure — Sequential logic and always blocks

Ex 1 — Case A: pure D→Q capture


Ex 2 — Case B: the operator changes the hardware


Ex 3 — Case C: asynchronous reset acting between edges


Ex 4 — Case D: synchronous reset waits for the edge


Ex 5 — Case E (degenerate): enable holds the value


Ex 6 — Case F (limiting value): counter that wraps


Ex 7 — Case G: the inferred-latch trap


Ex 8 — Case H: real-world word problem (pedestrian button)


Ex 9 — Case I (exam twist): self-referencing non-blocking


Coverage check

Every matrix cell A–I now has a worked example. Re-map yourself:

Recall Which example covered which cell?

A pure capture ::: Ex 1 B blocking vs non-blocking ::: Ex 2 C async reset ::: Ex 3 D sync reset ::: Ex 4 E enable/hold degenerate ::: Ex 5 F counter wrap (limiting) ::: Ex 6 G inferred latch trap ::: Ex 7 H real-world word problem ::: Ex 8 I exam twist self-reference ::: Ex 9


Active-recall