Recall & Review
beginner
What is binary state encoding in Verilog FSM design?
Binary state encoding assigns states using the minimum number of bits needed, representing states as binary numbers (e.g., 00, 01, 10). It is memory efficient but can be slower due to multiple bits changing between states.
Click to reveal answer
beginner
Explain one-hot state encoding.
One-hot encoding uses one flip-flop per state. Only one bit is '1' at a time, and all others are '0'. This makes state decoding simple and fast but uses more hardware resources.
Click to reveal answer
intermediate
What is Gray code state encoding and why is it used?
Gray code encoding assigns states so that only one bit changes between consecutive states. This reduces glitches and switching noise in hardware, useful in some FSM designs.
Click to reveal answer
intermediate
Show a simple Verilog example of a one-hot encoded FSM with 3 states.
```verilog
module fsm_one_hot(input clk, reset, input in, output reg out);
typedef enum logic [2:0] {S0=3'b001, S1=3'b010, S2=3'b100} state_t;
state_t state, next_state;
always_ff @(posedge clk or posedge reset) begin
if (reset) state <= S0;
else state <= next_state;
end
always_comb begin
case(state)
S0: next_state = in ? S1 : S0;
S1: next_state = in ? S2 : S0;
S2: next_state = S0;
default: next_state = S0;
endcase
end
always_comb begin
out = (state == S2);
end
endmodule
```
Click to reveal answer
intermediate
Compare advantages and disadvantages of binary, one-hot, and gray state encoding.
- Binary: Uses fewer bits, saves hardware, but can cause glitches due to multiple bit changes.
- One-hot: Simple decoding, fast transitions, but uses more flip-flops.
- Gray: Minimizes glitches by changing one bit at a time, but needs more bits than binary and more complex encoding.
Click to reveal answer
Which state encoding uses one flip-flop per state?
✗ Incorrect
One-hot encoding assigns one flip-flop per state, with only one bit set to '1' at a time.
What is the main advantage of Gray code encoding in FSMs?
✗ Incorrect
Gray code changes only one bit between consecutive states, reducing glitches and switching noise.
Which encoding is most hardware efficient in terms of flip-flop count?
✗ Incorrect
Binary encoding uses the minimum number of bits, so it is most hardware efficient.
In a 4-state FSM, how many bits are needed for binary encoding?
✗ Incorrect
2 bits can represent 4 states (00, 01, 10, 11).
Which encoding typically results in the fastest state transitions?
✗ Incorrect
One-hot encoding has simple decoding and only one bit changes, making transitions faster.
Describe the differences between binary, one-hot, and gray state encoding in FSM design.
Think about how many bits change and how many flip-flops each encoding uses.
You got /4 concepts.
Write a simple Verilog snippet for a one-hot encoded FSM with three states and explain how the states are represented.
Use a typedef enum with one bit set per state.
You got /4 concepts.