蔡覺平老師西電VerilogHDL上機大作業硬件描述語言微電子學院_第1頁
蔡覺平老師西電VerilogHDL上機大作業硬件描述語言微電子學院_第2頁
蔡覺平老師西電VerilogHDL上機大作業硬件描述語言微電子學院_第3頁
蔡覺平老師西電VerilogHDL上機大作業硬件描述語言微電子學院_第4頁
蔡覺平老師西電VerilogHDL上機大作業硬件描述語言微電子學院_第5頁
已閱讀5頁,還剩9頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Verilog HDL數字集成電路設計原理與應用上機作業班級:*學號:*姓名:*題目1:數字集成電路的verilog HDL描述與仿真。要求:(1)學習使用Modelsim設計和仿真軟件; (2)練習教材7.2.1中的例子; (3)掌握設計代碼和測試代碼的編寫; (4)掌握測試仿真流程; (5)掌握Modelsim軟件的波形驗證方式。解答: 題目2: 簡述begin-end語句塊和fork-join語句塊的區別,并寫出下面信號對應的程序代碼解答:(1)begin-end語句塊和fork-join語句塊的區別:1、執行順序:begin-end語句塊按照語句順序執行,fork-join語句塊所有語

2、句均在同一時刻執行;2、語句前面延遲時間的意義:begin-end語句塊為相對于前一條語句執行結束的時間,fork-join語句塊為相對于并行語句塊啟動的時間;3、起始時間:begin-end語句塊為首句開始執行的時間,fork-join語句塊為轉入并行語句塊的時間;4、結束時間:begin-end語句塊為最后一條語句執行結束的時間,fork-join語句塊為執行時間最長的那條語句執行結束的時間;5、行為描述的意義:begin-end語句塊為電路中的數據在時鐘及控制信號的作用下,沿數據通道中各級寄存器之間的傳送過程。fork-join語句塊為電路上電后,各電路模塊同時開始工作的過程。(2)程序

3、代碼:Begin-end語句:module initial_tb1;reg A,B;initialbeginA=0;B=1;#10A=1;B=0;#10B=1;#10A=0;#10B=0;#10A=1;B=1;endendmoduleFrk-join語句:module wave_tb2;reg A,B;parameter T=10;initialfork A=0;B=1;#TA=1;B=0;#(2*T)B=1;#(3*T)A=0;#(4*T)B=0;#(5*T)A=1;B=1;joinendmodule 題目3. 分別用阻塞和非阻塞賦值語句描述如下圖所示移位寄存器的電路圖。解答:(1)阻塞賦值

4、語句module block2(din,clk,out0,out1,out2,out3);input din,clk;output out0,out1,out2,out3;reg out0,out1,out2,out3;always(posedge clk)beginout0=din;out1=out0; out2=out1;out3=out2;endendmodule(2)非阻塞賦值語句module non_block1 (din,clk,out0,out1,out2,out3);input din,clk;output out0,out1,out2,out3;reg out0,out1,o

5、ut2,out3;always(posedge clk) beginout0<=din;out1<=out0; out2<=out1;out3<=out2;endendmodule 題目4:設計16位同步計數器要求:(1)分析16位同步計數器結構和電路特點; (2)用硬件描述語言進行設計; (3)編寫測試仿真并進行仿真。解答:(1)電路特點:同步計數器的時間信號是同步的;每當到達最高計數后就會重新計數。(2)程序代碼:module comp_16 (count, clk, rst );output 15:0 count;input clk,rst; reg 15:0 c

6、ount;always (posedge clk) if (rst)count<=16'b0000000000000000; else if (count=16'b1111111111111111) count<=16'b0000000000000000; else count<=count+1;endmodule(3)仿真代碼:module comp_16_tb;wire 15:0 count;reg clk,rst; comp_16 U1 (count, clk, rst );always #1 clk=clk;initialbeginclk=0;

7、rst=0;#1 rst=1;#10 rst=0;#10 rst=1;#10 rst=0;#99999 $finish;endendmodule 題目5. 試用Verilog HDL門級描述方式描述如下圖所示的電路。解答:module zy(D0,D1,D2,D3,S1,S2,T0,T1,T2,T3,Z);output Z;input D0,D1,D2,D3,S1,S2;wire T0,T1,T2,T3,wire1,wire2;not U1(wire1,S1), U2(wire2,S2);and U3(T0,D0,wire2,wire1), U4(T1,D1,S1,wire1), U5(T2,

8、D2,S1,wire2), U6(T3,D3,S1,S2);or U7(Z,T0,T1,T2,T3,);endmodule 題目6. 試用查找真值表的方式實現真值表中的加法器,寫出Verilog HDL代碼:CinainbinsumCout0000000110010100110110010101011100111111解答:module homework6(SUM,COUT,A,B,CIN);output SUM,COUT;input A,B,CIN;reg SUM,COUT;always(A or B or CIN)case(A,B,CIN) 3'b000:SUM<=0; 3&

9、#39;b000:COUT<=0; 3'b001:SUM<=1; 3'b001:COUT<=0; 3'b010:SUM<=1; 3'b010:COUT<=0; 3'b011:SUM<=0; 3'b011:COUT<=1; 3'b100:SUM<=1; 3'b100:COUT<=0; 3'b101:SUM<=0; 3'b101:COUT<=1; 3'b110:SUM<=0; 3'b110:COUT<=1; 3'b11

