I am designing "0110" overlapping sequence detector using moore model in verilog
verilog code:
`timescale 1ns / 1ps
module seq_detector(
input x,clk,reset,
output reg z
);
parameter S0 = 0 , S1 = 1 , S2 = 2 , S3 = 3 , S4 = 4;
reg [3:0] PS,NS ;
always@(posedge clk or posedge reset)
begin
if(reset)
PS <= S0;
else
PS <= NS ;
end
always@(PS or x)
begin
case(PS)
S0 : begin
z <= 0 ;
NS <= x ? S0 : S1 ;
$display(PS);
end
S1 : begin
z <= 0 ;
NS <= x ? S2 : S1 ;
$display(PS);
end
S2 : begin
z <= 0 ;
NS <= x ? S3 : S1 ;
$display(PS);
end
S3 : begin
z <= 0;
NS <= x ? S0 : S4 ;
$display(PS);
end
S4 : begin
z <= 1;
NS <= x ? S2 : S1 ;
$display(PS);
end
default: NS = S0;
endcase
end
always @(PS)
begin
case(PS)
S4: z = 1;
default: z = 0;
endcase
end
endmodule
module mooreoutput;
// Inputs
reg x;
reg clk;
reg reset;
// Outputs
wire z;
// Instantiate the Unit Under Test (UUT)
seq_detector uut (
.x(x),
.clk(clk),
.reset(reset),
.z(z)
);
always #5 clk = ~clk;
initial begin
$dumpfile("mooreoutput.vcd");
$dumpvars(1,mooreoutput);
fork
clk = 1'b0;
reset = 1'b1;
#15 reset = 1'b0;
begin
#11 x = 0; #10 x = 1 ; #11 x = 1 ; #10 x = 0 ;
#11 x = 1; #10 x = 1 ; #11 x = 0 ; #10 x = 1 ;
#11 x = 1; #10 x = 0 ; #11 x = 1 ; #10 x = 1 ;
#11 x = 0; #10 x = 1 ; #11 x = 1 ; #10 x = 0 ;
#10 $finish;
end
join
end
endmodule
The issue is that I have applied 5 times occurring "0110" overlapping, but in the waveform showing output 'z' is occurring 'high' for 4 times . What's the possible modification that I'd have to do, so as to eliminate this error ?can anyone send moore state table and logic circuit of 0110