So I am pretty new to Verilog and I am trying to write a simple FSM.
Input a
is a push button and by pushing it starts the machine. But every other next state, after initially pressing a
, causes to go back to the start/initial state.
input clk, reset;
input a,b,c;
reg [1:0] state;
reg [1:0] nextstate;
parameter = START=2b'0,
STATE1=2b'1,
STATE2=2b'11;
always @(posedge clk)
if(reset) state <= START;
else state<=nextstate;
always @(state, a)
case (state)
START: begin if(a) nextstate<=STATE1; else nextstate<=START; end
STATE1: begin if(a) nextstate<=START; else if(b) nextstate<=STATE2; else nextstate<=STATE1; end
STATE2: begin if(a) nextstate<=START; else if(c) nextstate<=STATE1; else nextstate<=STATE2; end
endcase
Keeping your finger on a
now means my state is alternating between STATE1
and START
every positive edge of clk
.
How do I fix this?