1-to-4 Demultiplexer (if-else statement)
The demultiplexer is a combinational logic circuit designed to switch one input line to one of several separate output lines. It is exactly opposite of Multiplexer.
In 1-to-4 Demux the input line is connected to one of the 4 output lines depending on the select line input. The below VHDL code is written using if-else statement.
VHDL Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity demux14 is
Port ( Din : in STD_LOGIC;
Sel : in STD_LOGIC_VECTOR (1 downto 0);
dout : out STD_LOGIC_VECTOR (3 downto 0));
end demux14;
architecture Behavioral of demux14 is
begin
process(din,sel)
begin
if(sel="00") then
dout <= "000"&din;
elsif(sel="01") then
dout <= "00"&din&'0';
elsif(sel="10") then
dout <= '0'&din&"00";
else
dout <= din&"000";
end if;
end process;
end Behavioral;
Testbench:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY demux14_tb IS
END demux14_tb;
ARCHITECTURE behavior OF demux14_tb IS
COMPONENT demux14
PORT(
Din : IN std_logic;
Sel : IN std_logic_vector(1 downto 0);
dout : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal Din : std_logic := '0';
signal Sel : std_logic_vector(1 downto 0) := (others => '0');
--Outputs
signal dout : std_logic_vector(3 downto 0);
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: demux14 PORT MAP (
Din => Din,
Sel => Sel,
dout => dout
);
-- Stimulus process
stim_proc: process(din,sel)
begin
din <= '1';
sel(1) <= not sel(1) after 40 ns;
sel(0) <= not sel(0) after 20 ns;
end process;
END;
Output:
The above code is tested on Xilinx ISE Design Suite 14.7 Webpack.
It is intended only for educational purpose.
Comments
Post a Comment