Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


State Machine odd behavior

State Machine odd behavior

State Machine odd behavior

Hi all, I am going nuts trying to figure out a problem with a simple state machine I wrote (shown below). It is just a 3-state design. In simulation I am getting a problem where whenever I am in a non-IDLE state, it first jumps to IDLE before going to the correct state. For instance, I am in READ, going to RUN. The simulation shows me going READ->IDLE->RUN, even though there is no possibility to jump from IDLE state to RUN state. Can anybody give me an idea of what I'm facing? This is quite embarrassing for me, as I am not new to this sort of thing O_O

And yes, I triple checked the state jumping conditions and they are what they are supposed to be.


parameter IDLE_STATE = 2'b00;
parameter READ_STATE = 2'b01;
parameter RUN_STATE  = 2'b10;

reg [1:0] current_state, next_state;

//current state handling
always @ (posedge clk) begin
    if (rst) current_state <= IDLE_STATE;
    else current_state <= next_state;

//next state handling
always @ (posedge clk) begin
    if (rst) next_state <= IDLE_STATE;
    else begin
        case (current_state)
            IDLE_STATE: begin if (!inc_fifo_empty)                 next_state <= READ_STATE;                     else next_state <= IDLE_STATE; end
            READ_STATE:    begin if (command == `CMD_WIDTH'd`RUN)  next_state <= RUN_STATE;                     else next_state <= IDLE_STATE; end
            RUN_STATE : begin if (tests_complete)                  next_state <= IDLE_STATE;                     else next_state <= RUN_STATE;  end
            default: next_state <= next_state;

RE: State Machine odd behavior

Conventionally, the next_state block would be combinational logic, not sequential logic as you have it.  Try to recode it as something like:


always @(*) begin
    case (current_state)
        IDLE_STATE: begin
           if (!inc_fifo_empty) next_state = READ_STATE;


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close