What is the output of the following Verilog code snippet that uses binary state encoding?
module fsm_binary(input clk, input rst, output reg [1:0] state); parameter S0 = 2'b00, S1 = 2'b01, S2 = 2'b10; always @(posedge clk or posedge rst) begin if (rst) state <= S0; else case(state) S0: state <= S1; S1: state <= S2; S2: state <= S0; default: state <= S0; endcase end endmodule // Initial state is S0 (00). After 3 clock cycles, what is the state value?
Trace the state transitions starting from S0 for 3 clock cycles.
The state machine cycles through S0 (00), S1 (01), S2 (10), then back to S0 (00). After 3 cycles, it returns to S0 (00).
Given this one-hot encoded FSM, what is the value of state after 2 clock cycles?
module fsm_onehot(input clk, input rst, output reg [2:0] state); parameter S0 = 3'b001, S1 = 3'b010, S2 = 3'b100; always @(posedge clk or posedge rst) begin if (rst) state <= S0; else case(state) S0: state <= S1; S1: state <= S2; S2: state <= S0; default: state <= S0; endcase end endmodule // Initial state is S0 (001). After 2 clock cycles, what is the state value?
Follow the one-hot transitions from S0 through S1 to S2.
The FSM moves from S0 (001) to S1 (010) after 1 clock, then to S2 (100) after 2 clocks.
What is the output state after 4 clock cycles in this Gray code encoded FSM?
module fsm_gray(input clk, input rst, output reg [1:0] state); parameter S0 = 2'b00, S1 = 2'b01, S2 = 2'b11, S3 = 2'b10; always @(posedge clk or posedge rst) begin if (rst) state <= S0; else case(state) S0: state <= S1; S1: state <= S2; S2: state <= S3; S3: state <= S0; default: state <= S0; endcase end endmodule // Initial state is S0 (00). After 4 clock cycles, what is the state value?
Trace the Gray code sequence through all states for 4 cycles.
The FSM cycles through S0 (00), S1 (01), S2 (11), S3 (10), then back to S0 (00). After 4 cycles, it returns to S0.
Which option contains the error that will cause a synthesis or runtime problem in this one-hot FSM code?
module fsm_onehot_bug(input clk, input rst, output reg [2:0] state); parameter S0 = 3'b001, S1 = 3'b010, S2 = 3'b100; always @(posedge clk or posedge rst) begin if (rst) state <= S0; else case(state) S0: state <= S1; S1: state <= S2; S2: state <= 3'b110; // suspicious default: state <= S0; endcase end endmodule
Check if the assigned state values maintain one-hot encoding.
One-hot encoding requires only one bit set at a time. 3'b110 has two bits set, breaking the encoding and causing synthesis/runtime issues.
You have a FSM with 10 states encoded using Gray code. What is the minimal number of bits required to encode all states uniquely?
Think about how many unique states can be represented by n bits.
4 bits can represent 16 unique states, which is enough for 10 states. 3 bits only represent 8 states, which is insufficient.