1

does the enum literal deceleration of states for a state machine, guarantee a glitch free behavior as same as one would to assign order as below to the states?

enum { a,b,c} states; 

//vs if you were to declare

parameter a = 3'b000;
parameter b= 3'b010;
parameter c = 3'b011;

/////////////////////////

always @(posedge clk) begin  
  if ( reset) begin
    // initial condition 
    end
  else begin
    case ( state) begin
      a: begin
        state<=b;
      end
      b: begin   
        state<=c;
      end
      c: begin
        state<= a;
      end
      default: state<=c;
    endcase
  end
end
Matthew Taylor
  • 13,365
  • 3
  • 17
  • 44
Mel
  • 174
  • 1
  • 11

2 Answers2

2

For a state-machine to work 'reliably' all input signals must meet the setup and hold time of all registers which make up the state-machine.

This has nothing to do whatsoever how the state values are defined. Either direct or through an enum.

If one or more control signal arrives asynchronously it is not guaranteed what the next state will be.

Even if the states are defined using Gray-code and are following a Gray-sequence (See example below). This does no guarantee that the state-machine will work 'reliably'.

localparam ST0 = 2'b00,
           ST1 = 2'b01,
           ST2 = 2'b11,
           ST3 = 2'b10;
  ...
  case (state)
  ST0 : if (in==2'b11)
           state <= ST1;
  ST1 : if (in!=2'b11)
           state <= ST2;
  ST2 : if (in==2'b10)
           state <= ST3;
  ST3 : if (in==2'b01)
           state <= ST0;
  endcase

If in arrives asynchronously it can go from any state to any other state. This is because the logic driving each register needs to 'settle'. While the signal is not settled it may change between '1' or '0'. Thus each register can get a '1' or '0' at the input. The next state of the FSM can then take any possible value (or stay at the old state).

Oldfart
  • 6,104
  • 2
  • 13
  • 15
1

By default, the enum labels get the encodings a=0, b=1, c=2. And you can give explicit encodings:

enum { a=0,b=2,c=3} states; 

But many synthesis tools have directives to let the tool decide the best encodings for the FSM styles they recognize.

dave_59
  • 39,096
  • 3
  • 24
  • 63