Challenge - 5 Problems
Priority Encoder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a 4-to-2 Priority Encoder
What is the output of this 4-to-2 priority encoder when the input is "1010"?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity priority_encoder is Port ( input : in STD_LOGIC_VECTOR (3 downto 0); output : out STD_LOGIC_VECTOR (1 downto 0); valid : out STD_LOGIC); end priority_encoder; architecture Behavioral of priority_encoder is begin process(input) begin valid <= '0'; output <= "00"; if input(3) = '1' then output <= "11"; valid <= '1'; elsif input(2) = '1' then output <= "10"; valid <= '1'; elsif input(1) = '1' then output <= "01"; valid <= '1'; elsif input(0) = '1' then output <= "00"; valid <= '1'; end if; end process; end Behavioral;
Attempts:
2 left
💡 Hint
Remember the priority encoder outputs the highest priority bit set to 1.
✗ Incorrect
The input "1010" means bits 3 and 1 are set. The highest priority bit is bit 3, so output is "11" and valid is '1'.
🧠 Conceptual
intermediate1:30remaining
Understanding Priority Encoder Valid Signal
In a priority encoder, what does the 'valid' output signal indicate?
Attempts:
2 left
💡 Hint
Think about when the encoder should output a valid code.
✗ Incorrect
The 'valid' signal is '1' only when at least one input bit is set to 1, indicating the output code is meaningful.
🔧 Debug
advanced2:30remaining
Identify the Error in Priority Encoder Code
What error will this VHDL priority encoder code produce when compiled?
VHDL
architecture Behavioral of priority_encoder is begin process(input) begin valid <= '0'; output <= "00"; if input(3) = '1' then output <= "11"; valid <= '1'; elsif input(2) = '1' then output <= "10"; valid <= '1'; elsif input(1) = '1' then output <= "01"; valid <= '1'; elsif input(0) = '1' then output <= "00"; valid <= '1'; end if; end process; end Behavioral;
Attempts:
2 left
💡 Hint
Check the syntax of the if statement endings.
✗ Incorrect
The 'end if' statement is missing a semicolon, which is required in VHDL syntax.
📝 Syntax
advanced1:30remaining
Correct VHDL Signal Declaration for Priority Encoder Output
Which of the following is the correct way to declare the output signal for a 3-bit priority encoder output in VHDL?
Attempts:
2 left
💡 Hint
Remember the output should be 3 bits wide and an output port.
✗ Incorrect
Option B correctly declares a 3-bit output vector from bit 2 down to 0.
🚀 Application
expert3:00remaining
Priority Encoder Output for Multiple Inputs Set
Given a 5-bit input to a priority encoder with bit 4 as highest priority and bit 0 as lowest, what is the output when input = "01101"?
Attempts:
2 left
💡 Hint
Find the highest priority bit set to 1 and output its index in binary.
✗ Incorrect
Input "01101" means bits 3, 2, and 0 are set. Highest priority set bit is bit 3, which is binary "011".