10、1:SUM<=1; 3'b111: COUT<=1; endcase endmodule 題目7:設計16位同步加法器和乘法器要求:(1)分析16位同步加法器和乘法器結構和電路特點; (2)用硬件描述語言進行設計; (3)編寫測試仿真并進行仿真。解答:(1)16位同步加法器和乘法器結構和電路特點:加法器的進位只用考慮一位,但是乘法器的進位要考慮到32位才行。(2)程序代碼:16位同步加法器:module adder(a,b,c,sum,cout); output 15:0sum; output cout; input 15:0a,b; input c; assign cou

11、t,sum=a+b+c;endmodule16位同步乘法器:module multiplier(a,b,mul); input 15:0a,b; output 31:0mul; assign mul=a*b;endmodule(3)仿真代碼:16位同步加法器:module adder_tb;reg 15:0a,b; reg c; wire 15:0sum; wire cout; initial begin a=8;b=8;c=1; end initial begin #10 a=16'b1111111111111111;#10 b=1; end adder U2(.a (a),.b (

12、b),.c(c),.cout(cout),.sum(sum);endmodule16位同步乘法器:module multiplier_tb; reg 15:0a,b; wire 31:0mul; initial begin a=3;b=8; end initial begin #10 a=100; #15 b=100; end multiplier U1(.a(a),.b(b),.mul(mul);endmodule仿真截圖:加法器:乘法器: 題目8. 將下面的狀態轉移圖用Verilog HDL描述。在圖中,狀態機的輸入只與狀態的跳轉有關,與狀態機的輸出無關,因此該狀態機為摩爾型狀態機。下面為

13、三段式描述方式。解答:程序代碼:module homework8(clk,out,step,clr); output 2:0out; input step,clk,clr; reg 2:0out; reg 1:0state,next_state; always (posedge clk) state<=next_state; always (state or clr) if(clr) next_state<=0; else case(state) 2'b00: case(step) 1'b0:begin next_state<=2'b00;out<

14、;=3'b001;end 1'b1:begin next_state<=2'b01;out<=3'b001;end endcase 2'b01: begin out<=3'b010; next_state<=2'b10; end 2'b10: case(step) 1'b0:begin next_state<=2'b00;out<=3'b100;end 1'b1:begin next_state<=2'b11;out<=3'b100;e

15、nd endcase 2'b11: case(step) 1'b0:begin next_state<=2'b11;out<=3'b111;end 1'b1:begin next_state<=2'b00;out<=3'b111;end endcase endcaseendmodule仿真代碼:module homework8_tb; reg clk,step,clr; wire 3:0out; always #5 clk=clk; initial begin clk=0; clr=1;step=1;end ini

16、tial begin #5clr=0; #10 step=0; #10step=1;end homework8 U1(clk,out,step,clr);endmodule仿真截圖: 題目9. 如下圖所示電路,若其延遲時間設定如表所示,試寫Verilog HDL程序設計該電路。路徑最小值(min)典型值(type)最大值(max)a_sa_y101214s_s0_sa_y151719s_sb_y111315b_sb_y101214解答:程序代碼:module a(a,s,b,y,s0); input a,b,s,s0; output y; assign y=(s&&b)|(s0

17、&&a); specify (a=>y)=(10,12,14); (b=>y)=(10,12,14); (s=>y)=(11,13,15); (s0=>y)=(11,13,15); endspecifyendmodulemodule b(a,s,b,y); input s,a,s,b; output y; wire s0; not #(4)U1(s0,s); delay_door U2(a,s,b,y,s0);endmodule 題目10.設計一個8位數字顯示的簡易頻率計。要求:能夠測試10Hz10MHz方波信號;電路輸入的基準時鐘為1Hz,要求測量值以

18、8421BCD碼形式輸出;系統有復位鍵;采用分層次分模塊的方法,用Verilog HDL進行設計。解答:程序代碼:module x; reg standard_clk; reg test_clk; wire 7:0out; reg reset; initial begin reset=0; test_clk=0; standard_clk=0; end initial #15 reset=1; always #1 test_clk=test_clk; always #10 standard_clk=standard_clk; a U1(.reset(reset),.test_clk(test_

19、clk),.standard_clk(standard_clk),.ratio_final(out);endmodulemodule a(reset,test_clk,standard_clk,ratio_final); input reset,test_clk,standard_clk; output 7:0ratio_final; wire mul_clk; wire reset_comp; wire 7:0ratio_start; and U0(reset_comp,reset,standard_clk); t U1(.ain(test_clk),.din(standard_clk),.

20、mul(mul_clk); w U2(.clk(mul_clk),.count(ratio_start),.reset(reset_comp); c U3(.ratio_start(ratio_start),.ratio_final(ratio_final);endmodule module w(clk,count,reset); input clk,reset; output count; parameter bit=8; reg bit-1:0count; always (posedge clk or negedge reset) if(!reset) count<=8'b0

21、0000000; else count<=count+1; endmodulemodule t(ain,din,mul); parameter width=1; input width-1:0ain,din; output width*2-1:0mul; assign mul=ain*din;endmodulemodule c(ratio_start,ratio_final); input 7:0ratio_start; output 7:0ratio_final; assign ratio_final=2*ratio_start;endmodule 題目11. 用Verilog HDL設計一個4位LED顯示器的動態掃描譯碼電路。要求:4個七段顯示器共用一個譯碼驅動電路;顯示的數碼管清晰明亮,無閃爍現象發生。解答:module a(out,in); output out; input in; reg6:0out; wire3:0in; always(in) begin case(in) 4'd0:out=7'b1111110; 4'd1:out=7'b0110000; 4'd2:out=7'b1101101; 4'd3:out=7'b1111001; 4'd4:out=7&

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論