Design overlapping and non-overlapping Mealy FSMs for sequence detector 1010
Design overlapping and non-overlapping Mealy FSMs for sequence detector 1010
Model answer
States: A = idle, B = seen 1 , C = seen 10 , D = seen 101 . Output $z=1$ when in D and input $x=0$ (Mealy output). The **only** difference is state D on $x=0$: non-overlapping goes back to A (start fresh); overlapping goes to C (the trailing 10 of 1010 is the start of the next match). {|c|c|c|c|}\hline Present state & Seen so far & x=0\ (next/z) & x=1\ (next/z)\\ \hline A & none & A/0 & B/0\\ \hline B & 1 & C/0 & B/0\\ \hline C & 10 & A/0 & D/0\\ \hline D & 101 & A/1\ (non-ovl)\ \ or\ \ C/1\ (ovl) & B/0\\ \hline Non-overlapping: verilog module seq_1010_nonoverlap (input clk, rst_n, x, output z); localparam A = 2'd0, B = 2'd1, C = 2'd2, D = 2'd3; reg [1:0] state, next_state; verilog always @(posedge clk or negedge rst_n) if (!rst_n) state <= A; else state <= next_state; verilog always @(*) begin case (state) A: next_state = x ? B : A; B: next_state = x ? B : C; C: next_state = x ? D : A; D: next_state = x ? B : A; // restart default: next_state = A; endcase end verilog assign z = (state == D) && !x; endmodule Overlapping: identical, except the D branch: Testbench (input stream 10101010 , one bit per clock): verilog module tb; reg clk = 0, rst_n = 0, x = 0; wire z; seq_1010_nonoverlap dut (clk, rst_n, x, z); // swap for the overlapping module always #5 clk = ~clk; verilog reg [7:0] stream = 8'b1010_1010; integer i; initial begin $monitor("t=%0t x=%b z=%b", $time, x, z); #12 rst_n = 1; for (i = 7; i >= 0; i = i - 1) @(negedge clk) x = stream[i]; @(negedge clk); $finish; end endmodule {|l|c|c|c|c|c|c|c|c|}\hline Input x & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0\\ \hline z\ (non-overlapping) & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 1\\ \hline z\ (overlapping) & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 1\\ \hline State diagram — non-overlapping (TikZ): State diagram — overlapping (TikZ): Edge label format is input/output . ---