0% found this document useful (0 votes)
244 views17 pages

Bài Thí Nghiệm 2 I. Thí nghiệm 2.1 - Thiết kế bộ cộng hai số 4 bit. 1. Yêu cầu: Thiết kế bộ ALU (Arithmetic and Logic Unit) thực hiện 1. Thiết kế: a) Sơ đồ khối (Block Diagram) - b) VHDL Code

The document describes the design of an ALU (Arithmetic and Logic Unit) circuit using VHDL that performs basic arithmetic and logic functions on 4-bit inputs. It includes the VHDL code for the design and describes the steps taken to synthesize, simulate and implement the design on an FPGA development board, including generating test waveforms, compiling the code, and downloading the design to the board to test it. The design is successfully synthesized, simulated, and implemented on the target board as intended.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views17 pages

Bài Thí Nghiệm 2 I. Thí nghiệm 2.1 - Thiết kế bộ cộng hai số 4 bit. 1. Yêu cầu: Thiết kế bộ ALU (Arithmetic and Logic Unit) thực hiện 1. Thiết kế: a) Sơ đồ khối (Block Diagram) - b) VHDL Code

The document describes the design of an ALU (Arithmetic and Logic Unit) circuit using VHDL that performs basic arithmetic and logic functions on 4-bit inputs. It includes the VHDL code for the design and describes the steps taken to synthesize, simulate and implement the design on an FPGA development board, including generating test waveforms, compiling the code, and downloading the design to the board to test it. The design is successfully synthesized, simulated, and implemented on the target board as intended.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

BÀI THÍ NGHIỆM 2

I. Thí nghiệm 2.1 – Thiết kế bộ cộng hai số 4 bit.


1. Yêu cầu: Thiết kế bộ ALU (Arithmetic and Logic Unit) thực hiện
8 hàm tính toán số học và logic đơn giản.
1. Thiết kế:
a) Sơ đồ khối (Block Diagram).
b) VHDL Code.
Library ieee;
Use ieee.std_logic_1164.all;
Entity seg7 is
Port ( bcd: in std_logic_vector(3 downto 0);
leds: out std_logic_vector(1 to 7));
End seg7;
Architecture behavior of seg7 is
Begin
Process(bcd)
Begin
Case bcd is
When "0000" => leds <= "1111110";
When "0001" => leds <= "0110000";
When "0010" => leds <= "1101101";
When "0011" => leds <= "1111110";
When "0100" => leds <= "0110011";
When "0101" => leds <= "1011011";
When "0110" => leds <= "1011110";
When "0111" => leds <= "1110000";
When "1000" => leds <= "1111111";
When "1001" => leds <= "1111011";
When others => leds <= "0101010";
End case;
End process;
End behavior;

Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;

Entity ld is
port( x: in std_logic_vector(2 downto 0);
y: out std_logic_vector(2 downto 0));
End entity;

Architecture behavior of ld is
Begin
y(2 downto 0)<= x(2 downto 0);
End architecture;
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;

Entity ld1 is
Port( x: in std_logic;
y: out std_logic);
End entity;

Architecture behavior of ld1 is


Begin
y<= x;
End architecture;

Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;

Entity t3 is
Port( control: in std_logic_vector(2 downto 0);
cin: in std_logic;
a,b: in std_logic_vector(3 downto 0);
alu_out: inout std_logic_vector(3 downto 0);
cout: inout std_logic;
leda, ledb, ledc : out std_logic_vector(1 to 7));
End t3;

Architecture beha1 of t3 is
Component seg7
Port ( bcd: in std_logic_vector(3 downto 0);
leds : out std_logic_vector(1 to 7));
End component;
Component ld
Port( x: in std_logic_vector(2 downto 0);
y: out std_logic_vector(2 downto 0));
End component;
Component ld1
Port( x: in std_logic;
y: out std_logic);
End component;
Begin
Process(control, cin, a, b)
Begin
Case control is
When "000" => alu_out <= a + b + cin;
When "001" => alu_out <= a - b - cin;
When "010" => alu_out <= a or b;
When "011" => alu_out <= a and b;
When "100" => alu_out <= a(2 downto 0) & '0';
When "101" => alu_out <= '0' & a(3 downto 1);
When "110" => alu_out <= a(2 downto 0) & a(3);
When "111" => alu_out <= a(0) & a(3 downto 1);
When others => alu_out <= "1111";
End case;
End process;
u1: ld port map ( x(2 downto 0)=> control(2 downto 0));
u2: ld1 port map ( x => cin);
u3: seg7 port map ( bcd(3 downto 0) => a(3 downto 0), leds => leda(1 to 7));
u4: seg7 port map ( bcd(3 downto 0) => b(3 downto 0), leds => ledb(1 to 7));
u5: seg7 port map ( bcd(3 downto 0) => alu_out(3 downto 0), leds => ledc(1 to
7));
u6: ld1 port map ( x => cout);
End beha1;
c) Các bước thực hiện.

