Professional Documents
Culture Documents
Lab 2 Firna
Lab 2 Firna
2-1. Output 4-bit binary input onto one LED (most significant bit) and the right most 7-
segment display (least significant digit) after converting them into two-digit decimal
equivalent (BCD). Use only dataflow modeling.
Structural Model :
Desain :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab2_1 is
Port ( v : in STD_LOGIC_VECTOR (3 downto 0);
z : out STD_LOGIC;
s : out STD_LOGIC_VECTOR (6 downto 0));
end lab2_1;
component comparator
Port ( v : in STD_LOGIC_VECTOR (3 downto 0);
z : out STD_LOGIC );
end component comparator;
component circuitA
Port ( v : in STD_LOGIC_VECTOR (2 downto 0);
a : out STD_LOGIC_VECTOR (2 downto 0) );
end component circuitA;
signal p : std_logic_vector (2 downto 0);
component tugas2_1
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
s : in STD_LOGIC;
m : out STD_LOGIC );
end component tugas2_1;
signal m : std_logic_vector (3 downto 0);
signal q : std_logic;
component tugas5_2
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
an : in STD_LOGIC_VECTOR (3 downto 0);
seg : out STD_LOGIC_VECTOR (6 downto 0));
end component tugas5_2;
begin
z <= q;
komparator : comparator port map (
v => v,
z => q );
end Structural;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab2_1 IS
END tb_lab2_1;
COMPONENT lab2_1
PORT(
v : IN std_logic_vector(3 downto 0);
z : OUT std_logic;
s : OUT std_logic_vector(6 downto 0)
);
END COMPONENT;
--Inputs
signal v : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal z : std_logic;
signal s : std_logic_vector(6 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Stimulus process
stim_proc: process
begin
v <= "0000";
wait for 50 ns;
v <= "0001";
wait for 50 ns;
v <= "0010";
wait for 50 ns;
v <= "0011";
wait for 50 ns;
v <= "0100";
wait for 50 ns;
v <= "0101";
wait for 50 ns;
v <= "0110";
wait for 50 ns;
v <= "0111";
wait for 50 ns;
v <= "1000";
wait for 50 ns;
v <= "1001";
wait for 50 ns;
v <= "1010";
wait for 50 ns;
v <= "1011";
wait for 50 ns;
v <= "1100";
wait for 50 ns;
v <= "1101";
wait for 50 ns;
v <= "1110";
wait for 50 ns;
v <= "1111";
wait for 50 ns;
end process;
END;
Simulasi
2-2. Model a 2-out-of-5 binary code and display a 4-bit binary coded decimal input
number onto five LEDs. Use dataflow modeling.
Dataflow Model
Desain :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab2_2 is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
y : out STD_LOGIC_VECTOR (4 downto 0));
end lab2_2;
begin
y(0) <= ((not x(3)) and x(2) and (not x(1))) or (x(3) and x(2) and x(1));
y(1) <= ((not x(3)) and (not x(2)) and x(1) and x(0)) or ((not x(3)) and x(2) and x(1) and
(not x(0))) or (x(3) and x(2) and (not x(1)) and x(0));
y(2) <= ((not x(3)) and (not x(2)) and x(1) and x(0)) or ((not x(3)) and x(2) and x(1) and
x(0)) or (x(3) and x(2) and (not x(1)) and (not x(0)));
y(3) <= ((not x(3)) and (not x(2)) and (not x(1)) and x(0)) or (x(3) and (not x(2)) and
(not x(1)) and (not x(0))) or (x(3) and (not x(2)) and x(1) and x(0));
y(4) <= ((not x(3)) and (not x(2)) and (not x(1)) and (not x(0))) or (x(3) and (not x(2))
and (not x(1)) and x(0)) or (x(3) and (not x(2)) and x(1) and (not x(0)));
end Dataflow;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab2_2 IS
END tb_lab2_2;
COMPONENT lab2_2
PORT(
x : IN std_logic_vector(3 downto 0);
y : OUT std_logic_vector(4 downto 0)
);
END COMPONENT;
--Inputs
signal x : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal y : std_logic_vector(4 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Stimulus process
stim_proc: process
begin
x <= "0000";
wait for 50 ns;
x <= "0001";
wait for 50 ns;
x <= "0010";
wait for 50 ns;
x <= "0011";
wait for 50 ns;
x <= "0100";
wait for 50 ns;
x <= "0101";
wait for 50 ns;
x <= "0110";
wait for 50 ns;
x <= "0111";
wait for 50 ns;
x <= "1000";
wait for 50 ns;
x <= "1001";
wait for 50 ns;
x <= "1010";
wait for 50 ns;
x <= "1011";
wait for 50 ns;
x <= "1100";
wait for 50 ns;
x <= "1101";
wait for 50 ns;
x <= "1110";
wait for 50 ns;
x <= "1111";
wait for 50 ns;
end process;
END;
Simulasi
3-1. Create a 4-bit ripple carry adder using dataflow modeling.
Structural Model
Desain :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab3_1 is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC);
end lab3_1;
component FullAdder_1bit is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC
);
end component FullAdder_1bit;
begin
end Structural;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab3_1 IS
END tb_lab3_1;
--Inputs
signal a : std_logic_vector(3 downto 0) := (others => '0');
signal b : std_logic_vector(3 downto 0) := (others => '0');
signal cin : std_logic := '0';
--Outputs
signal s : std_logic_vector(3 downto 0);
signal cout : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Stimulus process
stim_proc: process
begin
a <= "0000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "1000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0000";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "1000";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0000";
b <= "0010";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0010";
cin <= '0';
wait for 50 ns;
end process;
END;
Simulasi
3-2. Modify the design of 3-1 by treating the 4-bit input as BCD, performing addition,
generating result in BCD, and displaying it on LED0 and right most 7-segment display.
Use switches to input two 4-bit BCD input and BTNU for carry-in. Reuse models
developed in 2-1 and 3-1 as needed. Use dataflow modeling.
Dataflow Model
Desain :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab3_2 is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
s : inout STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC;
z : out STD_LOGIC;
seg : out STD_LOGIC_VECTOR (6 downto 0));
end lab3_2;
component lab3_1 is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC
);
end component lab3_1;
component lab2_1 is
Port ( v : in STD_LOGIC_VECTOR (3 downto 0);
z : out STD_LOGIC;
s : out STD_LOGIC_VECTOR (6 downto 0)
);
end component lab2_1;
begin
end Structural;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab3_2 IS
END tb_lab3_2;
COMPONENT lab3_2
PORT(
a : IN std_logic_vector(3 downto 0);
b : IN std_logic_vector(3 downto 0);
cin : IN std_logic;
s : INOUT std_logic_vector(3 downto 0);
cout : OUT std_logic;
z : OUT std_logic;
seg : OUT std_logic_vector(6 downto 0)
);
END COMPONENT;
--Inputs
signal a : std_logic_vector(3 downto 0) := (others => '0');
signal b : std_logic_vector(3 downto 0) := (others => '0');
signal cin : std_logic := '0';
--BiDirs
signal s : std_logic_vector(3 downto 0);
--Outputs
signal cout : std_logic;
signal z : std_logic;
signal seg : std_logic_vector(6 downto 0);
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: lab3_2 PORT MAP (
a => a,
b => b,
cin => cin,
s => s,
cout => cout,
z => z,
seg => seg
);
-- Stimulus process
stim_proc: process
begin
a <= "0000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "1000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0000";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "1000";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0000";
b <= "0010";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0010";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0010";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0010";
cin <= '0';
wait for 50 ns;
end process;
END;
Simulasi
4-1. Create a carry-look ahead adder circuit by modifying the project of 3-1 and using dataflow
modeling.
Dataflow Model
Desain :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab4_1 is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC);
end lab4_1;
component FullAdder_1bit is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC
);
end component FullAdder_1bit;
component CarryLookAhead is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
cout : out STD_LOGIC);
end component CarryLookAhead;
begin
end Structural;
Testbench :
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_lab4_1 IS
END tb_lab4_1;
COMPONENT lab4_1
PORT(
a : IN std_logic_vector(3 downto 0);
b : IN std_logic_vector(3 downto 0);
cin : IN std_logic;
s : OUT std_logic_vector(3 downto 0);
cout : OUT std_logic
);
END COMPONENT;
--Inputs
signal a : std_logic_vector(3 downto 0) := (others => '0');
signal b : std_logic_vector(3 downto 0) := (others => '0');
signal cin : std_logic := '0';
--Outputs
signal s : std_logic_vector(3 downto 0);
signal cout : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Stimulus process
stim_proc: process
begin
a <= "0000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0001";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0100";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "1000";
b <= "0000";
cin <= '0';
wait for 50 ns;
a <= "0000";
b <= "0001";
cin <= '0';
wait for 50 ns;
a <= "0010";
b <= "0100";
cin <= '1';
wait for 50 ns;
a <= "0100";
b <= "0100";
cin <= '1';
wait for 50 ns;
a <= "1000";
b <= "0100";
cin <= '1';
wait for 50 ns;
a <= "0000";
b <= "1000";
cin <= '1';
wait for 50 ns;
a <= "0001";
b <= "1000";
cin <= '1';
wait for 50 ns;
a <= "0010";
b <= "1000";
cin <= '1';
wait for 50 ns;
a <= "0100";
b <= "1000";
cin <= '1';
wait for 50 ns;
a <= "1000";
b <= "1000";
cin <= '1';
wait for 50 ns;
a <= "1111";
b <= "1111";
cin <= '1';
wait for 50 ns;
end process;
END;
Simulasi