06 Synchronous Sequential Circuits

This is the core chapter on finite state machine (FSM) design. The systematic design procedure is presented: from state diagram to state table, state assignment, choice of flip-flops, derivation of next-state and output logic, to timing verification. Both Moore machines (output depends only on state) and Mealy machines (output depends on state and current inputs) are covered with clear examples. State assignment strategies include binary encoding and one-hot encoding. The chapter includes a thorough treatment of state minimization using the partitioning procedure. A serial adder is designed in both Moore and Mealy styles to illustrate the tradeoffs. Arbiter circuits, counter design using the sequential-circuit approach, analysis of existing sequential circuits, and ASM (Algorithmic State Machine) charts are also covered. Verilog code examples use parameter, case, and multi-block FSM coding styles.

Moore vs Mealy FSMs State Diagrams / Tables State Assignment One-Hot Encoding State Minimization Serial Adder ASM Charts Arbiter Circuits Verilog FSM Styles
Moore vs Mealy: how the two state diagrams differ visually

Both styles describe the same kind of FSM, but the output is drawn in different places. This shows up in flow tables (ch 9) the same way it shows up in synchronous state diagrams (ch 6).

Side-by-side example — both detect the input sequence "11" and assert $z=1$. Same behavior, different drawing convention:

Mooreoutput written inside the stateAz=0Bz=0Cz=1w=0w=1w=1w=0w=0w=1Mealyoutput written on the transition (input/output)ABw=0/0w=1/0w=1/1w=0/0

Reading the labels:

stylestate circlearrow labeloutput rule
Moorename + output value (e.g. A/0, C/1)just the input value (w=1)$z = f(\text{state})$ — registered, stable for full cycle
Mealyjust the state name (no output)input/output (w=1/1)$z = f(\text{state}, \text{input})$ — combinational, may change mid-cycle

Same job, different state count. The Moore version above needs 3 states (A, B, C — with C dedicated to "saw 11" so $z=1$ can live in a state). The Mealy version needs only 2 states (A, B) because the "$z=1$" event is fired on the B→B transition itself, no extra state required.

Quick visual cues to tell them apart at a glance:

  • If you see a slash inside a circle (A/0) and arrow labels are just inputs → Moore.
  • If you see a slash on an arrow (w=1/1) and circles only contain state names → Mealy.
  • Sometimes a Moore "accepting" state is drawn with a double circle (concentric rings) — Mealy has no such convention.
  • In synchronous state tables (this chapter): Moore lists outputs as a separate column keyed on present state; Mealy lists outputs per (state, input) cell, alongside the next-state entry.
6.1MediumTier 1?R
Derive the state diagram for an FSM with input w and output z that outputs z=1 whenever the input sequence 101 is detected. Overlapping sequences should be detected.
6.2MediumTier 1?R
For the FSM in exercise 6.1, derive the state table, assign binary state codes, and determine the next-state and output equations using D flip-flops.
Context: the FSM from exercise 6.1 — "101" sequence detector with overlap

Recap of exercise 6.1. The FSM detects the input sequence 101 on input $w$ and asserts $z=1$ when the sequence completes. Overlapping is allowed — e.g., on $w = 1,0,1,0,1$ the detector should fire twice: at position 3 (first "101") and at position 5 (second "101", reusing the "1" at position 3).

Moore state diagram (4 states):

  • A — initial / no useful prefix. $w=0 \to A$, $w=1 \to B$. $z=0$.
  • B — last input was 1. $w=0 \to C$, $w=1 \to B$. $z=0$.
  • C — last two inputs were "10". $w=0 \to A$, $w=1 \to D$ (sequence complete). $z=0$.
  • D — sequence "101" just detected. $w=0 \to C$ (the new "0" plus the trailing "1" from D forms "10"), $w=1 \to B$ (overlap — the trailing "1" of D plus the new "1" makes B). $z=1$.

Overlapping comes from D\'s transitions: the "1" that completed the sequence is reused as the prefix of the next attempt.

State table with 2-bit Gray-style binary assignment $A=00, B=01, C=10, D=11$:

Present $y_2 y_1$$w=0$ next $Y_2 Y_1$$w=1$ next $Y_2 Y_1$$z$
A=0000 (A)01 (B)0
B=0110 (C)01 (B)0
C=1000 (A)11 (D)0
D=1110 (C)01 (B)1

Next-state equations (D flip-flops):

