0
0
VHDLprogramming~20 mins

Priority encoder in VHDL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Priority Encoder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
Aoutput = "11", valid = '1'
Boutput = "10", valid = '1'
Coutput = "01", valid = '1'
Doutput = "00", valid = '1'
Attempts:
2 left
💡 Hint
Remember the priority encoder outputs the highest priority bit set to 1.
🧠 Conceptual
intermediate
1:30remaining
Understanding Priority Encoder Valid Signal
In a priority encoder, what does the 'valid' output signal indicate?
AIt resets the encoder output.
BIt shows the highest priority input bit index.
CIt indicates if any input bit is set to 1.
DIt enables the input signals.
Attempts:
2 left
💡 Hint
Think about when the encoder should output a valid code.
🔧 Debug
advanced
2: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;
ATypeError: Mismatched signal types
BRuntimeError: Signal assignment conflict
CNo error, code compiles successfully
DSyntaxError: Missing semicolon after 'end if'
Attempts:
2 left
💡 Hint
Check the syntax of the if statement endings.
📝 Syntax
advanced
1: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?
Aoutput : out STD_LOGIC_VECTOR(0 to 2);
Boutput : out STD_LOGIC_VECTOR(2 downto 0);
Coutput : out STD_LOGIC_VECTOR(3 downto 0);
Doutput : in STD_LOGIC_VECTOR(3 downto 1);
Attempts:
2 left
💡 Hint
Remember the output should be 3 bits wide and an output port.
🚀 Application
expert
3: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"?
AOutput = "011", valid = '1'
BOutput = "010", valid = '1'
COutput = "100", valid = '1'
DOutput = "101", valid = '1'
Attempts:
2 left
💡 Hint
Find the highest priority bit set to 1 and output its index in binary.