I have a state machine with several states that are very similar. I could write it for each state, like in the following example:
module CHECK_FSM (
GO,
DONE,
CLK, RESETN );
input GO;
output reg DONE;
input CLK,RESETN;
reg[7:0] state;
reg[7:0] next_state;
//the actual registers
always @(posedge CLK or negedge RESETN)
if (!RESETN) state <= 8'd0;
else state <= next_state;
//next state logic
always @(*)
begin
//defaults
next_state = state;
DONE = 1'b0; //low by default
case(state)
0: //S_INIT
if(GO==1'b1)
next_state = 8'd1;
else
next_state = 8'd0;
1: //S_WAIT_1:
if(GO==1'b1)
next_state = state+1; //continue
else
next_state = 8'd0; //go back to S_INIT
2: //S_WAIT_2:
if(GO==1'b1)
next_state = state+1; //continue
else
next_state = 8'd0; //go back to S_INIT
3: //S_WAIT_3:
if(GO==1'b1)
next_state = state+1; //continue
else
next_state = 8'd0; //go back to S_INIT
//...
127: //S_FINISH
begin
DONE = 1'b1;
next_state = state; //stay put
end
default: next_state= 8'd0;
endcase
end
endmodule
I am wondering if there is a way to specify the case statement for multiple states. Something like:
case(state)
0: //S_INIT
if(GO==1'b1)
next_state = 8'd1;
else
next_state = 8'd0;
[1-->126]:
if(GO==1'b1)
next_state = state+1; //continue
else
next_state = 8'd0; //go back to S_INIT
127: //S_FINISH
begin
DONE = 1'b1;
next_state = state; //stay put
end
default: next_state= 8'd0;
endcase
I want to avoid repeating the statements (that are all the same) to be more clear and to avoid errors if I need to modify it afterwards (my actual FSM is more complicated than this...). Any ideas ?
PS: The code is meant to be synthesized. In my case, the synthesis tool does not support SystemVerilog statements, so I am hoping for a Verilog solution.