Documente Academic
Documente Profesional
Documente Cultură
NIM : 165060300111007
LAB 3
3.1 Comparator dan ROM
Program Utama
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comparator is
Port ( A : in STD_LOGIC_VECTOR (1 downto 0);
B : in STD_LOGIC_VECTOR (1 downto 0);
less : out STD_LOGIC;
equal : out STD_LOGIC;
greater : out STD_LOGIC);
end comparator;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ROM_3x2 is
Port(ROM_addr : in STD_LOGIC_VECTOR(2 downto 0);
ROM_data : out STD_LOGIC_VECTOR( 1 downto 0)
);
end ROM_3x2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity compRom is
Port (A : in STD_LOGIC_VECTOR(1 downto 0);
B : in STD_LOGIC_VECTOR(1 downto 0);
O : out STD_LOGIC_VECTOR(1 downto 0));
end compRom;
Testbench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY compRom_tb IS
END compRom_tb;
COMPONENT compRom
PORT(
A : IN std_logic_vector(1 downto 0);
B : IN std_logic_vector(1 downto 0);
O : OUT std_logic_vector(1 downto 0)
);
END COMPONENT;
BEGIN
END;
Hasil Simulasi
Pada program ini dibuat perbandingan antara a dan b, apabila a=b maka
o=10, apabila a>b maka o=11, apabila a<b mama o=01, dan selain
persyaratan tersebut o=00. Dari hasil simulasi menunjukkan program
sudah berhasil melakukan hal tersebut.
end if;
end process;
process (ROM_addr)
begin
case ROM_addr is
when "000" => ROM_data <= MY_ROM(0);
when "001" => ROM_data <= MY_ROM(1);
when "010" => ROM_data <= MY_ROM(2);
when "011" => ROM_data <= MY_ROM(3);
when "100" => ROM_data <= MY_ROM(4);
when "101" => ROM_data <= MY_ROM(5);
when "110" => ROM_data <= MY_ROM(6);
when others =>
end case;
end process;
end Behavioral;
Test Bench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY multiplierRom_tb IS
END multiplierRom_tb;
BEGIN
uut: multiplierRomImplement PORT MAP (
a => a_sig,
b => b_sig,
ROM_data => ROM_data
);
stim_proc: process
begin
wait for 10 ns; a_sig <= "00"; b_sig <= "00";
wait for 10 ns; a_sig <= "01"; b_sig <= "01";
wait for 10 ns; a_sig <= "10"; b_sig <= "11";
wait for 10 ns; a_sig <= "11"; b_sig <= "11";
end process;
END;
Hasil Simulasi
Hasil Implementasi
Hasil
a b
Implementasi pada board FPGA menggunakan sw0 dan sw1 sebagai input a
dan sw2 dan sw3 sebagai input b. Hasil perkalian a dan b ditampilkan
pada LED0 – LED3