module One_part( input clk, rst, input in, output [2:0] out ); reg [1:0] state=2'd0; reg [2:0] out_d=3'd0;
assign out=out_d;
always @(posedge clk or negedge rst) begin if (!rst) begin state <= 2'd0; end else begin case (state) 2'd0: begin if (in) begin //输入 state <= 2'd1; //判断 out_d <= 3'd2; //输出 end else begin state <= 2'd1; out_d <= 3'd0; end end 2'd1: begin if (in) begin state <= 2'd2; out_d <= 3'd3; end else begin state <= 2'd0; out_d <= 3'd8; end end 2'd2: begin if (in) begin state <= 2'd3; out_d <= 3'd4; end else begin state <= 2'd2; out_d <= 3'd7; end end 2'd3: begin if (in) begin state <= 2'd1; out_d <= 3'd5; end else begin state <= 2'd2; out_d <= 3'd6; end end default: state <= 2'd0; endcase end end
module two_parts( input clk, rst, input in, output [2:0] out ); reg [1:0] current_state=2'd0, next_state=2'd0; reg [2:0] out_d=3'd0; assign out=out_d; always @(posedge clk or negedge rst) begin if (!rst) begin current_state <= 1'd0; end else begin current_state <= next_state; end end
always @(*) begin case (current_state) 2'd0: begin out_d <= 3'd0; if (in) begin next_state <= 2'd1; end else begin next_state <= 2'd0; end end 2'd1: begin out_d <= 3'd1; if (in) begin next_state <= 2'd2; end else begin next_state <= 2'd0; end end 2'd2: begin out_d <= 3'd2; if (in) begin next_state <= 2'd3; end else begin next_state <= 2'd2; end end 2'd3: begin out_d <= 3'd3; if (in) begin next_state <= 2'd1; end else begin next_state <= 2'd2; end end endcase end endmodule
module three_parts( input clk, rst, input in, output [2:0] out ); reg [1:0] current_state=2'd0, next_state=2'd0; reg [2:0] out_d=3'd0; assign out=out_d; always @(posedge clk or negedge rst) begin if (!rst) begin current_state <= 1'd0; end else begin current_state <= next_state; end end
always @(*) begin case (current_state) 2'd0: begin if (in) begin next_state <= 2'd1; end else begin next_state <= 2'd0; end end 2'd1: begin if (in) begin next_state <= 2'd2; end else begin next_state <= 2'd0; end end 2'd2: begin if (in) begin next_state <= 2'd3; end else begin next_state <= 2'd2; end end 2'd3: begin if (in) begin next_state <= 2'd1; end else begin next_state <= 2'd2; end end endcase end
always @(posedge clk) begin case (current_state) 2'd0: begin out_d <= 3'd0; end 2'd1: begin out_d <= 3'd1; end 2'd2: begin out_d <= 3'd2; end 2'd3: begin out_d <= 3'd3; end endcase end