You are on page 1of 15

國立高雄科技大學

電子工程系(第一校區)

硬體描述語言
Lab. 2

指導教授:陳銘志
班 級:電子二甲
學生姓名:蔡孟哲
學 號:C110112150

本週起恢復繳交 PDF 檔,檔名 : 姓名_Labx_version。

version 從第二版之後加上 EX: 第二版 _v2


Lab. 2: 4-bit Ripple Carry Adder
題目說明 : 請在 ISE14.7 使用 gate-level 語法完成以下兩題

1 在 1-bit Full Adder 內, 其 XOR 的 gate delay=5 ;

AND 的 gate delay=3。跑出波形並驗證其結果是否正確。

2 其 4-bit Ripple Carry Adder 計算 a=1011, b=1101,

產生結果輸出, 需經過多少時間 ?

(Hint: rise, fall, turn-off delay 皆相同於 gate delay)

(內容包含: 題目、程式、RTL Schematic、Technology Schematic、

Behavioral 波形圖及 post-route 波形圖)

作業需檢附項目如下表所示

項目 說明

1 Vegilog code 包含 主程式 & 測試程式

2 RTL Schematic 需要每一層的示意圖

3 Technology Schematic 需要每一層的示意圖

請截圖清楚及解釋波型
4 Behavioral waveform
並附上 monitor 結果
Post&Route 請截圖清楚及解釋波型
5
waveform 並附上 monitor 結果
一 程式碼
主程式
請使用 notepad++ 匯出 PDF 並插入完成的檔案(插入 google 搜尋 PDF 整理)
1 `timescale 1ns / 1ps
2 //////////////////////////////////////////////////////////////////////////////////
3 // Company:
4 // Engineer:C110112150 蔡孟哲
5 //
6 // Create Date: 20:19:54 10/29/2022
7 // Design Name:
8 // Module Name: lab2_1
9 // Project Name:
10 // Target Devices:
11 // Tool versions:
12 // Description:
13 //
14 // Dependencies:
15 //
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 //
20 //////////////////////////////////////////////////////////////////////////////////
21 //----------------lab2-1主程式-----------------//
22 module lab2_1(sum,c_out,a,b,c_in);
23
24 output sum,c_out;
25 input a,b,c_in;
26 wire s1,c1,s2;
27
28 xor #(5)n1(s1,a,b);
29 and #(3)n2(c1,a,b);
30 xor #(5)n3(sum,s1,c_in);
31 and #(3)n4(s2,s1,c_in);
32 or n5(c_out,s2,c1);
33
34
35 endmodule
36
測試程式
請使用 notepad++ 匯出 PDF 並插入完成的檔案(插入 google 搜尋 PDF 整理)
1 `timescale 1ns / 1ps
2 //////////////////////////////////////////////////////////////////////////////////
3 // Company:
4 // Engineer: C110112150 蔡孟哲
5 //
6 // Create Date: 20:22:36 10/29/2022
7 // Design Name:
8 // Module Name: lab2_1_test
9 // Project Name:
10 // Target Devices:
11 // Tool versions:
12 // Description:
13 //
14 // Dependencies:
15 //
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 //
20 //////////////////////////////////////////////////////////////////////////////////
21 //----------------lab2-1測試程式-----------------//
22 module lab2_1_test;
23
24 reg a;
25 reg b;
26 reg c_in;
27
28 wire sum;
29 wire c_out;
30
31 lab2_1 test(sum,c_out,a,b,c_in);
32
33 initial begin
34 a = 0;
35 b = 0;
36 c_in = 0;
37 #10 a=0;b=0;c_in=0;
38 #15 a=0;b=0;c_in=1;
39 #15 a=0;b=1;c_in=0;
40 #15 a=0;b=1;c_in=1;
41 #15 a=1;b=0;c_in=0;
42 #15 a=1;b=0;c_in=1;
43 #15 a=1;b=1;c_in=0;
44 #15 a=1;b=1;c_in=1;
45 #150 $finish;
46
47 end
48 initial
49 $monitor($stime,"a=%d,b=%d,c_in=%d,c_out=%d,sum=%d;",a,b,c_in,c_out,sum);
50
51
52 endmodule
53
54
二 RTL Schematic
外層

