Tuesday, June 8, 2010

Combinational Circuit design

What is the difference between encoder and multiplexer? Write VHDL code for both ?


An encoder is a device used to change a signal (such as a bitstream)
or data into a code.Encoders work in exactly the opposite way as decoders,
taking 2N inputs, and having N outputs. When a bit comes in on an input
wire, the encoder outputs the physical address of that wire.

A multiplexer combines multiple inputs into one output.
It selects the input, depending on the inputs at
select lines and sends the selected input to the output.
e.g. 4:1 , 2:1 multiplexor.

--------Multiplexer ----------------------------

library ieee;
use ieee.std_logic_1164.all;

entity Mux is
port( I3: in std_logic_vector(2 downto 0);
I2: in std_logic_vector(2 downto 0);
I1: in std_logic_vector(2 downto 0);
I0: in std_logic_vector(2 downto 0);
S: in std_logic_vector(1 downto 0);
O: out std_logic_vector(2 downto 0)
);
end Mux;

architecture behv1 of Mux is
begin
process(I3,I2,I1,I0,S)
begin

-- use case statement
case S is
when "00" => O <= I0; when "01" => O <= I1; when "10" => O <= I2; when "11" => O <= I3; when others => O <= "ZZZ"; end case; end process; end behv1; architecture behv2 of Mux is begin O <= I0 when S="00" else I1 when S="01" else I2 when S="10" else I3 when S="11" else "ZZZ"; end behv2;



What is the difference between decoder and demultiplexer ? Write VHDL code for both ?

library ieee;
use ieee.std_logic_1164.all;

-------------------------------------------------

entity DECODER is
port( I: in std_logic_vector(1 downto 0);
O: out std_logic_vector(3 downto 0)
);
end DECODER;

architecture behv of DECODER is
begin

-- process statement

process (I)
begin

-- use case statement

case I is
when "00" => O <= "0001"; when "01" => O <= "0010"; when "10" => O <= "0100"; when "11" => O <= "1000"; when others => O <= "XXXX"; end case;
end process;
end behv;
architecture when_else of DECODER is begin
-- use when..else statement O <= "0001" when I = "00" else "0010" when I = "01" else "0100" when I = "10" else "1000" when I = "11" else "XXXX"; end when_else;


No comments:

Post a Comment