Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) VHDL code for 4-2 priority encoder I have already (here): http://imgur.com/1i

ID: 3546275 • Letter: 1

Question

1) VHDL code for 4-2 priority encoder I have already (here): http://imgur.com/1iTh8W5, and http://imgur.com/9dlgG7A

What is the testbench VHDL code? (along with simulation if possible)


2) VHDL code (now for a 2^n to n encoder). Have tried working on this one and can not get it. What is the code (in vhdl) along with the testbench vhdl code (along with simulation if possible).

VHDL code for 4-2 priority encoder What is the testbench VHDL code? VHDL code (now for a 2^n to n encoder). Have tried working on this one and cannot get it. What is the code (in vhdl) along with the testbench vhdl code (along with simulation

Explanation / Answer

1) VHDL code for 4 to 2 Priority Encoder:


library ieee;

use ieee.std_logic_1164.all;

entity pri_encod42 is

port(a:in std_logic_vector(3 downto 0);

y:out std_logic_vector(1 downto 0);

valid:out std_logic);

end pri_encod42;


architecture pri_encod42_beh of pri_encod42 is

begin

process(a)

begin

if(a(3)='1')then

y<="11";

valid<='1';

elsif (a(2)='1')then

y<="10";

valid<='1';

elsif (a(1)='1')then

y<="01";

valid<='1';

elsif (a(0)='1')then

y<="00";

valid<='1';

else

y<="XX";

valid<='0';

end if;

end process:

end pri_encod42_beh;



VHDL Test Bench:



library ieee;

use ieee.std_logic_1164.all;

entity pri_encod42_tst is

end pri_encod42_tst;


architecture pri_encod42_tst_a of pri_encod42 is

component pri_encode42

port(a:in std_logic_vector(3 downto 0);

y:out std_logic_vector(1 downto 0);

);

end component;

signal a:std_logic_vector(3 downto 0);

signal y:std_logic_vector(3 downto 0);

begin

a<="0000";

wait for 100ns;

a<="0001";

wait for 100ns;

a<="0010";

wait for 100ns;

a<="0011";

wait for 100ns;

a<="0100";

wait for 100ns;

a<="0101";

wait for 100ns;

a<="0110";

wait for 100ns;

a<="0111";

wait for 100ns;

a<="1000";

wait for 100ns;

a<="1001";

wait for 100ns;

a<="1010";

wait for 100ns;

a<="1011";

wait for 100ns;

a<="1100";

wait for 100ns;

a<="1101";

wait for 100ns;

a<="1110";

wait for 100ns;

a<="1111";

wait for 100ns;

end process;

end pri_encod42_tst_a;


2) for general encoder we take input vector 2^n-1 down to 0 and we take output vector n-1 down to 0..

by taking these values we can develop..