I'm trying to convert a flow chart simple state machine into Verilog code.
But I'm somehow stuck with the following, and as I have hardly any knowledge in Verilog I'm probably missing something.
The statemachine detects for an input stream of 0 and 1, if the count of 1s can be divided by 3 (or simply: if there have been 3 times number 1).

module example (
input clk,
input rst,
input input1,
output output
);
reg state;
reg nextstate;
localparam state2 = 3'd0;
localparam state1 = 3'd1;
localparam state0 = 3'd2;
always @(posedge clk or posedge rst) begin
if (rst)
state <= state0;
else
state <= nextstate;
end
always @* begin
case(state)
state0: begin
if(input1)
nextstate = state1;
end
state2: begin
if(input1)
nextstate = state0;
end
state1: begin
if(input1)
nextstate = state2;
end
default: nextstate = state0;
endcase
end
always @* begin
output1 = state0 & input1;
end
endmodule
I'm not sure:
do I have to define the inputs + outputs as
regorwire? Or isinputandoutput! sufficient?must I provide a vector dimension for the
reg state, nextstate? If yes, how to I know which dimension to pick?can I write these kind of assertions at the end like
state0 & input1? Or should I usestate = state0 & input1 = ??- yes, what?