




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、2016Verilog 語言 ·實驗報告·專 業(yè):計算機科學與技術(shù)班 級:CS1409學 號:U201414813姓 名:唐禮威電 話 件:1770723422完成日期:2016.6.13華 中 科 技 大 學 課 程 實 驗 報 告目 錄1數(shù)據(jù)通路實驗11.1實驗目的11.2實驗內(nèi)容及要求11.3實驗方案21.4實驗步驟21.5故障及分析21.6仿真與結(jié)果31.7心得與體會42FSM實驗52.1實驗目的52.2實驗內(nèi)容及要求52.3實驗方案62.4實驗步驟62.5故障及分析72.6仿真與結(jié)果72.7心得與體會83意見和建議94附錄1011 數(shù)據(jù)通
2、路實驗1.1 實驗目的綜合應用掌握的簡單組合電路和時序電路的設計方法,完成一個簡單的數(shù)據(jù)通路的設計。1.2 實驗內(nèi)容及要求1. 根據(jù)下圖給出的數(shù)據(jù)通路(圖中R0、R1和ACC是寄存器,+是加法器,其它則是多路選擇器),完成相應的Verilog程序設計,圖中數(shù)據(jù)線的寬度為8位,要求可以擴充至16位或者是32位;2. 根據(jù)下圖給出的數(shù)據(jù)通路(圖中SUM和NEXT是寄存器,Memory是存儲器,+是加法器,=0是比較器,其它則是多路選擇器),完成相應的Verilog程序設計,圖中數(shù)據(jù)線的寬度為8位,要求可以擴充至16位或者是32位。實驗要求:程序必須自己編寫,滿足數(shù)據(jù)通路設計要求,綜合結(jié)果正確。1.
3、3 實驗方案根據(jù)要求,先把選擇器、加法器、寄存器、比較器和存儲器分模塊編寫,在主模塊中根據(jù)數(shù)據(jù)通路調(diào)用即可。題目中要求數(shù)據(jù)線寬度為8位,并且可以擴充至16位或32位,所以在前面定義WIDTH,利用parameter的參數(shù)傳遞功能來實現(xiàn)。1.4 實驗步驟1.分模塊編寫代碼(見附錄)2.運行綜合Run Synthesis3.綜合成功后檢查RTL Analysis中的電路圖Schematic1.5 故障及分析剛開始跑出來很多線是斷的,后來發(fā)現(xiàn)是引腳對應部分的代碼沒有寫完整。后來加法器和ACC的參數(shù)順序?qū)戝e,導致接線與題給的不一致,發(fā)現(xiàn)問題后及時改正了。1.6 仿真與結(jié)果Schematic圖形如下:第
4、一個數(shù)據(jù)通路:第二個數(shù)據(jù)通路:由以上兩圖可得,成功完成了要求的數(shù)據(jù)通路的設計,滿足了各基本器件的輸入輸出鏈接要求;改變數(shù)據(jù)線寬度后再檢查電路圖,發(fā)現(xiàn)數(shù)據(jù)線做出相應改變,完成該實驗。1.7 心得與體會對數(shù)據(jù)通路的設計有了更好的理解,明白了數(shù)據(jù)通路的基本器件構(gòu)成,熟悉了這些器件的功能和端口,掌握了Verilog完成基本運算器件的設計,完成了數(shù)據(jù)通路的設計。 2 FSM實驗2.1 實驗目的掌握用Verilog語言進行FSM設計、實現(xiàn)和仿真的方法。2.2 實驗內(nèi)容及要求5.1_1、用FSM實現(xiàn)一個mealy型序列檢測器,對一位的串行輸入序列中的“1”的數(shù)量進行檢測。如果“1”的總數(shù)可以被3整除,輸出“
5、1”,否則輸出“0”。5.1_2、用FSM實現(xiàn)一個moore型序列檢測器,對兩位的串行輸入序列進行檢測。輸入01,00時,輸出0,輸入11,00時,輸出1,輸入10,00時,輸出反向。5.1_3、用FSM實現(xiàn)一個計數(shù)器(采用存儲器),對一位的輸入進行計數(shù)。計數(shù)序列為:000,001,011,101,111,010。5.2、用FSM實現(xiàn)一個序列識別器,該FSM的狀態(tài)轉(zhuǎn)移圖如下所示,它能夠?qū)σ晃坏拇休斎胄蛄兄械摹?”的數(shù)量進行檢測。如果FSM發(fā)現(xiàn)輸入“1”的總數(shù)可以被3整除時,輸出“1”;否則,輸出“0”。同時針對“01011011101”輸入序列,寫出相應的仿真程序并進行真波測試。2.3 實驗
6、方案先根據(jù)要求畫出狀態(tài)圖,根據(jù)狀態(tài)圖編寫程序,根據(jù)程序編寫仿真程序,最后得出結(jié)果和結(jié)論。2.4 實驗步驟5.1_1狀態(tài)圖:S1S0 in=1/1 in=1/0 in=0/0 in=1/0 in=1/0S4S3 in=0/0 in=1/1 in=0/05.1_2狀態(tài)圖:S0 in=00 in=01 in=10 in=11S2S1S3S6S5S4 in=00 in=00 in=00 out=0 out翻轉(zhuǎn) out=15.1_3狀態(tài)圖:1.根據(jù)以上狀態(tài)圖編寫源程序(見附錄)2.運行綜合Run Synthesis3.綜合正確后編寫仿真程序4.仿真,得到仿真波形,驗證結(jié)果2.5 故障及分析無故障2.6
7、仿真與結(jié)果5.1_1:如圖,1的個數(shù)是3的倍數(shù)時輸出1與預期一致5.1_2:如圖,輸入01后再輸入00,輸出0;輸入11后再輸入00,輸出1;輸入10后再輸入00,輸出翻轉(zhuǎn):與預期一致5.1_3:如圖,輸出序列為000,001,011,101,111,010(重復)與預期一致5.2:如圖,1的個數(shù)是3的倍數(shù)時輸出1與預期一致2.7 心得與體會這次實驗通過FSM設計明白了設計的過程和步驟,首先要知道分為哪些狀態(tài),設計的是何種電路,如何選擇用mealy還是moore型電路,狀態(tài)轉(zhuǎn)移要如何實現(xiàn)。知道了mealy型和moore型電路的區(qū)別:當要求輸出對輸入快速響應并希望電路簡單時選擇mealy型,當要
8、求時序輸出穩(wěn)定,能接受輸出序列晚一個周期,即選擇moore型電路不增加電路復雜性時,選擇moore型電路。3 意見和建議建議老師上課還是用中文PPT比較好,另外作業(yè)練習也用中文給出來,題目要求也盡量具體些,這樣會減少我們學習的成本,更加有效的學習這門課。4 附錄源程序:4.1(第一個數(shù)據(jù)通路)/主模塊module text4(S0,S1,S2,S3,Clk,reset,load,outR0,outR1,outACC,outS0,outS1,outS2,outS3,outA); parameter WIDTH=8; /位寬8位 input S0,S1,S2,S3,Clk,reset,load;
9、output WIDTH-1:0 outR0,outR1,outACC,outS0,outS1,outS2,outS3,outA; register #(8) R0(inR0,Clk,reset,load,outR0); register #(8) R1(inR1,Clk,reset,load,outR1); register #(8) ACC(inACC,Clk,reset,load,outACC); mux #(8) S0(S0,inS00,inS01,outS0); mux #(8) S1(S1,inS10,inS11,outS1); mux #(8) S2(S2,inS20,inS21
10、,outS2); mux #(8) S3(S3,inS30,inS31,outS3); add #(8) W1(inA0,inA1,outA); assign inS00=outS3; assign inS10=outS3; assign inS01=outR0; assign inS20=outR0; assign inS11=outR1; assign inS21=outR1; assign inA0=outACC; assign inS31=outACC; assign inACC=outA; assign inA1=outS2; assign inS30=outS2; assign i
11、nR1=outS1; assign inR0=outS0;endmodule/加法器模塊module add(A,B,C); parameter WIDTH=8; input WIDTH-1:0 A, B; output WIDTH-1:0 C; wire WIDTH:0 DATA; assign DATA=A+B; assign C=DATA7:0;endmodule/寄存器模塊module register(D,Clk,reset,load,Q); parameter WIDTH=8; input WIDTH-1:0 D; input Clk,reset,load; output reg
12、WIDTH-1:0 Q;always (posedge Clk)if (reset)beginQ <= 8'b0;end else if (load)beginQ <= D;endendmodule/二路選擇器模塊module mux(s,x,y,m); parameter WIDTH=8; input WIDTH-1:0 x,y; input s; output WIDTH-1:0 m;assign m =(s?y:x);endmodule4.2(第二個數(shù)據(jù)通路)/主模塊module text2(SUM_SEL,NEXT_SEL,A_SEL,LD_SUM,LD_NEXT,
13、NEXT_ZERO,outSUM_SEL,outNEXT_SEL,outA_SEL,outSUM,outNEXT,outA1,outA2,outMEM);parameter WIDTH=8; input SUM_SEL,NEXT_SEL,A_SEL,LD_SUM,LD_NEXT; wire WIDTH-1:0 inSUM_SEL00,inSUM_SEL01,outSUM_SEL,inNEXT_SEL00,inNEXT_SEL01,outNEXT_SEL; output WIDTH-1:0 outSUM_SEL,outNEXT_SEL,outA_SEL,outSUM,outNEXT,outA1,
14、outA2,outMEM; output NEXT_ZERO; mux #(WIDTH) SUM_SEL(SUM_SEL,inSUM_SEL00,inSUM_SEL01,outSUM_SEL); mux #(WIDTH) NEXT_SEL(NEXT_SEL,inNEXT_SEL00,inNEXT_SEL01,outNEXT_SEL); mux #(WIDTH) A_SEL(A_SEL,inA_SEL00,inA_SEL01,outA_SEL); register #(WIDTH) SUM(inSUM,Clk,reset,LD_SUM,outSUM); register #(WIDTH) NEX
15、T(inNEXT,Clk,reset,LD_NEXT,outNEXT); add #(WIDTH) A1(inA10,inA11,outA1); add #(WIDTH) A2(inA20,inA21,outA2); ROM #(WIDTH,WIDTH) MEM(outMEM,inMEM); COM #(WIDTH) COM(inCOM0,inCOM1,NEXT_ZERO); assign inA10=outSUM; assign inA11=outMEM; assign inNEXT_SEL00=outMEM; assign inNEXT_SEL01=0; assign inSUM_SEL0
16、0=outA1; assign inSUM_SEL01=0; assign inSUM=outSUM_SEL; assign inNEXT=outNEXT_SEL; assign inA20=outNEXT; assign inA21=1; assign inA_SEL00=outNEXT; assign inA_SEL01=outA2; assign inMEM=outA_SEL; assign inCOM0=outNEXT_SEL; assign inCOM1=0; endmodulemodule COM(a,b,out); parameter WIDTH=8; input WIDTH-1
17、:0 a,b; output out; reg out; always (a or b) begin if(a>b) out=1; else out=0; endendmodule/存儲器模塊module ROM(ROM_data, ROM_addr);parameter data_WIDTH=8;parameter addr_WIDTH=8;output addr_WIDTH-1:0 ROM_data;input addr_WIDTH-1:0 ROM_addr;reg addr_WIDTH-1:0 ROM data_WIDTH-1:0; / defining 4x2 ROMassign
18、 ROM_data = ROMROM_addr; / reading ROM content at the address ROM_addrinitial $readmemb ("ROM_data.txt", ROM, 0, 3); / load ROM content from ROM_data.txt fileendmodule/寄存器模塊module register(D,Clk,reset,load,Q); parameter WIDTH=8; input WIDTH-1:0 D; input Clk,reset,load; output reg WIDTH-1:0
19、 Q;always (posedge Clk)if (reset)beginQ <= 8'b0;end else if (load)beginQ <= D;endendmodule/加法器模塊module add(A,B,C); parameter WIDTH=8; input WIDTH-1:0 A, B; output WIDTH-1:0 C; wire WIDTH:0 DATA; assign DATA=A+B; assign C=DATA7:0;endmodule/二路選擇器模塊module mux(s,x,y,m); parameter WIDTH=8; inpu
20、t WIDTH-1:0 x,y; input s; output WIDTH-1:0 m;assign m =(s?y:x);endmodule5.1_1module lab5_1_1(input clk, input reset, input ain, output reg yout, output reg 3:0 count); reg 1:0 state, nextstate; parameter S0=0, S1=1, S2=2, S3=3; always (posedge clk) / always block to update state if (reset) begin sta
21、te <= S0; count = 0; end else state <= nextstate; always (state or ain) / always block to compute output begin yout = 0; case(state) S0: if(!ain) yout = 1; S1: yout = 0; S2: yout = 0; S3: if(ain) yout = 1; endcase end always (posedge clk) / always block to compute output begin if(ain) count =
22、count + 1; end always (state or ain) / always block to compute nextstate begin case(state) S0: if(ain) nextstate = S1; else nextstate = S0; S1: if(ain) nextstate = S2; else nextstate = S1; S2: if(ain) nextstate = S3; else nextstate = S2; S3: if(ain) nextstate = S1; else nextstate = S3; endcase end e
23、ndmodule仿真程序:module lab5_1_1_tb(); reg clk,reset,ain; wire yout; wire 3:0 count; integer i; parameter TIME = 400; parameter DELAY = 5; lab5_1_1 DUT (.clk(clk), .ain(ain), .count(count), .reset(reset), .yout(yout); initial begin #TIME $finish; end initial begin clk = 0; for(i = 0; i < (TIME/DELAY)
24、; i = i + 1) #DELAY clk = clk; end initial begin reset = 1; #(4*DELAY) reset = 0; #(34*DELAY) reset = 1; #(2*DELAY) reset = 0; end initial begin ain = 0; #(8*DELAY) ain = ain; #(4*DELAY) ain = ain; #(12*DELAY) ain = ain; #(8*DELAY) ain = ain; #(4*DELAY) ain = ain; #(6*DELAY) ain = ain; #(6*DELAY) ai
25、n = ain; endendmodule5.1_2module lab5_1_2(input clk, input reset, input 1:0 x, output reg yout, output reg 2:0 nextstate); reg 2:0 state; parameter S0=0, S11=1, S21=2, S31=3, S12=4, S22=5, S32=6; always (posedge clk) / always block to update state if (reset) begin state <= S0; nextstate = S0; you
26、t = 0; end else state <= nextstate; always (state) / always block to compute output begin case(state) S0: yout = yout; S12: yout = 0; S22: yout = 1; S32: yout = yout; endcase end always (state or x) / always block to compute nextstate begin case(state) S0: if(x = 1) nextstate = S11; else if(x = 3
27、) nextstate = S21; else if(x = 2) nextstate = S31; S11: if(x = 0) nextstate = S12; else if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else if(x = 2) nextstate = S31; S12: if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else if(x = 2) nextstate = S31; S21: if(x = 0) nextstate
28、= S22; else if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else if(x = 2) nextstate = S31; S22: if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else if(x = 2) nextstate = S31; S31: if(x = 0) nextstate = S32; else if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else
29、if(x = 2) nextstate = S31; S32: if(x = 1) nextstate = S11; else if(x = 3) nextstate = S21; else if(x = 2) nextstate = S31; endcase endendmodule仿真程序:module lab5_1_2_tb(); reg clk,reset; reg 1:0 x; wire 2:0 nextstate; wire yout; integer i; parameter TIME = 200; parameter DELAY = 5; lab5_1_2 DUT (.clk(
30、clk), .x(x), .reset(reset), .yout(yout), .nextstate(nextstate); initial begin #TIME $finish; end initial begin clk = 0; for(i = 0; i < (TIME/DELAY); i = i + 1) #DELAY clk = clk; end initial begin reset = 1; #(4*DELAY) reset = 0; end initial begin x = 0; #(8*DELAY) x = 3; #(2*DELAY) x = 2; #(2*DEL
31、AY) x = 0; #(4*DELAY) x = 2; #(2*DELAY) x = 0; #(2*DELAY) x = 3; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 2; #(2*DELAY) x = 3; #(2*DELAY) x = 0; #(6*DELAY) x = 2; #(6*DELAY) x = 0; endendmodule5.1_3module lab5_1_3(input clk, input reset, input x, output reg 2:0 yout, outp
32、ut reg 2:0 nextstate); reg 2:0 state; parameter S0=0, S1=1, S2=2, S3=3, S4=4, S5=5; always (posedge clk) / always block to update state if (reset) begin state <= S0; nextstate = S0; end else state <= nextstate; always (state or x) / always block to compute output begin case(state) S0: yout = 0
33、; S1: yout = 1; S2: yout = 3; S3: yout = 5; S4: yout = 7; S5: yout = 2; endcase end always (x or state) / always block to compute nextstate begin case(state) S0: if(x) nextstate = S1; else nextstate = S0; S1: if(x) nextstate = S2; else nextstate = S1; S2: if(x) nextstate = S3; else nextstate = S2; S
34、3: if(x) nextstate = S4; else nextstate = S3; S4: if(x) nextstate = S5; else nextstate = S4; S5: if(x) nextstate = S0; else nextstate = S5; endcase endendmodule仿真程序:module lab5_1_3_tb(); reg clk,reset; reg x; wire 2:0 nextstate; wire 2:0 yout; integer i; parameter TIME = 400; parameter DELAY = 5; la
35、b5_1_3 DUT (.clk(clk), .x(x), .reset(reset), .yout(yout), .nextstate(nextstate); initial begin #TIME $finish; end initial begin clk = 0; for(i = 0; i < (TIME/DELAY); i = i + 1) #DELAY clk = clk; end initial begin reset = 1; #(4*DELAY) reset = 0; end initial begin x = 0; #(8*DELAY) x = 1; #(2*DELA
36、Y) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; #(2*DELAY) x = 1; #(2*DELAY) x = 0; en
37、dendmodule5.2module lab5_2_1(input clk, input reset, input ain, output reg yout, output reg 3:0 count); reg 1:0 state, nextstate; parameter S0=0, S1=1, S2=2, S3=3; always (posedge clk) / always block to update state if (reset) begin state <= S0; count = 0; end else begin state <= nextstate; if(ain) count = count + 1; end always (state) / always block to compute output begin yout = 0; case(state) S0
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 配件買賣合同
- 湖北省十堰市2024-2025學年高二上學期1月期末地理試題 含解析
- 日常辦公事務處理文書詳案
- 融資借款合同協(xié)議書
- 數(shù)據(jù)傳輸效率評估表
- 產(chǎn)品分銷合同協(xié)議規(guī)范書
- 中學生科普知識解讀征文
- 電商平臺在線客服機器人技術(shù)支持協(xié)議
- 《現(xiàn)代酒店管理基礎》(第二版)課件 任務9 酒店集團化管理
- 幼兒啟蒙成語故事解讀
- 生產(chǎn)工藝的標準化與規(guī)范化
- 河道清淤培訓課件
- 機械基礎全冊教案第四版
- 《瘋狂動物城》全本臺詞中英文對照
- 大班語言猴子過河教案反思
- 同位語從句和定語從句
- 醫(yī)院OSCE考站建設需求
- 10以內(nèi)加減法口算題(13套100道題直接打印)
- 十年免還協(xié)議合同
- 中國建筑三鐵六律行為安全準則培訓ppt
- 斷橋門聯(lián)窗施工方案
評論
0/150
提交評論