HDL & Verification

In the state machine above, why does the second always block begin with "next = state;"?

always @(posedge clk)
    state <= next;
always @(*) begin
    next = state;
    case (state)
        IDLE: if (start) next = RUN;
        RUN:  if (done)  next = IDLE;
    endcase
end
  1. ATo stay in the current state when no condition matches and to assign next in every case, preventing a latch
  2. BTo return the state to IDLE every time
  3. CTo stop the clock
Show answer and explanation

Answer: A. To stay in the current state when no condition matches and to assign next in every case, preventing a latch

Splitting a state machine into a register block that updates the state and a combinational block that computes the next state is a common style. In the combinational block, if nothing assigns next when start or done is 0, a latch forms. Starting with "next = state;" clearly expresses staying in the current state when no condition matches, while preventing the latch.

  • A. Correct. It sets the default value first.
  • B. It holds the current state rather than resetting to IDLE.
  • C. It has nothing to do with the clock.
Practice this topic Back to topic

More HDL & Verification questions

  1. What characterizes a Mealy state machine?
  2. What is a characteristic of one-hot encoding for state machine states?
  3. For a state machine with three states, how many flip-flops are needed to store the state (binary encoding / one-hot encoding)?
  4. In the 4-bit counter above, when count is 15 and a rising clock edge arrives, what does count become?
  5. In Verilog, two 8-bit signals a and b are added and assigned to an 8-bit signal s (assign s = a + b;). What should be watched for?