Lesson 18 +40 XP

Synchronous Sequential Design & Sequence Detectors

Synchronous Sequential Design & Sequence Detectors

Design is analysis run backwards. We start from a word description ("output 1 whenever the input has been 1 three times in a row"), turn it into a state diagram, and end with flip-flops and gates. The sequence detector is the classic exam problem for this procedure, and this lesson works several of them in full.

1. The Design Procedure

Eight steps of sequential circuit designEight steps of sequential circuit design

  1. From the word statement, draw the state diagram (decide Mealy or Moore).
  2. Write the state table.
  3. Reduce the number of states if possible (Lesson 17).
  4. Assign binary codes to the states.
  5. Choose the flip-flop type (D, JK or T).
  6. Build the excitation table: add the required flip-flop inputs to each row of the state table.
  7. Simplify each flip-flop input and each output with K-maps (unused states are don't-cares).
  8. Draw the circuit and check what happens in the unused states.

With D flip-flops step 6 is free, because D = Q+: the next-state columns are the D inputs.

2. Example: Three or More Consecutive 1s

SolvedExample 1 · Moore detector for 111 with D flip-flops (Mano)

Design a circuit with input x and output y, where y = 1 when x has been 1 for three or more consecutive clock pulses.

  1. States. S0: last input 0 (or reset); S1: one 1; S2: two 1s; S3: three or more 1s, output 1. Any 0 returns to S0; a 1 moves one state right, and S3 stays in S3.
  2. Assignment. S0 = 00, S1 = 01, S2 = 10, S3 = 11 (flip-flops A, B).
  3. State table:
ABxA⁺B⁺y
000000
001010
010000
011100
100000
101110
110001
111111
  1. A+ = ∑ m(3, 5, 7) over A, B, x: pairs Bx (3, 7) and Ax (5, 7), so DA = Ax + Bx.
  2. B+ = ∑ m(1, 5, 7): pairs B'x (1, 5) and Ax (5, 7), so DB = Ax + B'x.
  3. The output depends only on the state: y = AB (Moore).
AnswerDA = Ax + Bx, DB = Ax + B'x, y = AB

State diagram of the three-1s detectorState diagram of the three-1s detector

3. Sequence Detectors: Overlapping or Not

A sequence detector outputs 1 when a particular bit pattern has just arrived on its serial input. Two conventions exist:

OverlappingNon-overlapping
Rulethe end of one match may start the nextafter a match, start again from scratch
Input 1011011 for pattern 1011detects at bit 4 and bit 7detects at bit 4 only
After a match go tothe state for the longest suffix that is still a prefixthe reset state

The states of a detector record how much of the pattern has been seen so far. For pattern 1011 they are: nothing, "1", "10", "101".

On a wrong bit, do not simply go back to the start: go to the state for the longest suffix of what was seen that is also a prefix of the pattern. For example, in state "101" an input 0 gives "1010", whose longest useful suffix is "10".

4. The 1011 Detector (Mealy)

SolvedExample 2 · Mealy 1011 detector, overlapping, with D flip-flops

Design a Mealy circuit that outputs z = 1 when the last four inputs were 1011 (overlapping allowed).

  1. States: S0 (nothing), S1 (seen 1), S2 (seen 10), S3 (seen 101).
  2. Transitions:
Presentx = 0x = 1Reason
S0S0 / 0S1 / 0a 1 starts the pattern
S1S2 / 0S1 / 0"11": the last 1 is still a start
S2S0 / 0S3 / 0"100" has no useful suffix
S3S2 / 0S1 / 1"1011" found; its last 1 starts a new match
  1. Assignment S0 = 00, S1 = 01, S2 = 10, S3 = 11 gives the binary state table:
ABxA⁺B⁺z
000000
001010
010100
011010
100000
101110
110100
111011
  1. DA = A+ = ∑ m(2, 5, 6): pair Bx' (2, 6) and single AB'x (5). So DA = Bx' + AB'x.
  2. DB = B+ = ∑ m(1, 3, 5, 7) = x.
  3. z = ∑ m(7) = ABx.
AnswerDA = Bx' + AB'x, DB = x, z = ABx

Mealy state diagram for 1011Mealy state diagram for 1011

K-map for DA and the logic diagram of the detectorK-map for DA and the logic diagram of the detector

Notice how cheap the assignment made B: since every state reached by an input 1 has B = 1 and every state reached by 0 has B = 0, DB = x directly. A good assignment can save a lot of logic.

5. The Same Detector as a Moore Machine

A Moore machine cannot put the output on an arrow, so it needs a separate state for "1011 just seen" with output 1.

SolvedExample 3 · Moore 1011 detector, overlapping

Draw the state diagram and state table of a Moore machine for 1011 (overlapping). How many flip-flops are needed?

StateMeaningx = 0x = 1Output
S0nothingS0S10
S1seen 1S2S10
S2seen 10S0S30
S3seen 101S2S40
S4seen 1011S2S11
  1. From S4 an input 0 gives "10110", whose longest useful suffix is "10": go to S2.
  2. From S4 an input 1 gives "10111", whose longest useful suffix is "1": go to S1.
  3. Five states need ⌈ log2 5 ⌉ = 3 flip-flops; three codes are unused and become don't-cares.
Answer5 states and 3 flip-flops (the Mealy version needs 4 states and 2 flip-flops)

Moore state diagram for 1011Moore state diagram for 1011

The Moore output appears one clock later than the Mealy output (in the cycle after the last 1), but it is free of input glitches.

SolvedExample 4 · Non-overlapping version

How does the Mealy state table of Example 2 change for a non-overlapping 1011 detector? What does it output for the input 1011011?

  1. Only the transition that completes a match changes: S3 with x = 1 now goes to S0 / 1 instead of S1 / 1.
  2. Input 1011011: bits 1 to 4 complete 1011, output 1, back to S0.
  3. Bits 5 to 7 are 011: from S0, 0 → S0, 1 → S1, 1 → S1. No second detection.
AnswerS3 goes to S0 with output 1 on input 1; the output is 0001000 (overlapping would give 0001001)
SolvedExample 5 · Mealy 101 detector (overlapping)

Give the state table of a Mealy detector for 101, overlapping. What is the output for the input 10101?

Statex = 0x = 1
S0 (nothing)S0 / 0S1 / 0
S1 (seen 1)S2 / 0S1 / 0
S2 (seen 10)S0 / 0S1 / 1
  1. After "101" the last 1 is the start of a new match, so S2 goes to S1 with output 1 on input 1.
  2. Input 1, 0, 1, 0, 1: states S1, S2, S1 (output 1), S2, S1 (output 1).
Answeroutput 00101 (two overlapping detections)

6. Sequence Detector in Verilog

The usual HDL style for a state machine has two always blocks: one sequential block that updates the state register on the clock, and one combinational block (a case statement) for the next state. The testbench also builds the gate-level design of Example 2 and feeds both the stream 10110111011:

VERILOG
// 1011 sequence detector (Mealy, overlapping): behavioural FSM and the gate-level design
module det1011_fsm (
    input      clk,
    input      rst_n,
    input      x,
    output     z
);
    localparam S0 = 2'b00,      // nothing useful seen
               S1 = 2'b01,      // seen 1
               S2 = 2'b10,      // seen 10
               S3 = 2'b11;      // seen 101
    reg [1:0] state, next;

    always @(posedge clk or negedge rst_n) begin
        if (!rst_n)
            state <= S0;
        else
            state <= next;
    end

    always @(*) begin
        case (state)
            S0: next = x ? S1 : S0;
            S1: next = x ? S1 : S2;
            S2: next = x ? S3 : S0;
            S3: next = x ? S1 : S2;     // 1011 overlaps into "1"; 1010 into "10"
        endcase
    end

    assign z = (state == S3) & x;       // Mealy output
endmodule

module det1011_gates (
    input      clk,
    input      rst_n,
    input      x,
    output     z
);
    reg A, B;
    wire DA = (B & ~x) | (A & ~B & x);  // from the K-map
    wire DB = x;

    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            A <= 1'b0;
            B <= 1'b0;
        end else begin
            A <= DA;
            B <= DB;
        end
    end

    assign z = A & B & x;
endmodule

module tb;
    reg clk = 0, rst_n = 0, x = 0;
    wire z1, z2;
    reg [10:0] stream = 11'b10110111011;
    integer i;

    det1011_fsm   u1 (.clk(clk), .rst_n(rst_n), .x(x), .z(z1));
    det1011_gates u2 (.clk(clk), .rst_n(rst_n), .x(x), .z(z2));

    initial begin
        #1 rst_n = 1;
        $display("bit  x  z(fsm)  z(gates)");
        for (i = 10; i >= 0; i = i - 1) begin
            x = stream[i];
            #1 $display("%3d  %b    %b       %b", 10 - i, x, z1, z2);
            #4 clk = 1;
            #5 clk = 0;
        end
    end
endmodule

The two designs agree, and detections occur at bits 3, 6 and 10 (counting from 0), including the overlapping one at bit 6:

OUTPUT
bit  x  z(fsm)  z(gates)
  0  1    0       0
  1  0    0       0
  2  1    0       0
  3  1    1       1
  4  0    0       0
  5  1    0       0
  6  1    1       1
  7  1    0       0
  8  0    0       0
  9  1    0       0
 10  1    1       1
💡 Tip

Key points to remember

  • Design: diagram → table → reduce → assign → choose FF → excitation → K-maps → circuit.
  • With D flip-flops, D = Q+; unused states are don't-cares.
  • A detector's states record how much of the pattern has been matched; on a mismatch go to the longest suffix that is a prefix.
  • Overlapping: after a match, keep the useful suffix. Non-overlapping: go back to reset.
  • Mealy 1011: 4 states, DA = Bx' + AB'x, DB = x, z = ABx. Moore 1011: 5 states.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. Explain the steps in the design of a clocked synchronous sequential circuit. (5 Marks)
  • Q2. Design a sequence detector for 1011 (overlapping) using D flip-flops. Draw the state diagram, state table, K-maps and circuit. (10 Marks)
  • Write: the 4-state Mealy diagram, the binary state table, DA = Bx' + AB'x, DB = x, z = ABx, the logic diagram.
  • Q3. Design a Moore machine that outputs 1 when three or more consecutive 1s have been received. (10 Marks)
  • Q4. Draw the Mealy and Moore state diagrams for a 101 sequence detector. Compare the number of states. (5 Marks)
  • Q5. Distinguish between overlapping and non-overlapping sequence detection with an example. (2.5 Marks)