$Y_1$ K-map by inspection — $Y_1 = 1$ only in cells where $w=1$ (regardless of present state):

$$Y_1 = w$$

$Y_2$ K-map — $Y_2 = 1$ in cells: $(w=0, y_2 y_1 = 01)$, $(w=0, y_2 y_1 = 11)$, $(w=1, y_2 y_1 = 10)$. Group: the first two cells share $\overline{w}\,y_1$; the third is $w\,y_2\,\overline{y_1}$.

$$Y_2 = \overline{w}\,y_1 + w\,y_2\,\overline{y_1}$$

Output: $z = 1$ only in state D = 11.

$$z = y_2 \cdot y_1$$

Implementation: 2 D flip-flops + a few gates. Total cost: 1 buffer ($Y_1 = w$ — no logic), 1 AND2 + 1 AND3 + 1 OR2 ($Y_2$), 1 AND2 ($z$) ≈ 5 gates / 9 inputs. Modern synthesis tools would derive this exactly.

Verification. Trace input $w = 1,0,1,0,1$ starting in A:

cyclestate in$w$state out$z$
0A1B0
1B0C0
2C1D0 → 1
3D0C1 → 0
4C1D0 → 1

Two "101" detections at cycles 2 and 4 — overlap correctly detected.

6.3MediumTier 1?R
Derive the state diagram for a Moore-type FSM that outputs z=1 when it has received at least three consecutive 1s on input w.
6.4MediumTier 1?R
Repeat exercise 6.3 as a Mealy-type FSM. Compare the number of states needed.
Context: the FSM from exercise 6.3 — "three consecutive 1s" detector

Recap of exercise 6.3 (Moore version). The FSM outputs $z=1$ once it has received at least three consecutive 1s on input $w$. As soon as a 0 arrives, the run breaks and the count resets.

Moore state diagram — 4 states:

  • A — no 1s pending. $w=0 \to A$, $w=1 \to B$. $z = 0$.
  • B — saw one 1. $w=0 \to A$, $w=1 \to C$. $z = 0$.
  • C — saw two consecutive 1s. $w=0 \to A$, $w=1 \to D$. $z = 0$.
  • D — saw three or more consecutive 1s. $w=0 \to A$, $w=1 \to D$ (stay). $z = 1$.

The Moore output is a function of state alone, so distinguishing "saw 3" from "saw ≥3" requires a separate "detection" state D where $z=1$ is registered.

Mealy version — 3 states:

  • A — no 1s. $w=0/0 \to A$, $w=1/0 \to B$.
  • B — saw one 1. $w=0/0 \to A$, $w=1/0 \to C$.
  • C — saw two consecutive 1s. $w=0/0 \to A$, $w=1/\mathbf{1} \to C$ (output 1 on the third 1; stay in C as long as 1s continue, firing $z=1$ on every additional 1).

Notation $w/z$ means input/output on the transition. The Mealy form fires $z=1$ on the transition from C to itself when $w=1$, so we don\'t need a separate "saw three" state — the third 1\'s effect is registered as the output of the very transition that observes it.

Mealy state diagram (return arrows from B and C to A are routed at distinct depths so they never overlap):

ABC0/01/11/01/00/00/0

Verilog (Mealy, 3 states) — combinational output uses both state and input $w$ on the C→C transition:

module mealy_three_ones (
  input  clock, resetn, w,
  output reg z
);
  reg [1:0] y;
  parameter A = 2'b00, B = 2'b01, C = 2'b10;

  // single always block: state register + registered Mealy output
  always @(posedge clock or negedge resetn) begin
    if (!resetn) begin
      y <= A;
      z <= 1'b0;
    end else begin
      case (y)
        A:       begin y <= (w ? B : A); z <= 1'b0; end
        B:       begin y <= (w ? C : A); z <= 1'b0; end
        C:       begin y <= (w ? C : A); z <= w;    end  // z=1 on C&&w=1
        default: begin y <= A;         z <= 1'b0; end
      endcase
    end
  end
endmodule

Comparison:

PropertyMoore (ex 6.3)Mealy (ex 6.4)
States4  (A, B, C, D)3  (A, B, C)
Flip-flops22
Output$z = f(\text{state})$$z = f(\text{state}, w)$
Output timingsynchronous (clock edge)combinational (input-driven)

