马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本人学生党一枚,今天练习一个三段式的1101序列检测器,但是仿真输出来看,现态CS就没有变过,希望有大佬能帮忙看下代码,有没有啥问题
module seq_check(
input clk,
input rst_n,
input in,
output reg out,
output reg [2:0] CS,
output reg [2:0] NS
);
parameter [2:0] S0 = 3'b000;
parameter [2:0] S1 = 3'b001;
parameter [2:0] S2 = 3'b010;
parameter [2:0] S3 = 3'b011;
parameter [2:0] S4 = 3'b100;
always @ (posedge clk, negedge rst_n)
if (!rst_n)
CS <= S0;
else
CS <= NS;
always @ (in, rst_n, CS)
begin
case (CS)
S0: begin
if (!in)
NS = S0;
else
NS = S1;
end
S1: begin
if (!in)
NS = S0;
else
NS = S2;
end
S2: begin
if (!in)
NS = S3;
else
NS = S2;
end
S3: begin
if (!in)
NS = S0;
else
NS = S4;
end
S4: begin
if (!in)
NS = S0;
else
NS = S2;
end
endcase
end
always @ (posedge clk, negedge rst_n)
if (!rst_n)
out <= 1'b0;
else
begin
case (NS)
S0: out <= 1'b0;
S1: out <= 1'b0;
S2: out <= 1'b0;
S3: out <= 1'b0;
S4: out <= 1'b1;
endcase
end
endmodule
|