module state_6_8(x,z,clk,rst,state); input x,clk,rst; output z; output[2:0] state; reg z; reg [2:0] current_state,next_state; parameter s0=3'd0, s1=3'd1, s2=3'd2, s3=3'd3, s4=3'd4;//标识符 assign state=current_state; always@(posedge clk or posedge rst) begin if(rst) begin current_state<=s0; end else current_state<=next_state; end //主控时序逻辑描述 always@(current_state or x) begin casex(current_state) s0:if(x==1'b1) begin next_state<=s1; //次态逻辑和输出 z<=0; end else begin next_state<=s0; //次态逻辑和输出 z<=0; end s1:if(x==1'b0) begin next_state<=s2; //次态逻辑和输出 z<=0; end else begin next_state<=s1; z<=0; end s2:if(x==1'b0) begin next_state<=s3; z<=0; end else begin next_state<=s1; z<=0; end s3:if(x==1'b1) begin next_state<=s4; z<=1; end else begin next_state<=s0; z<=0; end /*s4:if(x==1'b1) begin next_state<=s1; z<=0; end else begin next_state<=s0; z<=0; end*/ s4:if(x==1'b1) begin next_state<=s1; z<=0; end else begin next_state<=s2; z<=0; end default next_state<=s0; endcase end endmodule 修改为11011序列检测电路代码
时间: 2024-04-02 12:32:53 浏览: 97
module state_11011(x, z, clk, rst, state);
input x, clk, rst;
output z;
output [2:0] state;
reg z;
reg [2:0] current_state, next_state;
parameter s0 = 3'd0, s1 = 3'd1, s2 = 3'd2, s3 = 3'd3, s4 = 3'd4;
assign state = current_state;
always @(posedge clk or posedge rst) begin
if (rst) begin
current_state <= s0;
end else begin
current_state <= next_state;
end
end
always @(current_state or x) begin
case (current_state)
s0: if (x == 1'b1) begin
next_state <= s1;
z <= 0;
end else begin
next_state <= s0;
z <= 0;
end
s1: if (x == 1'b1) begin
next_state <= s2;
z <= 0;
end else if (x == 1'b0) begin
next_state <= s1;
z <= 0;
end
s2: if (x == 1'b0) begin
next_state <= s3;
z <= 0;
end else if (x == 1'b1) begin
next_state <= s1;
z <= 0;
end
s3: if (x == 1'b1) begin
next_state <= s4;
z <= 0;
end else if (x == 1'b0) begin
next_state <= s3;
z <= 0;
end
s4: if (x == 1'b1) begin
next_state <= s1;
z <= 1;
end else if (x == 1'b0) begin
next_state <= s2;
z <= 0;
end
default: next_state <= s0;
endcase
end
endmodule
阅读全文