0
0
Verilogprogramming~10 mins

FSM with output logic in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the state register.

Verilog
reg [1:0] [1];
Drag options to blanks, or click blank then click option'
Ainput
Bstate
Coutput
Dclk
Attempts:
3 left
💡 Hint
Common Mistakes
Using input or output names instead of the state register.
2fill in blank
medium

Complete the code to define the next state logic using a case statement.

Verilog
always @(*) begin
  case (state)
    2'b00: next_state = [1];
    default: next_state = 2'b00;
  endcase
end
Drag options to blanks, or click blank then click option'
A2'b11
B2'b10
C2'b01
D2'b00
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the current state as next state causing no transition.
3fill in blank
hard

Fix the error in the output logic to assign output based on the current state.

Verilog
always @(*) begin
  case ([1])
    2'b00: out = 1'b0;
    2'b01: out = 1'b1;
    default: out = 1'b0;
  endcase
end
Drag options to blanks, or click blank then click option'
Anext_state
Bclk
Cinput
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using next_state or input signals instead of current state.
4fill in blank
hard

Fill both blanks to complete the synchronous state update logic.

Verilog
always @(posedge [1] or posedge [2]) begin
  if (reset)
    state <= 2'b00;
  else
    state <= next_state;
end
Drag options to blanks, or click blank then click option'
Aclk
Breset
Cinput
Dout
Attempts:
3 left
💡 Hint
Common Mistakes
Using input or output signals instead of clock or reset.
5fill in blank
hard

Fill all three blanks to complete the FSM module header and port declarations.

Verilog
module fsm(
  input wire [1],
  input wire [2],
  output reg [3]
);
Drag options to blanks, or click blank then click option'
Aclk
Breset
Cout
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using internal signals like state as ports.