Key takeaways:

  • Mealy reduces state count by folding "I just detected the event" into the transition output rather than into a dedicated state. Saves exactly one state in this case (4 → 3).
  • Flip-flop count doesn\'t always go down with state count — both versions need 2 flip-flops because $\lceil \log_2 3 \rceil = \lceil \log_2 4 \rceil = 2$.
  • Mealy output $z$ can change in the middle of a clock cycle when $w$ changes — Moore $z$ only changes at clock edges. If glitch-free output is required, Moore is safer; if minimum latency from input to output matters, Mealy wins.
6.5MediumTier 1?R
Explain the difference between Moore and Mealy FSMs. Give one advantage of each type.
6.6MediumTier 1?R
What is one-hot state encoding? For an FSM with 5 states, how many flip-flops are needed for binary encoding versus one-hot? Discuss the tradeoffs.
6.7MediumTier 1?R
Write Verilog code for the Moore-type sequence detector in exercise 6.1 using a case statement and parameter declarations for the states.
6.8MediumTier 1?R
Write Verilog code for a Mealy FSM that outputs 1 whenever the last two inputs were 01. Use a three-block coding style (state register, next-state logic, output logic).
Context: the three-block FSM coding style

The three-block style separates an FSM into three distinct always blocks, each with one focused responsibility. It cleanly mirrors the FSM's conceptual decomposition into a state register, a next-state function, and an output function:

Block 2next-state logicalways @(*)Block 1state registeralways @(posedge clk)Block 3output logicalways @(*) or assignYyy feeds back to next-state logic (and to output logic)wz

The three blocks at a glance:

blocksensitivityassignmentrole
1. State register@(posedge clk)non-blocking <=commits next-state to FFs on every clock edge
2. Next-state logic@(*)blocking =combinational: $Y = \delta(y, w)$
3. Output logic@(*) or assignblocking = / assigncombinational: Moore $z = f(y)$ or Mealy $z = f(y, w)$

Skeleton for the "last two inputs = 01" Mealy detector (2 states):

