题解 | #状态机-非重叠的序列检测#
这个因为是非重叠序列的检测,所以检测过的bit就不能重新检测了,所以所有的次状态都是返回s0
没有问题
`timescale 1ns/1ns
module sequence_test1(
input wire clk ,
input wire rst ,
input wire data ,
output reg flag
);
//*************code***********//
parameter [4:0]s0 = 'b0;
parameter [4:0]s1 = 'b1;
parameter [4:0]s2 = 'b10;
parameter [4:0]s3 = 'b101;
parameter [4:0]s4 = 'b1011;
parameter [4:0]s5 = 'b10111;
reg [4:0] cur_st,next_st;
always @(posedge clk,negedge rst)
begin
if(!rst)
begin
cur_st <= s0;
end
else
begin
cur_st <= next_st;
end
end
always @(*)
begin
if(!rst)
begin
next_st <= s0;
flag <= 0;
end
else
begin
case(cur_st)
s0 : next_st <= data?s1:s0;
s1 : next_st <= data?s0:s2;
s2 : next_st <= data?s3:s0;
s3 : next_st <= data?s4:s0;
s4 : next_st <= data?s5:s0;
s5 : next_st <= data?s1:s0;
default : next_st <= s0;
endcase
if (cur_st == s5)
flag <= 1;
else
flag <= 0;
end
end
//*************code***********//
endmodule