Professional Documents
Culture Documents
Kalkulator
Kalkulator
Modul 4
MODUL 4
Kalkulator 4-bit
I. Pendahuluan
Pada praktikum ini, anda akan mempelajari cara mendisain beberapa sub-disain dari sebuah sistem besar stopwatch menggunakan VHDL. Sub-disain yang dibuat ada empat macam yaitu bagian sinkronisasi input untuk menghilangkan efek bouncing karena menggunakan saklar mekanik sebagai masukan, bagian pemilih mode kalkulasi untuk memilih satu dari sepuluh macam mode kalkulasi, bagian kalkulator sebagai inti dari sistem untuk melakukan perhitungan, dan bagian untuk menampilkan nilai hasil perhitungan ke seven segmen. Sistem stopwatch ini direalisasikan pada IC FPGA.
II. Tujuan
Setelah menyelesaikan praktikum ini, yang anda peroleh adalah : lebih memahami cara menggunakan software ISE WebPack untuk membuat disain pada IC FPGA dan menggunakan software untuk melakukan download. dapat membuat disain untuk sinkonisasi input dan menghilangkan efek bouncing dengan VHDL. dapat membuat counter dan latch dengan VHDL. dapat memanfaatkan fungsi matematik dan fungsi logika dengan VHDL. dapat membuat disain kalkulator 4-bit sederhana.
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
Nomor Mode 1 2 3 4 5 6 7 8 9 10
Mode kalkulasi dipilih dengan cara menekan sebuah push-button. Mode yang dipilih akan ditampilkan pada led. Bilangan A dan B masing-masing selebar 4-bit yang akan dimasukkan menggunakan DIP-switch. Apabila push-button lainnya ditekan, yang berfungsi sebagai tombol enter, maka hasil kalkulasi akan ditampilkan pada dua buah seven segmen dalam format heksadesimal. Referensi: - http://www.xess.com
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
V. Peralatan
1 set PC yang dilengkapi dengan software ISE WebPack dan ModelSim. 1 development board XSA-50 dan XSTend Board 1 power-supply +9VDC
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
Berikut panduan untuk membuat kode VHDLnya. Blok sinkronisasi input Semua blok didisain secara sinkron menggunakan sebuah sinyal clock yang sama, penekanan tombol push-button akan disinkronkan terhadap clock. Clock yang digunakan (default) mempunyai frekuensi 50MHz atau 20ndetik sedangkan penekanan tombol push-button dapat menghasilkan pulsa yang lebih lebar sekitar beberapa milidetik. Ilustrasinya diperlihatkan oleh gambar 3. Blok tersebut bertugas menghasilkan satu pulsa selebar satu periode clock.
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity debouncing is port( clk : in std_logic; enter, mode : in std_logic; enter_db, mode_db : out std_logic );
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
end debouncing; architecture Behavioral of debouncing is signal A,B : std_logic_vector(2 downto 0) := "000"; begin process(clk,enter) begin if (clk'event and clk='1') then A <= A(1 downto 0) & enter; -- shift left end if; end process; process(clk,mode) begin if (clk'event and clk='1') then B <= B(1 downto 0) & mode; -- shift left end if; end process; enter_db <= not(A(2)) and A(1) and A(0); mode_db <= not(B(2)) and B(1) and B(0); end Behavioral;
Blok pemilih mode kalkulasi Bagian ini bertugas untuk menghasilkan hitungan dari 0 sampai 9. Hasil hitungan tersebut digunakan untuk menentukan mode pilihan kalkulasi seperti pada tabel 1. Mode pilihan kalkulasi ini ditampilkan pada 10-buah led yang terdapat pada board.
: : : :
architecture Behavioral of pilih_mode is signal count : std_logic_vector(3 downto 0) := "0000"; begin process(clk,mode_db) begin if (clk'event and clk='1') then if (mode_db='1') then if (count >= "1001") then count <= "0000"; else
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
count <= count + "0001"; end if; end if; end if; end process; -- keluarkan pilihan <= count; -- tampilkan barled <= "0000000001" when (count="0000") else "0000000010" when (count="0001") else "0000000100" when (count="0010") else "0000001000" when (count="0011") else "0000010000" when (count="0100") else "0000100000" when (count="0101") else "0001000000" when (count="0110") else "0010000000" when (count="0111") else "0100000000" when (count="1000") else "1000000000" when (count="1001") else "0000000000"; end Behavioral;
Blok kalkulator Bagian ini adalah inti dari kalkulator 4-bit. Blok ini mendapat masukan dua buah bilangan A dan B masing-masing selebar 4-bit yang didapat dari DIP-switch pada board. Penekanan enter_ (sinyal ini didapat dari keluaran blok sinkronisasi input) akan menghasilkan keluaran hasil selebar 8-bit sesuai dengan sinyal pilihan yang didapat dari blok pemilih mode kalkulasi.
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity kalkulator is port( clk : in std_logic; enter_db : in std_logic; bilA : in std_logic_vector(3 bilB : in std_logic_vector(3 pilihan : in std_logic_vector(3 hasil : out std_logic_vector(7 downto ); end kalkulator;
architecture Behavioral of kalkulator is signal temp : std_logic_vector(7 downto 0) := "00000000"; begin process(clk,enter_db,bilA,bilB,pilihan) begin if (clk'event and clk='1') then
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
if (enter_db='1') then case pilihan is when "0000" => -- (+) temp <= ("0000"&bilA) + ("0000"&bilB); when "0001" => -- (-) temp <= ("0000"&bilA) - ("0000"&bilB); when "0010" => -- (*) temp <= bilA * bilB; when "0011" => temp <= not("0000"&bilA); when "0100" => temp <= not("0000"&bilB); when "0101" => temp <= ("0000"&bilA) AND ("0000"&bilB); when "0110" => temp <= ("0000"&bilA) OR ("0000"&bilB); when "0111" => temp <= ("0000"&bilA) XOR ("0000"&bilB); when "1000" => temp <= SHL(("0000"&bilA),("0000"&bilB)); when "1001" => temp <= SHR(("0000"&bilA),("0000"&bilB)); when others => temp <= "00000000"; end case; end if; end if; end process; hasil <= temp; end Behavioral;
Blok tampilan ke seven segmen Bagian ini akan menampilkan hasil keluaran dari blok kalkulasi selebar 8-bit pada dua buah seven segmen dalam format heksadesimal.
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
"01001111" "01100110" "01101101" "01111101" "00000111" "01111111" "01101111" "01110111" "01111100" "00111001" "01011110" "01111001" "01110001" "00111111" ledtwo <= "00000110" "01011011" "01001111" "01100110" "01101101" "01111101" "00000111" "01111111" "01101111" "01110111" "01111100" "00111001" "01011110" "01111001" "01110001" "00111111" end Behavioral;
when when when when when when when when when when when when when when when when when when when when when when when when when when when when when when
(LSB="0011") else (LSB="0100") else (LSB="0101") else (LSB="0110") else (LSB="0111") else (LSB="1000") else (LSB="1001") else (LSB="1010") else (LSB="1011") else (LSB="1100") else (LSB="1101") else (LSB="1110") else (LSB="1111") else (LSB="0000"); (MSB="0001") else (MSB="0010") else (MSB="0011") else (MSB="0100") else (MSB="0101") else (MSB="0110") else (MSB="0111") else (MSB="1000") else (MSB="1001") else (MSB="1010") else (MSB="1011") else (MSB="1100") else (MSB="1101") else (MSB="1110") else (MSB="1111") else (MSB="0000");
--3 --4 --5 --6 --7 --8 --9 --A --b --C --d --E --F --0 --1 --2 --3 --4 --5 --6 --7 --8 --9 --A --b --C --d --E --F --0
File ucf untuk mendefinisikan pin-pin IC Nomor-nomor pin yang dipakai untuk seven segmen, barled, push-button dan dip-switch.
net clk loc=p88; #net pushsw3 loc=p78; # pushbuttons net mode loc=p26; net enter loc=p23; net net net net net net net net net net net net net net net net net net net net net net net net ledtwo<0> ledtwo<1> ledtwo<2> ledtwo<3> ledtwo<4> ledtwo<5> ledtwo<6> ledtwo<7> ledone<0> ledone<1> ledone<2> ledone<3> ledone<4> ledone<5> ledone<6> ledone<7> barled<1> barled<2> barled<3> barled<4> barled<5> barled<6> barled<7> barled<8> loc=p48; loc=p27; loc=p40; loc=p47; loc=p28; loc=p42; loc=p29; loc=p38; loc=p56; loc=p51; loc=p65; loc=p64; loc=p76; loc=p54; loc=p50; loc=p63; # 7-segment LED # 76543210 # .gfedcba
# 7-segment LED
loc=p68; # bargraph LED loc=p44; loc=p46; loc=p49; loc=p57; loc=p62; loc=p60; loc=p67;
hary@eepis-its.edu, hendri@eepis-its.edu
Modul 4
net barled<9> loc=p39; net barled<10> loc=p59; net net net net net net net net A<3> A<2> A<1> A<0> B<3> B<2> B<1> B<0> loc=p30; # DIP switches loc=p58; loc=p74; loc=p75; loc=p66; loc=p77; loc=p80; loc=p79;
IX. Tambahan
Berikan saran atau komentar guna pengembangan lebih lanjut praktikum ini.
hary@eepis-its.edu, hendri@eepis-its.edu