module detect_01_mealy (
  input  clk, resetn, w,
  output reg z
);
  reg y, Y;
  parameter A = 1'b0,   // have not just seen a 0
            B = 1'b1;   // last input was 0

  // ── Block 1: state register ─────────────────────────────
  always @(posedge clk or negedge resetn) begin
    if (!resetn) y <= A;
    else         y <= Y;
  end

  // ── Block 2: next-state logic (combinational) ───────────
  always @(*) begin
    case (y)
      A: Y = (w == 1'b0) ? B : A;   // saw a 0 → go to B
      B: Y = (w == 1'b0) ? B : A;   // saw 0 again → stay; saw 1 → done, return to A
      default: Y = A;
    endcase
  end

  // ── Block 3: output logic (Mealy — uses state AND input) ──
  always @(*) z = (y == B) && (w == 1'b1);
endmodule

Why split it up:

  • Each block is locally readable. Block 1 is boilerplate; Block 2 is the state-transition table; Block 3 holds the output rule.
  • Blocking vs non-blocking is unambiguous. Block 1 always uses <=; Blocks 2 & 3 always use =. Mixing them in a single block is the most common synthesis-vs-simulation mismatch.
  • Easy Moore ↔ Mealy switch. Only Block 3 changes; the register and transitions stay put.
  • Synthesis-friendly. Tools immediately recognize the pattern and infer flip-flops + combinational cones cleanly.

Variants: some authors merge Blocks 2 & 3 into one combinational always @(*) (a "two-block" style). Others reduce Block 3 to a single assign when the output is a one-state Moore decode. The invariant: state register stays sequential and isolated; everything else is combinational and explicitly labeled.

6.9MediumTier 1?R
Given the state-assigned table: Present State y₂y₁, Next State (w=0 / w=1), Output z: {00→10/11, 0}, {01→01/00, 0}, {10→11/00, 0}, {11→10/01, 1}. Derive the next-state and output equations using D flip-flops.
What is this problem asking?

You are given a state-assigned table — a state table where each abstract state has already been replaced by a concrete bit pattern. The job is to convert that abstract description into three Boolean expressions that you could wire up with logic gates and flip-flops.

How to read the table:

  • $y_2 y_1$ = the current values of two state flip-flops (the FSM has 4 states, so $\lceil\log_2 4\rceil = 2$ flip-flops).
  • Next state ($Y_2 Y_1$) = the bit pattern that should be loaded into the flip-flops on the next clock edge, listed for each input condition $w=0$ and $w=1$.
  • $z$ = the output, here Moore-style — depends only on present state, not on $w$.

Notation like "$00 \to 10/11$" reads: when present state is 00, next state is 10 if $w=0$, or 11 if $w=1$.

Why "using D flip-flops" matters: a D flip-flop has the property $Q^+ = D$ — whatever you put on the D input becomes the output after the next clock edge. So if you want next-state bit $i$ to equal $Y_i$, you simply connect the combinational signal $Y_i$ to the D input of flip-flop $i$. No conversion through excitation tables is needed (unlike JK or T flip-flops, which require an extra translation step).

What you must produce — three Boolean expressions:

  1. $Y_2 = D_2 = f(w, y_2, y_1)$ — the combinational logic feeding flip-flop 2.
  2. $Y_1 = D_1 = f(w, y_2, y_1)$ — likewise for flip-flop 1.
  3. $z = f(y_2, y_1)$ — the output decode (no $w$ since this is Moore).

Recommended procedure:

  1. Expand the 4-row table into an 8-row truth table indexed by $(w, y_2, y_1)$.
  2. Build a 3-variable K-map for each output column $Y_2$, $Y_1$, $z$.
  3. Read off minimum SOP (or POS) from each K-map.
  4. Sketch the circuit: two D flip-flops, with combinational gates implementing each $Y_i$ feeding into the corresponding $D_i$, and a small output decoder for $z$.

Sanity-check at the end: plug each row of the original table into your equations — every row's $Y_2 Y_1$ and $z$ should match. If they all match, the equations are correct (whether or not they're minimum). Then verify your K-map groupings are the largest possible to confirm minimality.

6.10MediumTier 1?R
Apply the state minimization partitioning procedure to reduce the following state table (states A–F) to a minimal form. Provide the original and reduced tables.
6.11MediumTier 1?R
Draw an ASM chart for a circuit that controls a vending machine: accepts nickels and dimes, dispenses a product when 15 cents or more is collected, and returns change if overpaid.
6.12MediumTier 1?R
Write Verilog code for a traffic light controller FSM with states: Green (30s), Yellow (5s), Red (30s). Use a counter for timing and an FSM for state control.
6.13HardTier 1E?R
Design a Moore-type FSM that swaps the contents of two registers $R_1$ and $R_2$ via a temporary register $R_3$, in response to a one-cycle pulse on input $w$. The FSM must generate the control signals $R1_{out}, R1_{in}, R2_{out}, R2_{in}, R3_{out}, R3_{in},$ and Done in the proper sequence. Derive the state diagram, state table, and a state-assigned implementation.
6.14MediumTier 1E?R
For the four-state register-swap FSM of Example 6.1, try the alternative state assignment in which states $C$ and $D$ are swapped. Derive the next-state and output expressions and compare the resulting cost to the straightforward assignment.
Context: Example 6.1 — 4-state register-swap FSM

The swap operation: swap contents of registers R1 and R2 using R3 as temp storage. Three transfers in sequence: R3 ← R2, then R2 ← R1, then R1 ← R3.

FSM: Moore-type, 4 states, started by a one-cycle pulse on input w:

  • A — idle, all outputs 0; stays in A while w=0, transitions to B when w=1
  • B — assert R2out=1, R3in=1 (so R3 latches R2 on next edge); always advances to C
  • C — assert R1out=1, R2in=1 (R2 latches R1); always advances to D
  • D — assert R3out=1, R1in=1, Done=1 (R1 latches old R2); always returns to A

State diagram:

A idle B R2out=1 R3in=1 C R1out=1 R2in=1 D R3out=1, R1in=1 Done=1 w=0 w=1 w=0/1 w=0/1 w=0/1 Reset

Straightforward state assignment (book convention): $A=00$, $B=01$, $C=10$, $D=11$ on $(y_2, y_1)$. With D flip-flops, the textbook derives:

$$Y_1 = w\,\overline{y_1}\,\overline{y_2} + \overline{y_1}\,y_2 \qquad Y_2 = y_1\,\overline{y_2} + \overline{y_1}\,y_2$$

What problem 6.14 asks: redo the next-state and output expressions with C and D swapped in the assignment ($A=00$, $B=01$, $C=11$, $D=10$). Compare the gate count to the original assignment — different state assignments produce algebraically different equations, often with different costs. The textbook lesson: state assignment is a non-trivial optimization knob.

— example 6.1
6.15MediumTier 1E?R
Apply one-hot state encoding to the four-state register-swap FSM. Use four flip-flops $y_1\ldots y_4$ and derive the next-state expressions directly by inspection of the state diagram.
Context: what is one-hot state encoding?

One-hot encoding = each state gets its own dedicated flip-flop, and exactly one is 1 ("hot") at any moment.

Comparison for a 4-state FSM (A, B, C, D):

EncodingABCD# of flip-flops
Binary00011011$\lceil\log_2 4\rceil = 2$
One-hot0001001001001000$N = 4$

Trade-off:

BinaryOne-hot
Flip-flops$\lceil\log_2 N\rceil$$N$
Next-state logicdecoded from binary stateeach transition is one product term
State-output decodeequality check (e.g. y2 && y1)a single wire — assign R1out = y3;
Speedslower (deeper logic)faster (one AND/OR layer)
FF costminimumlinear in $N$

Applied to the swap FSM ($y_1{=}A, y_2{=}B, y_3{=}C, y_4{=}D$):

Y1 = (y1 & ~w) | y4    // stay in A while w=0; come back from D
Y2 = y1 & w            // A→B when w=1
Y3 = y2                // B→C  (unconditional)
Y4 = y3                // C→D  (unconditional)
R2out = R3in = y2      // outputs come "for free"
R1out = R2in = y3
R3out = R1in = Done = y4

Each next-state expression is one tiny product term — that's the win. The cost is using 4 flip-flops instead of 2.

When to use which: Binary when area / FF count is the bottleneck. One-hot when you want simpler logic, faster combinational paths, and "free" state-output decoding — the standard choice on FPGAs where flip-flops are plentiful but routing/depth is the limit.

6.16HardTier 1E?R
Redesign the register-swap controller of Example 6.1 as a Mealy-type FSM. Show that only three states are needed and that the swap completes in three clock cycles instead of four. Derive a state diagram and discuss the timing of the output signals.— example 6.1
6.17MediumTier 1E?R
Write Verilog code for the four-state register-swap FSM of Example 6.1 using the two-always-block style: one combinational always for the next-state logic and one sequential always for the state register, with the outputs derived as assign expressions of the present state.— example 6.1
6.18MediumTier 1E?R
Apply the partitioning state-minimization procedure to a 7-state Moore FSM whose state table is given (Figure 6.51). Show each successive partition $P_1, P_2, \ldots$ and reduce the FSM to a 4-state equivalent.
Context: Figure 6.51 — 7-state Moore FSM (Example 6.6)

Figure 6.51 — original state table (7 states, Moore output $z$ depends only on present state):

Present$w=0$$w=1$$z$
ABC1
BDF1
CFE0
DBG1
EFC0
FED0
GFG0

Partitioning procedure (each $P_k$ groups states whose $k$-step successors stay in the same block):

  • $P_1 = (ABCDEFG)$ — start with everything in one block.
  • $P_2 = (ABD)(CEFG)$ — split by output: $z=1$ in $\{A,B,D\}$, $z=0$ in $\{C,E,F,G\}$.
  • $P_3 = (ABD)(CEG)(F)$ — within $(CEFG)$: 1-successors are $(E,C,D,G)$. $D$ is in a different block (it's in $\{A,B,D\}$), so $F$ (whose 1-successor is $D$) splits off.
  • $P_4 = (AD)(B)(CEG)(F)$ — within $(ABD)$: 1-successors are $(C,F,G)$. $F$ is in its own block, so $B$ (whose 1-successor is $F$) splits off.
  • $P_5 = P_4$ — no further splits, partitioning is done.

Equivalence classes: $\{A,D\}, \{B\}, \{C,E,G\}, \{F\}$ — four classes, so the minimized FSM has 4 states. Rename $\{A,D\} \to A$ and $\{C,E,G\} \to C$ to obtain Figure 6.52:

Present$w=0$$w=1$$z$
ABC1
BAF1
CFC0
FCA0

Implementation savings: $\lceil\log_2 7\rceil = 3$ flip-flops shrink to $\lceil\log_2 4\rceil = 2$. The merged states have indistinguishable behavior — any input sequence produces the same output sequence whether you start in $A$ or $D$, or in any of $C, E, G$.

— example 6.6
6.19HardTier 1E?R
Design a candy-vending machine controller that accepts nickels and dimes, dispenses candy when 15 cents has been deposited, and credits a buyer with 5 cents if 20 cents is deposited (no change is given). Derive an initial state diagram and use the partitioning procedure to obtain a minimum-state Moore FSM.
說明:什麼是分割程序 (partitioning procedure)?

分割程序是一種系統化方法,用來找出等價狀態——也就是對所有可能的未來輸入序列都表現相同的狀態,並將它們合併。兩個狀態等價的條件是:(1) 它們有相同的輸出,且 (2) 對每一種輸入,它們的下個狀態也彼此等價。此程序逐步精煉分割,直到達到不動點 (fixed point)。

演算法:

  1. $P_1$:把所有狀態放進同一個區塊 (block)。
  2. $P_2$:依照輸出把狀態分組。輸出 $z$ 不同的狀態不可能等價。
  3. $P_{k+1}$:對 $P_k$ 中的每個區塊,檢查所有輸入下的下個狀態。若同一區塊內兩個狀態的下個狀態落在 $P_k$ 的不同區塊,則它們等價,必須再拆成更小的子區塊。
  4. 停止條件:當 $P_{k+1} = P_k$(不再有新的分割)時停止。最終分割中的每個區塊就是一組等價類別——把同一區塊的狀態合併為單一狀態即可。

為什麼有效(非正式證明):若兩個狀態 $X$ 和 $Y$ 等價,必定存在某個輸入序列能區分它們——也就是經過若干步後抵達輸出不同的狀態。分割程序在第 $k$ 步追蹤的是:「只看前 $k$ 個輸入時,哪些狀態仍無法被區分」。當不再有新的區別出現時,精煉就停止;此時的分割恰好等於行為等價類。

小範例:假設:

狀態$w=0$$w=1$$z$
AAB0
BAC0
CAC1
  • $P_1 = (ABC)$
  • $P_2 = (AB)(C)$——依輸出分割(C 的 $z$ 不同)。
  • $P_3$:在 $(AB)$ 中,$w=1$ 的後繼狀態為 $(B,C)$,分別落在 $P_2$ 的不同區塊——所以 $A$ 與 $B$ 必須分開。$P_3 = (A)(B)(C)$。
  • $P_4 = P_3$——完成。三個區塊各自獨立 → 無法再合併;此 FSM 本身已經最小化。

為什麼要做?每減少一個狀態通常能省下一個或多個正反器(因為 FF 數量為 $\lceil\log_2 N ceil$),而且推導出來的下一狀態方程式與輸出方程式會有更少的最小項——電路更小、更快。對於手工設計的 FSM 來說,這個程序也能找出設計者誤以為不同、但其實重複的多餘狀態。

套用至問題 6.19:先畫出販賣機 FSM 的初始狀態圖(包含 "0¢", "5¢", "10¢", "15¢", "20¢",若允許兩個一角硬幣連續投入則還有 "25¢"),再以此程序合併行為相同的狀態(例如「20¢——找零 5¢」狀態,若機器在下一輪投幣時會重置找零紀錄,可能等價於「5¢」狀態)。

6.20MediumTier 1E?R
For an incompletely specified 7-state Mealy FSM with four unspecified entries, apply the partitioning procedure twice: first assuming both unspecified outputs are 0 and then assuming both are 1. Compare the resulting state counts.
6.21MediumTier 1E?R
Analyze a synchronous sequential circuit built from two D flip-flops with $Y_1 = w\overline{y_1}+wy_2$, $Y_2 = w\overline{y_1}+\overline{w}y_2$, and output $z=y_1 y_2$. Derive the state-assigned table and show the FSM detects three consecutive 1s on input $w$.
6.22MediumTier 1E?R
Analyze a synchronous sequential circuit built from two JK flip-flops with $J_1=w$, $K_1=\overline{w}+y_2$, $J_2=wy_1$, $K_2=\overline{w}$ and output $z=y_1 y_2$. Derive the excitation and state-assigned tables and identify the FSM behavior.
6.23MediumTier 1E?R
Analyze a synchronous circuit using a mixture of one D and one T flip-flop with $D_1=w(y_1+y_2)$, $T_2=\overline{w}y_2+wy_1\overline{y_2}$, and $z=y_1 y_2$. Derive the excitation table and show that this circuit implements the same FSM as those in Examples 6.9 and 6.10.— example 6.9
6.24HardTier 1E?R
Design a Moore-type sequence detector with input $w$ and output $z$ that asserts $z=1$ when the previous two values of $w$ were both 00 or both 11. Derive the state diagram, state table, and a state-assigned implementation.
6.25HardTier 1E?R
Implement the sequence detector of Example 6.12 as the parallel combination of two simpler FSMs: one that detects two consecutive 1s and one that detects two consecutive 0s. Combine the outputs with an OR gate.
Context: Example 6.12 — 5-state "00 or 11" sequence detector

Specification: output $z=1$ whenever the previous two values of input $w$ were both 0 or both 1; otherwise $z=0$.

FSM: Moore-type, 5 states (A reset, B/D = "saw a 0/1", C/E = "saw 00/11"):

StateMeaning$z$Next on $w$=0Next on $w$=1
Aafter reset0BD
Blast input was 00CD
Clast two were 001CD
Dlast input was 10BE
Elast two were 111BE

State diagram (output is the digit after the slash):

A/0 reset B/0 saw "0" C/1 saw "00" D/0 saw "1" E/1 saw "11" Reset w=0 w=1 w=0 w=1 w=0 w=1 w=0 w=1 w=1 w=0

Why exactly 5 states? The machine must remember three things: just-reset, just-saw-0, just-saw-1, plus the "00" / "11" run-detection states. Tracking only "last input" (3 states: A, B, D) isn't enough — you need to distinguish "first 0 ever" (B) from "second 0 in a row" (C) to decide whether $z$ goes high.

What problem 6.25 asks: instead of the single 5-state machine, build two parallel FSMs — one detects "two consecutive 0s" (3 states), the other detects "two consecutive 1s" (3 states). OR their outputs to get the combined $z$. The lesson: parallel decomposition often produces simpler FSMs than a single monolithic one (6 flip-flops total split between two machines vs. 3 flip-flops for the 5-state version, but with simpler next-state logic per machine).

What event actually triggers a state transition?

The arrows labeled w=0 / w=1 in any state diagram are conditions, not events. The actual event that changes the state in a synchronous FSM is the rising edge of the clock.

What happens during one clock cycle:

  • Between edges: the combinational next-state logic continuously evaluates $Q' = \delta(Q, w)$ — but the state register holds its current value $Q$. The arrow labels say "if $w=$0 during this cycle, the next state will be C; if $w=$1, the next state will be D".
  • At the rising edge: the state-register flip-flops sample $Q'$ (whatever the next-state logic was producing in the cycle just ending) and load it. $Q$ jumps to $Q'$.

So an arrow "B → C on $w=$0" really means: "if the FSM is in state B and $w=$0 during a clock cycle, then at the rising edge that ends that cycle, the state register loads C."

What the input does: $w$ doesn't cause the transition — it selects which transition will happen at the next clock edge. Changes to $w$ between edges only matter if $w$ is at the right level when the edge fires (must satisfy setup/hold times).

Consequences:

  • An input pulse shorter than a clock cycle may be missed — $w$ could be back to 0 by the next edge.
  • In a Moore FSM, $z = f(Q)$ — output changes only when $Q$ changes, i.e. only at clock edges (synchronous output).
  • In a Mealy FSM, $z = f(Q, w)$ — output can change mid-cycle when $w$ changes (asynchronous-looking output).

Mnemonic: the state diagram is a rulebook, not a movie. It says "in state X, if input is Y at the next clock edge, go to state Z." The clock is the implicit metronome that turns rules into transitions.

— example 6.12
6.26HardTier 1E?R
Derive a Mealy-type FSM that detects the same sequences as in Example 6.12 (two consecutive 0s or two consecutive 1s). Show that only three states are required and write the next-state and output expressions.— example 6.12
6.27HardTier 1E?R
Implement the state-assigned table of Figure 6.89 using JK-type flip-flops. Construct the excitation table for the J and K inputs and derive minimum expressions for $J_1, K_1, J_2, K_2, J_3, K_3$.
Context: Figure 6.89 — improved state assignment for Example 6.12

Figure 6.89 is an improved state assignment for the same 5-state "00 or 11" detector that Example 6.12 uses. The straightforward assignment in Figure 6.88 wastes the natural don't-cares; the improved one assigns codes so that $y_3$ acts as a "have we left reset?" flag — once the machine leaves state A, $y_3$ stays 1 forever.

Improved state assignment:

State$y_3 y_2 y_1$Next on $w=0$Next on $w=1$$z$
A (reset)000100 (B)110 (D)0
B (saw 0)100101 (C)110 (D)0
C (saw 00)101101 (C)110 (D)1
D (saw 1)110100 (B)111 (E)0
E (saw 11)111100 (B)111 (E)1

With D flip-flops, the textbook derives:

$$Y_1 = w\,\overline{y_2} + \overline{w}\,y_3\,y_2 \qquad Y_2 = w \qquad Y_3 = 1 \qquad z = y_1$$

Since $Y_3 = 1$ always (after leaving reset), $y_3$ collapses to a constant and the FSM reduces to two flip-flops + the trivial $y_3$ — much cheaper than the Figure 6.88 assignment.

What problem 6.27 asks: redo the implementation using JK flip-flops instead of D. For each state bit $y_i$, derive $J_i$ and $K_i$ such that the next state matches.

JK excitation table (the recipe for converting present→next into $J,K$):

Present $y_i$Next $Y_i$$J_i$$K_i$
000d
011d
10d1
11d0

Apply this row-by-row to every (present-state, $w$) combination in the table above to get a 10-row excitation table; then K-map-minimize each of $J_1, K_1, J_2, K_2, J_3, K_3$. Don't-care entries (the unused codes 001, 010, 011 and the don't-cares from the JK recipe) make the K-maps very loose — minimum-cost JK expressions are typically simpler than the corresponding D expressions for the same FSM.

— example 6.12
6.28MediumTier 1E?R
Write Verilog code that implements the 5-state Moore-type sequence detector of Example 6.12 (detects 00 or 11). Use a parameter statement to name the states and a two-always-block style.— example 6.12
6.29MediumTier 1E?R
Write Verilog code for the Mealy-type sequence detector of Example 6.14 (detects 00 or 11) using the style where the output $z$ is set inside the combinational always block.
Context: Example 6.14 — 3-state Mealy version of the "00 or 11" detector

Same specification as Example 6.12 (output 1 when previous two inputs were both 0 or both 1), but realized as a Mealy FSM. The Mealy form needs only 3 states instead of 5 because the output can depend on the current input as well as the state — so we don't need separate "saw 00" / "saw 11" states; the output fires on the transition itself.

States and transitions:

  • A — after reset, no relevant prior input. w=0 → B / z=0; w=1 → C / z=0
  • B — last input was 0. w=0 → B / z=1 (00 detected); w=1 → C / z=0
  • C — last input was 1. w=0 → B / z=0; w=1 → C / z=1 (11 detected)

State table (transitions show next-state / output):

State$w=0$ → next/$z$$w=1$ → next/$z$
AB / 0C / 0
B (saw 0)B / 1C / 0
C (saw 1)B / 0C / 1

Textbook state assignment ($y_2 y_1$): A=00, B=01, C=11. Code 10 is unused (don't-care). The clever bit: $y_1$ becomes a "have we left reset?" flag — once we leave A, $y_1$ stays 1, so $Y_1 = 1$ is the next-state equation. Effectively only one real flip-flop ($y_2$) is needed.

Why Mealy is more compact here: the Moore version (Example 6.12) needs separate states C and E to register "I've seen 00" / "I've seen 11" because Moore output is a function of state alone. Mealy fires its output the moment the qualifying input arrives, so the run-detection states aren't needed.

What problem 6.29 asks: write Verilog using the combinational always block style — both next-state and output are set inside always @*, with a separate always @(posedge clk) block for the state register. The Mealy nature means $z$ depends on both state and $w$, so $z$'s assignment lives in the same combinational block where state transitions are decided.

module mealy_seq (input w, clk, rst,
                  output reg z);
    parameter A = 2'b00, B = 2'b01, C = 2'b11;
    reg [1:0] state, next;

    always @(posedge clk or posedge rst)  // state register
        if (rst) state <= A;
        else     state <= next;

    always @* begin                        // next-state + output
        z = 1'b0;
        case (state)
            A: next = w ? C : B;
            B: begin next = w ? C : B; z = (w == 1'b0); end
            C: begin next = w ? C : B; z = (w == 1'b1); end
            default: next = A;
        endcase
    end
endmodule
— example 6.14
6.30HardTier 1E?R
Design a serial-data transmitter FSM that takes a 7-bit ASCII character on a parallel input and shifts it out one bit per clock cycle on a serial output line. Frame the byte appropriately and indicate when the transmission is complete.