內層

三 Technolog Schematic
外層
內層

內層

四 Behavioral waveform

Sum 經過兩個 xor 閘所以延遲時間是 10ns

Cout 經過一個 and 閘跟一個 xor 閘所以延遲時間是 8ns


2 其 4-bit Ripple Carry Adder 計算 a=1011, b=1101,

產生結果輸出, 需經過多少時間 ?

(Hint: rise, fall, turn-off delay 皆相同於 gate delay)


(內容包含: 題目、程式、RTL Schematic、Technology Schematic、

Behavioral 波形圖及 post-route 波形圖)

一 程式碼
主程式
請使用 notepad++ 匯出 PDF 並插入完成的檔案 (插入 google 搜尋 PDF 整理)
1 `timescale 1ns / 1ps
2 //////////////////////////////////////////////////////////////////////////////////
3 // Company:
4 // Engineer:C110112150 蔡孟哲
5 //
6 // Create Date: 21:32:58 10/29/2022
7 // Design Name:
8 // Module Name: lab2_2_test
9 // Project Name:
10 // Target Devices:
11 // Tool versions:
12 // Description:
13 //
14 // Dependencies:
15 //
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 //
20 //////////////////////////////////////////////////////////////////////////////////
21 //----------------lab2-2主程式-----------------//
22 module fulladd4(sum,c_out,a,b,c_in);
23
24 output [3:0]sum;
25 output c_out;
26 input [3:0]a,b;
27 input c_in;
28 wire c1,c2,c3;
29
30 fulladd fa0(sum[0],c1,a[0],b[0],c_in);
31 fulladd fa1(sum[1],c2,a[1],b[1],c1);
32 fulladd fa2(sum[2],c3,a[2],b[2],c2);
33 fulladd fa3(sum[3],c_out,a[3],b[3],c3);
34
35 endmodule
36
37 module fulladd(sum,c_out,a,b,c_in);
38
39 output sum,c_out;
40 input a,b,c_in;
41 wire s1,c1,s2;
42
43 xor #(5)n1(s1,a,b);
44 and #(3)n2(c1,a,b);
45 xor #(5)n3(sum,s1,c_in);
46 and #(3)n4(s2,s1,c_in);
47 or n5(c_out,s2,c1);
48
49 endmodule
50
測試程式
請使用 notepad++ 匯出 PDF 並插入完成的檔案(插入 google 搜尋 PDF 整理)
1 `timescale 1ns / 1ps
2 //////////////////////////////////////////////////////////////////////////////////
3 // Company:
4 // Engineer:C110112150 蔡孟哲
5 //
6 // Create Date: 21:35:17 10/29/2022
7 // Design Name:
8 // Module Name: lab2_2_test
9 // Project Name:
10 // Target Devices:
11 // Tool versions:
12 // Description:
13 //
14 // Dependencies:
15 //
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 //
20 //////////////////////////////////////////////////////////////////////////////////
21 //----------------lab2-2測試程式-----------------//
22 module lab2_2_test;
23
24 reg[3:0]a,b;
25 reg c_in;
26
27 wire[3:0]sum;
28 wire c_out;
29
30 fulladd4 fa_4(sum,c_out,a,b,c_in);
31
32 initial
33 begin
34
35 $monitor($time,"a=%b,b=%b,c_in=%b,c_out=%b,sum=%b\n",a,b,c_in,c_out,sum);
36
37 end
38
39 initial
40 begin
41
42 #5 a=4'd11;b=4'd13;c_in=1'b0;
43 #50 $finish;
44
45 end
46 endmodule
47
二 RTL Schematic
外層

中層
內層

三 Technolog Schematic
外層
內層

四 Behavioral waveform

當 a=1011,b=1101 時
sum 產生結果需要 16 秒
Cout 產生結果需要 1.5 秒

You might also like