Saturday, 20 July 2013

Design of 4 to 2 Encoder using IF- ELSE Statements (VHDL Code).





Design of 4 to 2 Encoder using IF-ELSE Statements (Behavior Modeling Style).


Output Waveform :   4 to 2 Encoder



VHDL Code -


-------------------------------------------------------------------------------
--
-- Title       : encoder4_2
-- Design      : vhdl_upload 1
-- Author      : Naresh Singh Dobal
-- Company     : nsdobal@gmail.com
-- VHDL Tutorials & exercise by Naresh Singh Dobal
-------------------------------------------------------------------------------
--
-- File        : 4 to 2 Encoder using if else.vhd

   

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity encoder4_2 is
     port(
         din : in STD_LOGIC_VECTOR(3 downto 0);
         dout : out STD_LOGIC_VECTOR(1 downto 0)
         );
end encoder4_2;

architecture encoder4_2_arc of encoder4_2 is
begin

    encoder : process (din) is
    begin
        if (din="1000") then
            dout <= "00";
        elsif (din="0100") then
            dout <= "01";
        elsif (din="0010") then
            dout <= "10";
        elsif (din="0001") then
            dout <= "11";
        else
            dout <= "ZZ";
        end if;
    end process encoder;

end encoder4_2_arc;

2 comments :

Anonymous said...

Thanx for the programs sir..these are really helpful! Can you plz guide me as to where and when do we use "zz", "u" , "x" etc..
Also, in the architecture for s-r flip flop,which one would be suitable for the toggle case ?
Plz reply asap... thnx !

Anonymous said...

:P

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes