Altera_Forum
Honored Contributor
16 years agoA problem of FSM
The verilog code below is a FSM I designed . I find this FSM can run correctly and jump between different states at first ,
but after running several seconds it will fall into a fixed state(state=0, state2=0 or state=7,state2=4) and never come out again. According to the logic , the FSM can step into state 0 only once after power on reset; moreover ,any time when falling into state 0,it should can come out and step into state 1. But the reality is that it never come out again. Is there any problem with this FSM code ? How to deal with this problem? Thanks! code: reg [2:0] state; reg [2:0] state2; reg [9:0] count; always @(posedge CLK) begin if(RESET)//power on reset begin state <= 0; state2 <= 0; count <= 0; end else begin case (state) 0: begin case (state2) 0: begin if (count == 0) begin //process count <= count + 1; end else if (count < 2) begin //process count <= count + 1; end else begin count <= 0; state2 <= 1; end [/INDENT]end 1: begin if (count == 0) begin //process count <= count + 1; end else if (count < 6) begin //process count <= count + 1; end else begin count <= 0; state2 <= 2; end [/INDENT]end 2: begin if (count == 0) begin //process count <= count + 1; end else if (count < 6) begin //process count <= count + 1; end else begin count <= 0; state2 <= 3; end [/INDENT]end 3: begin if (count == 0) begin //process count <= count + 1; end if (count == 1) begin //process count <= 0; state2 <= 0; state <= 1; end [/INDENT]end endcase [/INDENT][/INDENT]end 1: begin //process state <= 2; end 2: begin //process state <= 3; end 3: begin //process state <= 4; end 4: begin //process state <= 5; end 5: begin //process state <= 6; end 6: begin //process state <= 1; end default: begin state <= 1; end endcase [/INDENT]end [/INDENT]end