WRITE VHDL PROGRAM FOR 8 TO 3 ENCODER WITHOUT PRIORITY

An encoder is a digital circuit which performs the inverse of decoder.An encoder has 2^N input lines and N output lines.In encoder the output lines genrate the binary code corresponding to input value.The decimal to bcd encoder usually has 10 input lines and 4 ouput lines.The decoder decimal data as an input for decoder an encoded bcd ouput is available at 4 output lines.

 

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

 

entity Encoder8_3 is

port ( ENABLE :  in STD_LOGIC;

D_IN: in STD_LOGIC_VECTOR(7 downto 0);

D_OUT: out STD_LOGIC_VECTOR(2 downto 0) );

end Encoder8_3;

architecture encoder_arch of encoder8_3 is

begin

process(ENABLE,D_IN)

begin

if ( ENABLE = '1') then

D_OUT <= "000";

Else

case D_IN is

when "00000001" => D_OUT <= "000";

when "00000010" => D_OUT <= "001";

when "00000100" => D_OUT <= "010";

when "00001000" => D_OUT <= "011";

when "00010000" => D_OUT <= "100";

when "00100000" => D_OUT <= "101";

when "01000000" => D_OUT <= "110";

when “10000000” => D_OUT <= "111";

when OTHERS => NULL";

end case;

end if;

end process;

end encoder_arch;