parameter A = 3'd0, B = 3'd1, C = 3'd2; parameter D = 3'd3, E = 3'd4, F = 3'd5; reg [2:0] current_state, next_state;
always @(*) begin case(current_state) A: next_state = w ? B : A; B: next_state = w ? C : D; C: next_state = w ? E : D; D: next_state = w ? F : A; E: next_state = w ? E : D; F: next_state = w ? C : D; default:next_state = A; endcase end
always @(posedge clk) begin if(reset) begin current_state <= A; end elsebegin current_state <= next_state; end end
assign z = (current_state == E) | (current_state == F);
parameter A = 2'd0, B = 2'd1; parameter C = 2'd2, D = 2'd3; reg [1:0] current_state, next_state;
always @(*) begin case(current_state) A:begin if(r[1] == 1'b1) begin next_state = B; end elseif(r[2] == 1'b1) begin next_state = C; end elseif(r[3] == 1'b1) begin next_state = D; end elsebegin next_state = A; end end B: next_state = r[1] ? B : A; C: next_state = r[2] ? C : A; D: next_state = r[3] ? D : A; default: next_state = A; endcase end
always @(posedge clk) begin if(~resetn) begin current_state <= A; end elsebegin current_state <= next_state; end end