Loading lessons...
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 design
- From the word statement, draw the state diagram (decide Mealy or Moore).
- Write the state table.
- Reduce the number of states if possible (Lesson 17).
- Assign binary codes to the states.
- Choose the flip-flop type (D, JK or T).
- Build the excitation table: add the required flip-flop inputs to each row of the state table.
- Simplify each flip-flop input and each output with K-maps (unused states are don't-cares).
- 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
Design a circuit with input x and output y, where y = 1 when x has been 1 for three or more consecutive clock pulses.
- 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.
- Assignment. S0 = 00, S1 = 01, S2 = 10, S3 = 11 (flip-flops A, B).
- State table:
| AB | x | A⁺B⁺ | y |
|---|---|---|---|
| 00 | 0 | 00 | 0 |
| 00 | 1 | 01 | 0 |
| 01 | 0 | 00 | 0 |
| 01 | 1 | 10 | 0 |
| 10 | 0 | 00 | 0 |
| 10 | 1 | 11 | 0 |
| 11 | 0 | 00 | 1 |
| 11 | 1 | 11 | 1 |
- A+ = ∑ m(3, 5, 7) over A, B, x: pairs Bx (3, 7) and Ax (5, 7), so DA = Ax + Bx.
- B+ = ∑ m(1, 5, 7): pairs B'x (1, 5) and Ax (5, 7), so DB = Ax + B'x.
- The output depends only on the state: y = AB (Moore).
State 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:
| Overlapping | Non-overlapping | |
|---|---|---|
| Rule | the end of one match may start the next | after a match, start again from scratch |
| Input 1011011 for pattern 1011 | detects at bit 4 and bit 7 | detects at bit 4 only |
| After a match go to | the state for the longest suffix that is still a prefix | the 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)
Design a Mealy circuit that outputs z = 1 when the last four inputs were 1011 (overlapping allowed).
- States: S0 (nothing), S1 (seen 1), S2 (seen 10), S3 (seen 101).
- Transitions:
| Present | x = 0 | x = 1 | Reason |
|---|---|---|---|
| S0 | S0 / 0 | S1 / 0 | a 1 starts the pattern |
| S1 | S2 / 0 | S1 / 0 | "11": the last 1 is still a start |
| S2 | S0 / 0 | S3 / 0 | "100" has no useful suffix |
| S3 | S2 / 0 | S1 / 1 | "1011" found; its last 1 starts a new match |
- Assignment S0 = 00, S1 = 01, S2 = 10, S3 = 11 gives the binary state table:
| AB | x | A⁺B⁺ | z |
|---|---|---|---|
| 00 | 0 | 00 | 0 |
| 00 | 1 | 01 | 0 |
| 01 | 0 | 10 | 0 |
| 01 | 1 | 01 | 0 |
| 10 | 0 | 00 | 0 |
| 10 | 1 | 11 | 0 |
| 11 | 0 | 10 | 0 |
| 11 | 1 | 01 | 1 |
- DA = A+ = ∑ m(2, 5, 6): pair Bx' (2, 6) and single AB'x (5). So DA = Bx' + AB'x.
- DB = B+ = ∑ m(1, 3, 5, 7) = x.
- z = ∑ m(7) = ABx.
Mealy state diagram for 1011
K-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.
Draw the state diagram and state table of a Moore machine for 1011 (overlapping). How many flip-flops are needed?
| State | Meaning | x = 0 | x = 1 | Output |
|---|---|---|---|---|
| S0 | nothing | S0 | S1 | 0 |
| S1 | seen 1 | S2 | S1 | 0 |
| S2 | seen 10 | S0 | S3 | 0 |
| S3 | seen 101 | S2 | S4 | 0 |
| S4 | seen 1011 | S2 | S1 | 1 |
- From S4 an input 0 gives "10110", whose longest useful suffix is "10": go to S2.
- From S4 an input 1 gives "10111", whose longest useful suffix is "1": go to S1.
- Five states need ⌈ log2 5 ⌉ = 3 flip-flops; three codes are unused and become don't-cares.
Moore 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.
How does the Mealy state table of Example 2 change for a non-overlapping 1011 detector? What does it output for the input 1011011?
- Only the transition that completes a match changes: S3 with x = 1 now goes to S0 / 1 instead of S1 / 1.
- Input 1011011: bits 1 to 4 complete 1011, output 1, back to S0.
- Bits 5 to 7 are 011: from S0, 0 → S0, 1 → S1, 1 → S1. No second detection.
Give the state table of a Mealy detector for 101, overlapping. What is the output for the input 10101?
| State | x = 0 | x = 1 |
|---|---|---|
| S0 (nothing) | S0 / 0 | S1 / 0 |
| S1 (seen 1) | S2 / 0 | S1 / 0 |
| S2 (seen 10) | S0 / 0 | S1 / 1 |
- After "101" the last 1 is the start of a new match, so S2 goes to S1 with output 1 on input 1.
- Input 1, 0, 1, 0, 1: states S1, S2, S1 (output 1), S2, S1 (output 1).
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:
// 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
endmoduleThe two designs agree, and detections occur at bits 3, 6 and 10 (counting from 0), including the overlapping one at bit 6:
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 1Key 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.
📝 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)