Search This Blog

Monday, July 29, 2013

Design of 8 : 3 Priority Encoder using if - else statements - Method 1 (VHDL Code).





Design of 8 : 3 Priority Encoder using IF-ELSE Statements -


Output Waveform : 8 : 3 Priority Encoder



Output Waveform : 8 to 3 Priority Encoder



VHDL Code -



-------------------------------------------------------------------------------
--
-- Title       : priority_encoder_8_3
-- Design      : vhdl_upload2
-- Author      : Naresh Singh Dobal
-- Company     : nsdobal@gmail.com
-- Verilog HDL Programs &  Exercise with Naresh Singh Dobal.
--
-------------------------------------------------------------------------------
--
-- File        : Design of Priority Encoder using if else statements.vhd

   

library IEEE;
use IEEE.STD_LOGIC_1164.all;     
use ieee.numeric_std.all;

entity priority_encoder_8_3 is
     port(
         din : in STD_LOGIC_VECTOR(7 downto 0);
         dout : out STD_LOGIC_VECTOR(2 downto 0)
         );
end priority_encoder_8_3;


architecture priority_enc_arc of priority_encoder_8_3 is
begin

    pri_enc : process (din) is
    begin
        if (din(7)='1') then
            dout <= "000";
        elsif (din(6)='1') then
            dout <= "001";
        elsif (din(5)='1') then
            dout <= "010";
        elsif (din(4)='1') then
            dout <= "011";
        elsif (din(3)='1') then
            dout <= "100";
        elsif (din(2)='1') then
            dout <= "101";
        elsif (din(1)='1') then
            dout <= "110";
        elsif (din(0)='1') then
            dout <= "111";
        end if;
    end process pri_enc;
   

end priority_enc_arc;

8 comments:

  1. what happens if the input is suppose 00000011 then the output should be 001 but it is coming out 000 instead

    ReplyDelete
  2. it's returning 000 because:
    0 - LSB ( in entity use "downto")
    0 -
    0 -
    0 -
    0 -
    0 -
    0 -
    1 -
    1 - MSB (same as LSB)

    that way, the priority is given by the order of significant bytes. In this case, MSB is set to 1 then, no matter what, the output will be 000.

    ReplyDelete
  3. Could you please send me the Truth Table

    ReplyDelete
  4. din (7 downto 0) means din(7) is msb.
    in case of din=10000000 output should be 111.
    but here u have writen 000
    plz help????

    ReplyDelete
  5. you have given wrong priority bro!!!

    ReplyDelete
  6. Why using pri_enc:process statements

    ReplyDelete
  7. i think u had revere the priority

    ReplyDelete