0% found this document useful (0 votes)
34 views2 pages

Encoder

The document contains VHDL code for a 4:2 encoder implemented in three different models: a dataflow model, a behavioral model using a case statement, and a behavioral model using an if-else statement. Each model defines an entity 'encoder' with a 4-bit input and a 2-bit output. The output is determined based on the input vector, encoding the highest active input line into binary form.

Uploaded by

anktech201
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Encoder

The document contains VHDL code for a 4:2 encoder implemented in three different models: a dataflow model, a behavioral model using a case statement, and a behavioral model using an if-else statement. Each model defines an entity 'encoder' with a 4-bit input and a 2-bit output. The output is determined based on the input vector, encoding the highest active input line into binary form.

Uploaded by

anktech201
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VHDL code for 4:2 Encoder Dataflow model

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity encoder2 is
port(
a : in STD_LOGIC_VECTOR(3 downto 0);
b : out STD_LOGIC_VECTOR(1 downto 0)
);
end encoder2;

architecture bhv of encoder2 is


begin

b(0) <= a(1) or a(2);


b(1) <= a(1) or a(3);

end bhv;

VHDL code for 4: 2 Encoder Behavioural Model

Library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity encoder is
port(
a : in STD_LOGIC_VECTOR(3 downto 0);
b : out STD_LOGIC_VECTOR(1 downto 0)
);
end encoder;

architecture bhv of encoder is


begin

process(a)
begin
case a is
when "1000" => b <= "00"; when "0100" => b <= "01"; when "0010" => b <= "10";
when "0001" => b <= "11"; when others => b <= "ZZ";
end case;
end process;

end bhv;
VHDL code for 4: 2 Encoder using If-else statement

library IEEE;

use IEEE.STD_LOGIC_1164.all;

entity encoder1 is
port(
a : in STD_LOGIC_VECTOR(3 downto 0);
b : out STD_LOGIC_VECTOR(1 downto 0)
);
end encoder1;

architecture bhv of encoder1 is


begin

process(a)
begin
if (a="1000") then
b <= "00";
elsif (a="0100") then
b <= "01";
elsif (a="0010") then
b <= "10";
elsif (a="0001") then
b <= "11";
else
b <= "ZZ";
end if;
end process;

end bhv;

You might also like