Beruflich Dokumente
Kultur Dokumente
1-1. Model a 4-bit register with synchronous reset and load using the model
provided above. Develop a testbench and simulate the design. Assign Clk
to SW0, D input to SW4-SW1, reset to SW5, load to SW6, and output Q to
LED3-LED0. Verify the design in hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_1_1 is
Port ( clk : in STD_LOGIC;
load : in STD_LOGIC;
reset : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (3 downto 0);
Q : out STD_LOGIC_VECTOR (3 downto 0));
end lab6_1_1;
begin
end Behavioral;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_1_1 IS
END tb_lab6_1_1;
COMPONENT lab6_1_1
PORT(
clk : IN std_logic;
load : IN std_logic;
reset : IN std_logic;
D : IN std_logic_vector(3 downto 0);
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal load : std_logic := '0';
signal reset : std_logic := '0';
signal D : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal Q : std_logic_vector(3 downto 0);
BEGIN
-- Stimulus process
stim_proc: process
begin
clk <= '0'; load <= '0'; reset <= '0'; D <= "0000"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "0000"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1' after 50 ns; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1' after 50 ns; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0' after 50 ns; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; D <= "1001"; wait for 100 ns;
end process;
END;
1-2. Model a 4-bit register with synchronous reset, set, and load signals. Assign
Clk to SW0, D input to SW4-SW1, reset to SW5, set to SW6, load to SW7, and
output Q to LED3-LED0. Verify the design in hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_1_2 is
Port ( clk : in STD_LOGIC;
load : in STD_LOGIC;
reset : in STD_LOGIC;
set : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (3 downto 0);
Q : out STD_LOGIC_VECTOR (3 downto 0));
end lab6_1_2;
begin
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_1_2 IS
END tb_lab6_1_2;
ARCHITECTURE behavior OF tb_lab6_1_2 IS
COMPONENT lab6_1_2
PORT(
clk : IN std_logic;
load : IN std_logic;
reset : IN std_logic;
set : IN std_logic;
D : IN std_logic_vector(3 downto 0);
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal load : std_logic := '0';
signal reset : std_logic := '0';
signal set : std_logic := '0';
signal D : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal Q : std_logic_vector(3 downto 0);
BEGIN
-- Stimulus process
stim_proc: process
begin
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "0000"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "0000"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; set <= '0'; D <= "0101"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1' after 50 ns; set <= '1' after 50 ns; D <=
"1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1' after 50 ns; reset <= '1'; set <= '1'; D <= "1001"; wait for
100 ns;
clk <= '0'; load <= '1'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0' after 50 ns; reset <= '1'; set <= '1'; D <= "1001"; wait for
100 ns;
clk <= '0'; load <= '0'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '1'; set <= '1'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '0'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '0'; load <= '1'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
clk <= '1'; load <= '1'; reset <= '0'; set <= '0'; D <= "1001"; wait for 100 ns;
end process;
END;
1-3. Model a 1-bit delay line shift register using the above code. Develop a
testbench and simulate the design using the stimuli provided below. Assign
Clk to SW0, ShiftIn to SW1, and output ShiftOut to LED0. Verify the design in
hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_1_3 is
Port ( clk : in STD_LOGIC;
shift_in : in STD_LOGIC;
shift_out : out STD_LOGIC);
end lab6_1_3;
begin
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_1_3 IS
END tb_lab6_1_3;
--Inputs
signal clk : std_logic := '0';
signal shift_in : std_logic := '0';
--Outputs
signal shift_out : std_logic;
BEGIN
-- Stimulus process
stim_proc: process
begin
END;
1-4. Model a 4-bit parallel in left shift register using the above code. Develop a
testbench and simulate the design using the stimuli provided below. Assign
Clk to SW0, ParallelIn to SW4-SW1, load to SW5, ShiftEn to SW6, ShiftIn to
SW7, RegContent to LED3-LED0, and ShiftOut to LED7. Verify the design in
hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_1_4 is
Port ( clk : in STD_LOGIC;
load : in STD_LOGIC;
shift_en : in STD_LOGIC;
shift_in : in STD_LOGIC;
parallel_in : in STD_LOGIC_VECTOR (3 downto 0);
shift_out : out STD_LOGIC);
end lab6_1_4;
begin
end process;
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_1_4 IS
END tb_lab6_1_4;
COMPONENT lab6_1_4
PORT(
clk : IN std_logic;
load : IN std_logic;
shift_en : IN std_logic;
shift_in : IN std_logic;
parallel_in : IN std_logic_vector(3 downto 0);
shift_out : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal load : std_logic := '0';
signal shift_en : std_logic := '0';
signal shift_in : std_logic := '0';
signal parallel_in : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal shift_out : std_logic;
BEGIN
-- Stimulus process
stim_proc: process
begin
end process;
END;
2-1. Design a 8-bit counter using T flip-flops, extending the above structure to 8-
bits. Your design needs to be hierarchical, using a T flip-flop in behavioral
modeling, and rest either in dataflow or gate-level modeling. Develop a
testbench and validate the design. Assign Clock input to SW0, Clear_n to
SW1, Enable to SW2, and Q to LED7-LED0. Implement the design and verify
the functionality in hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_2_1 is
Port ( clk : in STD_LOGIC;
En : in STD_LOGIC;
clr : in STD_LOGIC;
Q : inout STD_LOGIC_VECTOR (7 downto 0));
end lab6_2_1;
component T_FlipFlop is
Port ( T : in STD_LOGIC;
En : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
Q : inout STD_LOGIC);
end component;
begin
end Structural;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_2_1 IS
END tb_lab6_2_1;
COMPONENT lab6_2_1
PORT(
clk : IN std_logic;
En : IN std_logic;
clr : IN std_logic;
Q : INOUT std_logic_vector(7 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal En : std_logic := '0';
signal clr : std_logic := '0';
--BiDirs
signal Q : std_logic_vector(7 downto 0);
-- Stimulus process
stim_proc: process
begin
clr <= '0';
En <= '0';
wait for 20 ns;
En <= '1';
clr <= '0';
wait for 20 ns;
En <= '1';
clr <= '1';
wait for 80 ns;
En <= '0';
wait for 80 ns;
En <= '1';
wait for 300 ns;
end process;
END;
2-2. Modify the 8-bit counter using D flip-flops. The design should be hierarchical,
defining D flip-flop in behavioral modeling, creating T flip-flop from the D flip-
flop, implementing additional functionality using dataflow modeling. Assign
Clock input to SW0, Clear_n to SW1, Enable to SW2, and Q to LED7-LED0.
Implement the design and verify the functionality in hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab6_2_2 is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
Q : inout STD_LOGIC_VECTOR (7 downto 0));
end lab6_2_2;
component D_FlipFlop is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
Q : inout STD_LOGIC);
end component;
begin
end Structural;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_2_2 IS
END tb_lab6_2_2;
COMPONENT lab6_2_2
PORT(
D : IN std_logic;
clk : IN std_logic;
clr : IN std_logic;
Q : INOUT std_logic_vector(7 downto 0)
);
END COMPONENT;
--Inputs
signal D : std_logic := '0';
signal clk : std_logic := '0';
signal clr : std_logic := '0';
--BiDirs
signal Q : std_logic_vector(7 downto 0);
BEGIN
-- Stimulus process
stim_proc: process
begin
clr <= '0';
D <= '0';
wait for 20 ns;
D <= '1';
clr <= '0';
wait for 20 ns;
D <= '1';
clr <= '1';
wait for 80 ns;
D <= '0';
wait for 80 ns;
D <= '1';
wait for 300 ns;
end process;
END;
2-3. Model a 4-bit up-counter with synchronous load, enable, and clear as given
in the code above. Develop a testbench (similar to the waveform shown
below) and verify the design works. Assign Clock input to SW0, Clear to
SW1, Enable to SW2, Load to SW3, and Q to LED3-LED0. Implement the
design and verify the functionality in hardware.
Desain
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity lab6_2_3 is
Port ( clk : in STD_LOGIC;
En : in STD_LOGIC;
clr : in STD_LOGIC;
load : in STD_LOGIC;
count : inout STD_LOGIC_VECTOR (3 downto 0);
cnt_done : inout STD_LOGIC;
Q : out STD_LOGIC_VECTOR (3 downto 0));
end lab6_2_3;
begin
end Behavioral;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab6_2_3 IS
END tb_lab6_2_3;
COMPONENT lab6_2_3
PORT(
clk : IN std_logic;
En : IN std_logic;
clr : IN std_logic;
load : IN std_logic;
count : INOUT std_logic_vector(3 downto 0);
cnt_done : INOUT std_logic;
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal En : std_logic := '0';
signal clr : std_logic := '0';
signal load : std_logic := '0';
--BiDirs
signal count : std_logic_vector(3 downto 0);
signal cnt_done : std_logic;
--Outputs
signal Q : std_logic_vector(3 downto 0);
BEGIN
-- Stimulus process
stim_proc: process
begin
En <= '0';
clr <= '0';
load <= '0';
wait for 20 ns;
En <= '1';
wait for 20 ns;
clr <= '1';
wait for 20 ns;
clr <= '0';
wait for 20 ns;
load <= '1';
wait for 10 ns;
load <= '0';
wait for 80 ns;
En <= '0';
wait for 40 ns;
En <= '1';
wait for 80 ns;
end process;
END;