Consider the following VHDL code snippet defining a state machine with states encoded using the state_encoding attribute. What is the output of the report statement?
type state_type is (IDLE, READ, WRITE); attribute state_encoding : string; attribute state_encoding of state_type : type is "onehot"; signal current_state : state_type := IDLE; process begin report "Encoding of current_state: " & state_type'state_encoding; wait; end process;
Check the attribute assigned to state_type.
The attribute state_encoding is set to "onehot" for the state_type. So, when queried for current_state, it returns "onehot".
What is the main purpose of the state_encoding attribute in VHDL state machines?
Think about how states are stored and implemented physically.
The state_encoding attribute tells the synthesis tool how to encode the states internally, such as one-hot or binary encoding, which affects hardware optimization.
Examine the following VHDL code snippet. What error will occur when synthesizing this code?
type state_type is (S0, S1, S2); attribute state_encoding : string; attribute state_encoding of state_type : type is "onehot"; signal state_reg : std_logic_vector(1 downto 0); process(clk) begin if rising_edge(clk) then case state_reg is when "00" => state_reg <= "01"; when "01" => state_reg <= "10"; when others => state_reg <= "00"; end case; end if; end process;
Check the types used for states and signals.
The state_encoding attribute is applied to state_type, but the process uses a std_logic_vector signal state_reg instead of state_type. This mismatch causes synthesis errors.
Which of the following is the correct syntax to apply the state_encoding attribute to an enumerated type fsm_state with encoding "binary"?
Remember the order: declare attribute, then apply it to type.
The correct syntax declares the attribute type first, then applies it to the type with the encoding string.
You have a VHDL state machine with state_encoding set to "onehot". How does this affect the synthesized hardware compared to "binary" encoding?
Think about how many bits represent states and logic complexity.
One-hot encoding assigns one flip-flop per state, increasing flip-flop count but simplifying combinational logic, which can improve speed.
