0
0
Verilogprogramming~20 mins

State diagram to Verilog translation - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
State Diagram to Verilog Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple FSM with two states
Given the following Verilog code for a simple FSM with states IDLE and ACTIVE, what is the output out after the first clock cycle if start is 1 at reset?
Verilog
module fsm(input clk, input reset, input start, output reg out);
  typedef enum logic [1:0] {IDLE=2'b00, ACTIVE=2'b01} state_t;
  state_t state, next_state;

  always_ff @(posedge clk or posedge reset) begin
    if (reset) state <= IDLE;
    else state <= next_state;
  end

  always_comb begin
    next_state = state;
    out = 0;
    case(state)
      IDLE: if (start) next_state = ACTIVE;
      ACTIVE: out = 1;
    endcase
  end
endmodule
Aout = Z (high impedance)
Bout = 1
Cout = X (unknown)
Dout = 0
Attempts:
2 left
💡 Hint
Combinational outputs update immediately based on the new state after the clock edge.
🧠 Conceptual
intermediate
1:30remaining
State encoding in Verilog FSM
Which of the following is the best way to encode states in a Verilog FSM for clarity and maintainability?
AUse <code>typedef enum logic</code> with named states
BUse <code>parameter</code> constants with binary values for each state
CUse plain integers without naming states
DUse <code>localparam</code> with decimal values for states
Attempts:
2 left
💡 Hint
Modern Verilog supports enumerated types for better readability.
🔧 Debug
advanced
2:00remaining
Identify the error in this FSM state transition code
What error will this Verilog FSM code produce when synthesized or simulated?
Verilog
always_ff @(posedge clk) begin
  if (reset) state <= IDLE;
  else begin
    case(state)
      IDLE: if (start) state <= ACTIVE;
      ACTIVE: state <= IDLE;
    endcase
  end
end

always_comb begin
  case(state)
    IDLE: out = 0;
    ACTIVE: out = 1;
  endcase
end
ASyntax error due to missing default case
BNo error, code works correctly
CLatch inferred for 'out' signal
DMultiple drivers for 'state' signal
Attempts:
2 left
💡 Hint
Check if all outputs are assigned in all branches of combinational block.
📝 Syntax
advanced
1:30remaining
Correct syntax for synchronous reset in Verilog FSM
Which option shows the correct syntax for a synchronous reset in a Verilog FSM?
Aalways_ff @(posedge clk) begin if (reset) state <= IDLE; else state <= next_state; end
Balways_ff @(posedge reset or posedge clk) begin if (reset) state <= IDLE; else state <= next_state; end
Calways_ff @(posedge clk or posedge reset) begin if (reset) state <= IDLE; else state <= next_state; end
Dalways_ff @(negedge clk) begin if (reset) state <= IDLE; else state <= next_state; end
Attempts:
2 left
💡 Hint
Synchronous reset triggers only on clock edge.
🚀 Application
expert
2:30remaining
Number of states and output values in a Mealy FSM
A Mealy FSM has 3 states and 2 inputs. The output depends on the current state and inputs. How many unique output values can this FSM produce at maximum?
A3
B6
C8
D12
Attempts:
2 left
💡 Hint
Consider outputs can differ for each state-input combination.