- Step 1: Bắt đầu quá trình tạo project, đặt tên cho project và thiết lập đường
dẫn đến thư mục làm việc của project.
Hình 1: Nhấn Next để tiếp tục sau khi thiết lập đường dẫn và tên dự án

- Step 2: Trong bước này có thể add them các file thiết kế trước đó nếu muốn,
Nhấn next để tiếp tục quá trình. Chọn device cho project muốn thiết kế,
trong phần Family chọn “Cyclone II” và trong phần Available device tìm
và chọn “EP2C35F672C6” nhấn Next để tiếp tục quá trình. Sau đó nhấn
Finish để hoàn thành quá trình.

- Step 3: Tạo file thiết kế cho project. Trong phần Design chọn VHDL File
nhấn OK để hoàn thành quá trình tạo file. Viết Code chương trình cho thiết
kế bằng ngôn ngữ VHDL. Sauk hi hoàn thành thiết kế save as để lưu file
(Tên của file thiết kế phải trùng với tên của project và file thiết kế phải cùng
chung thư mục với project).
Hình 2: Code VHDL

- Step 4: Tiến hành gán Pin cho thiết kế bằng cách import Assignments. Một
giao diện gán pin xuất hiện, chọn file gán “03_DE2_pin_assignments” đi
kèm với bộ tài liệu. Trên thanh công cụ Assignment chọn Assignment
Editor, giao diện edit assignment xuất hiện.
Hình 3: giao diện edit Assignment pin

- Step 5: Tiến hành biên dịch chương trình bằng nút Start Compilation, quá
trình biên dịch sẽ được tiến hành như Hình 4, sau khi biên dịch thành công
chương trình sẽ thông báo trong đó chỉ có Warning và Info messages.

Hình 4: Tiến hành biên dịch chương trình thành công


- Step 6: Sau khi biên dịch xong người đọc có thể xem chi thiết kế ở mức
cổng bằng cách sử dụng công cụ “Tools/Netlist Viewers/RTL Viewer”.

Hình 5: Xem thiết kế ở mức cổng


d) Thực hiện mô phỏng.

- Step 1: Tạo file waveform và tiến hành insert tín hiệu vào file waveform.
Trên thanh công cụ chọn Edit/Insert/Insert Node or Bus… Trên giao diện
này chọn Node Finder, trong giao diện này ở trường Filter chọn Pins:
assigned và click chuột vào List để chương trình liệt kê các pin được gán
trong thiết kế, chọn tín hiệu muốn add vào, tiếp theo nhấn OK.
Hình 6: Chọn tín hiệu cần mô phỏng bằng cách đưa các tín hiệu được
liệt kê ở cửa sổ bên trái qua bên phải bằng cách nhấn biểu tượng (>)

- Step 2:Vẽ dạng sóng cho tín hiệu đầu vào. Sauk hi vẽ dạng sóng các tín hiệu
đầu vào cho quá trình mô phỏng hoàn thành lưu file lại cùng chung thư mục
với file project.
Hình 7: Giao diện sóng với tín hiệu ngõ vào SW

- Step 3: Thiết lập thời gian chạy mô phỏng, trên thanh menu chọn Edit/End
Time, sau đó nhập thời gian chạy mô phỏng rồi nhấn OK. Trên thanh menu
chọn Processing/Generate Functional Simulation Netlist để tạo Netlist
function cho quá trình mô phỏng, sau đó click chuột vào nút Start
Simulation để bắt đầu chạy mô phỏng.

Hình 8: Kết quả quá trình chạy mô phỏng

e) Kết quả mô phỏng trên kit DE2.


Sau khi biên dịch hoàn tất người dùng có thể nạp lên kit thông qua công cụ
Tools/Programmer.
- Kiểm tra chính xác họ FPGA trên kit đang dùng.
- Mục HardwareSetup cần kiểm tra lại đã nhận Driver chưa. Nếu chưa sẽ hiện
No Hardware, còn nếu nhận sẽ hiện USB-Blaster.
- Sau khi nhận USB, nhấn Start để bắt đầu nạp file lên kit và kiểm tra.

Hình 9: Chương trình được nạp xuống thành công

- Kết quả được khảo sát thông qua hình 10. Khi ….
Hình 10:

You might also like