0
0
Verilogprogramming~5 mins

State encoding (binary, one-hot, gray) in Verilog - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABinary encoding
BThermometer encoding
COne-hot encoding
DGray encoding
What is the main advantage of Gray code encoding in FSMs?
AMinimizes number of flip-flops
BOnly one bit changes between states to reduce glitches
CSimplifies state decoding
DUses less power than binary encoding
Which encoding is most hardware efficient in terms of flip-flop count?
ABinary encoding
BOne-hot encoding
CGray encoding
DJohnson encoding
In a 4-state FSM, how many bits are needed for binary encoding?
A4 bits
B1 bit
C3 bits
D2 bits
Which encoding typically results in the fastest state transitions?
AOne-hot encoding
BBinary encoding
CGray encoding
DRandom encoding
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.