Lab - VHDL Multiplexer With A Clock
Lab - VHDL Multiplexer With A Clock
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mplex is
port(
a,b,c,d: in std_logic;
s: in std_logic_vector (1 downto 0);
f: out std_logic;
Clock: in std_logic);
end mplex;
--four data ports and 2bit address vector
begin
process (Clock) is
begin
--addressing is active only when the rising edge is detected otherwise no action
if (rising_edge(Clock)) then
--choosing data from the required input based on address
case s is
when "00" => f <= a;
when "01" => f <= b;
when "10" => f <= c;
when others => f <= d;
end case;
end if;
end process;
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY muxtb IS
END muxtb;
COMPONENT mplex
PORT(
a : IN std_logic;
b : IN std_logic;
c : IN std_logic;
d : IN std_logic;
s : IN std_logic_vector(1 downto 0);
f : OUT std_logic;
Clock : IN std_logic
--clock belongs to standard logic it exhibits transitions between 0 and 1
);
END COMPONENT;
--Inputs
signal a : std_logic := '0';
signal b : std_logic := '0';
signal c : std_logic := '0';
signal d : std_logic := '0';
signal s : std_logic_vector(1 downto 0) := (others => '0');
signal Clock : std_logic := '0';
--initial values are assigned
--Outputs
signal f : std_logic;
BEGIN
end process;
-- Stimulus process
stim_proc: process
begin
wait for 3 ns;
--I don't want the clock and data change at the same time, I delay by 3 ns
s <= "00";
a<='1';
b<='0';
c<='0';
d<='0';
--checking if data is taken from input a
wait for 10 ns;
a<='0';
--checking again if data is taken from input a
wait for 10 ns;
a<='1';
s<="01";
wait for 10 ns;
b<='0';
--checking if output data is updated based on b
wait for 10 ns;
b<='1';
--checking if output data is updated based on b
s<="10";
wait for 10 ns;
c<='0';
wait for 10 ns;
c<='1';
s<="11";
wait for 10 ns;
d<='0';
wait for 10 ns;
d<='1';
wait for 10 ns;
a<='0';
b<='0';
c<='0';
d<='0';
END;