verilog串并轉換并串轉換_第1頁
verilog串并轉換并串轉換_第2頁
verilog串并轉換并串轉換_第3頁
verilog串并轉換并串轉換_第4頁
verilog串并轉換并串轉換_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、1.設計名稱:38譯碼器帶使能端的主要功能:實現(xiàn)38譯碼功能,并且在使能段處于低電平是輸出為設計框圖:設計代碼:module decoder3_8(a,b,ena);input 2:0 a;input ena;output 7:0 b;reg 7:0 b;always (ena,a)if(!ena)begin b=8b;endelse begincase(a)3b000: b=8b;3b001: b=8b;3b010: b=8b;3b011: b=8b;3b100: b=8b;3b101: b=8b;3b110: b=8b;3b111: b=8b;default: b=8b;endcaseen

2、dendmodule仿真代碼:timescale 1ns/1nsmodule tb; reg 2:0 a; reg ena; wire 7:0 b; initial begin a = 3b000; ena = 1b0; #50; ena = 1b1; #50; a=3b001; #50; a=3b010; #50; a=3b011; #50; a=3b100; #50; a=3b101; #50; a=3b110; #50; a=3b111; #50; $ stop; end decoder3_8 udecoder3_8( .a(a), .ena(ena), .b(b) );endmodul

3、e仿真結果:輔助說明:當ena為低電平時,無論a為何值,總是輸出,當ena為高電平時,輸出即隨a的數(shù)值變化而變化,當a為001時,b的值變?yōu)?;當a為010時,b的值變?yōu)椋@與設計時的功能是一致的。_2.設計名稱:83編碼器帶使能端的和優(yōu)先級主要功能:實現(xiàn)83編碼功能,并且在使能段處于低電平是輸出為000,同時最高位的優(yōu)先級最高設計框圖:設計代碼:module undecoder8_3(a,b,ena);input 7:0 a;input ena;output 3:0 b;reg 3:0 b;always (ena,a)if(!ena)begin b=3b000;endelse if(a7) b

4、=3b111;elseif(a6) b=3b110;elseif(a5) b=3b101;elseif(a4) b=3b100;elseif(a3) b=3b011;elseif(a2) b=3b010;elseif(a1) b=3b001;elseif(a0) b=3b000;else b=3b000;endmodule仿真代碼:module tb; reg 7:0 a; reg ena; wire 2:0 b; initial begin a = 8b; ena = 1b0; #50; ena = 1b1; #50; a=8b; #50; a=8b; #50; a=8b; #50; a=8

5、b; #50; a=8b; #50; a=8b; #50; a=8b; #50; $stop; end undecoder8_3 unit1_undecoder8_3( .a(a), .ena(ena), .b(b) );endmodule仿真結果:輔助說明:當ena為低電平時,無論a為何值,總是輸出000,當ena為高電平時,輸出即隨a的數(shù)值變化而變化,當a為時,b為110,當a為是,b為101以此類推,同時最后一個波形為,當a為時,b為111,體現(xiàn)了優(yōu)先譯碼的功能,此結果和當初設計的功能一致的。_3.設計名稱:設計一個1:1的3分頻器主要功能:實現(xiàn)3分頻,同時高低電平比為1:1設計框圖:設

6、計代碼:這個設計可以利用模三計數(shù)器分別在時鐘的上升和下降沿設計一個高低電平為1:2的3分頻,然后將兩個波形相或即能得到結果。代碼一:module Devider2_1( /inputs clk, rst_n, /outputs opt1, opt2, opt); input clk; input rst_n; output opt; output opt1; output opt2; reg opt1; reg 1:0 temp1; reg opt2; reg 1:0 temp2; always(posedge clk) begin if(!rst_n) begin temp1 = 2d0;

7、opt1 = 1b0; end else if(temp1=1) begin opt1 =1b1; temp1 = temp1 + 2d1; end else if(temp1=2d2)begin opt1 = 1b0; temp1 = 2d0;end elsebegin temp1 = temp1+2d1;endend always(negedge clk) begin if(!rst_n) begin temp2 = 2d0; opt2 = 1b0; end else if(temp2=1) begin opt2 =1b1; temp2 = temp2 + 2d1; end else if

8、(temp2=2d2)begin opt2 = 1b0; temp2 = 2d0; end else begin temp2 = temp2+2d1; end end assign opt = opt1 | opt2; endmodule同時也可以用同樣的方法設計一個在上升和下降沿高低電平2:1的3分頻器,將兩個波形相與即可。代碼二:module Devider2_1( /inputs clk, rst_n, /outputs opt1, opt2, opt); input clk; input rst_n; output opt; output opt1; output opt2; reg

9、opt1; reg opt2; reg 1:0 temp1; reg 1:0 temp2; always(posedge clk) begin if(!rst_n) begin temp1 = 2d0; opt1 = 1b0;end /reset else if(temp1=2d0) begin opt1=1b1; temp1 = temp1 + 2d1;end else if(temp1=2d1)begin opt1 =1b1; temp1 = temp1 + 2d1;end else if(temp1=2d2)begin opt1 = 1b0; temp1 = 2d0;endend alw

10、ays(negedge clk) begin if(!rst_n)begin temp2 = 2d0; opt2 = 1b0;end /reset else if(temp2=2d0) begin opt2=1b1; temp2 = temp2 + 2d1;end else if(temp2=2d1) begin opt2 =1b1; temp2 = temp2 + 2d1;end else if(temp2=2d2)begin opt2 = 1b0; temp2 3) Q=1;else Q=0; endendmodule仿真代碼:timescale 1ns/1nsmodule q; reg

11、rst; reg 6:0vote; wire Q; initial begin rst=0; vote=7b;#50; rst=1;#50; rst=0;#50; vote=7b;#50; vote=7b;#50; vote=7b;#50; vote=7b;#50; vote=7b;#50; vote=7b;#50; $stop;endv v_unit(.vote(vote),.rst(rst),.Q(Q);endmodule仿真結果:輔助說明:第一個表決為,有6人同意,于是顯示通過,Q為高電平,第二個單位是,rst復位信號顯示為1,此時對表決器復位,于是Q清0,后面當rst為低電平時又可以開

12、始表決,當最后一個表決信號只有1個人同意時,由于人數(shù)少于4,所以Q為0,不通過,結果與設計相仿。_5設計名稱:十進制計數(shù)器的設計主要功能:使能端為高電平且復位信號為低電平是,進行模十同步計數(shù),同時滿10 的時候清0并且進位co置1,在一個始終后默認高位已經接受完進位信號將其清0。使能端為低電平時計數(shù)器保持輸出不變,當使能端為高電平,且復位信號為高電平時,將計數(shù)器異步清0.設計框圖:設計代碼:module ten(clk,rst_tong,rst_yi,a,co,ena); input clk; input rst_tong; input rst_yi; input ena; output 3:

13、0 a; output co; reg 3:0a; reg co;always(posedge clk or posedge rst_yi)beginco=0;if(rst_yi) begin a=4b0000; co=0;endif(!ena) beginco=0;endelsebegin if(rst_tong)begin a=4b0000; co=0;end else if(a4b1001) a=a+4b0001;elseif(a=4b1001)begin a=4b0000; co=1;endendendendmodule仿真代碼:timescale 1ns/1nsmodule tb;

14、reg clk; reg rst_yi; reg ena; reg rst_tong; wire 3:0a; wire co; always #10 clk = clk; initial begin ena=0; clk = 1b0; rst_yi= 1b1; rst_tong=1b0; #10; ena=1; #14; rst_yi= 1b0; #230; rst_yi= 1b1; #20; rst_yi=1b0; #20; ena=0; #30; rst_tong=1b1; #500; $stop; end ten ten_unit(.clk(clk), .rst_yi(rst_yi),

15、.rst_tong(rst_tong), .ena(ena), .a(a), .co(co) ); endmodule仿真結果:輔助說明:這個十進制計數(shù)器里面我設計了兩個復位端口,一個是同步復位端口rst_tong,一個是異步復位端口rst_yi,從仿真圖形中可以看出,在使能端ena為低是計數(shù)器保持數(shù)值不變,輸出全是0,當使能端ena為高電平的時候,當異步復位rst_yi為高電平是實現(xiàn)異步清零,這個可以在rst_yi的第二個高電平處看清楚,當rst_yi為低電平時,若rst_tong為低電平,實現(xiàn)正常計數(shù),此時從0000計數(shù)到1001,在下一個時鐘周期產生一個半個周期的進位高電平co,在并且計

16、數(shù)a重新變?yōu)?,當rst-tong為高電平時,在時鐘的上升沿進行同步置數(shù)此功能和當初的設計目標一致。_6:設計名稱: 4路搶答器主要功能: 完成搶答功能,并且在搶答結束的時候清0,在下一次搶答開始之前按搶答鍵無效。設計框圖:設計代碼:module qiang(a,b,start); input 3:0 a; input start; output 3:0b; reg 3:0b; reg 3:0temp; always(a or start)begin if(!start) begin temp=0; b=0; end else if(temp= 4b0000) begin temp=a; b=

17、temp; end end endmodule 仿真代碼:timescale 1ns/1nsmodule tb; reg 3:0a; reg start; wire 3:0b; initial begin start=0; a=4b0000; #10; start=1; #10; a=4b0100; #10; a=4b0110; #50; start=0; #10; a=4b0100; #30; a=4b0000; #50; start=1; #50; a=4b1000; #50; $stop; end qiang qiang_unit( .a(a), .start(start), .b(b)

18、 );Endmodule仿真結果: 輔助說明:可以看出,當start為0,搶答器未啟動時,輸出為0000,當start為1時,此時a=0010,表明第二個人已經先按下?lián)尨鹌?,這是輸出為0010,之后a=0110,又有人再次之后按下?lián)尨鹌?,但是由于a【1】已經先按下,所以a【2】按下后還是只能顯示0010,這就實現(xiàn)了搶答功能,當start=0是,這是輸出清零,這是輸入0100,由于搶答器未工作,所以輸出還是0000,后面當start又是1的時候,這時候a【3】搶答成功,所輸出又為1000,符合當初的設計功能。7.設計名稱:并串轉換主要功能:在沒有數(shù)據(jù)輸出時,輸出為x,此時ready信號為高,若l

19、oad信號也為高時,則將輸入的數(shù)據(jù)傳輸給中間寄存器temp,然后resdy信號變?yōu)榈碗娖剑瑀eady信號有temp【7】決定,當temp【7】中還有數(shù)據(jù)時,表明還沒有全部轉換完,則ready為低,當temp【7】沒有數(shù)據(jù)顯示為x時,則ready為高,表明可以接收數(shù)據(jù)了。當接收完數(shù)據(jù)之后,在8個時鐘周期將信號輸出。設計框圖:設計代碼:module bcc(clk,ain,rst,bout,load,ready); input clk; input 7:0ain; input rst; input load; output bout; output ready; reg bout; reg 7:0

20、temp; reg ready; always (posedge rst or posedge clk)begin if(rst)begin bout =1bx; temp =8bxxxxxxxx; ready=1;end else if(load & ready) temp=ain;/if load is high leve and temp is empty,then,transport data if(temp7|!temp7) /temp7 has databegin bout=temp7; /temp shift left,and temp0 equal x temp7:1=temp

21、6:0; temp0=1bx; ready=0;end else begin bout=1bx; ready=1;end end endmodule仿真代碼:timescale 1ns/1ns module bcc_tb; reg clk; reg 7:0ain; reg rst; reg load; wire ready; wire bout; always #10 clk = clk; initialbegin clk=0; rst=1; load=0; ain=11; #10; rst=0; #10; load=1; #20; load=0; #20; ain=8; #40; load=

22、1; #20; load=0; #100; load=1; #20; load=0; #200; rst=1; #10; $stop;end bcc bcc_unit( .clk(clk), .ain(ain), .rst(rst), .load(load), .bout(bout), .ready(ready) ); Endmodule仿真結果:輔助說明:可以從仿真圖形中看出,在rst為高時,進行復位,當rst為低時,由于temp里面沒有數(shù)據(jù),所以ready信號為高,此時表明temp可以接受數(shù)據(jù),若load信號為高,之后temp則接收到ain的信號,此時temp里面有了數(shù)據(jù),則ready信號

23、為0,不能再傳輸數(shù)據(jù),此時后8個時鐘周期輸出為,完成串并轉換,期間就算load為高電平,但是ready信號為低,所以不會傳輸下一個數(shù)據(jù),只有當之后ready為高電平時,此時財貨執(zhí)行下一個數(shù)據(jù)的傳輸。此仿真波形與我當時設計的目標相符,基本達到設計目標。8.設計名稱:串并轉換主要功能:當rst為高電平時進行復位,當rst為低電平時,若 load為高電平且ready為高電平(ready信號有temp決定,若temp里面的數(shù)據(jù)已經傳滿則ready為低電平,若temp數(shù)據(jù)還未傳滿,則ready為高電平)時將輸入數(shù)據(jù)傳給自己定義的中間寄存器temp,若temp接受完8位數(shù)據(jù),則ok信號為高電平并且將rea

24、dy置為低電平,就可以將temp的值傳給bout輸出,傳輸完畢之后temp又被清空,此時ok又置為低電平,ready顯示高電平。設計框圖:設計代碼:module cbc(clk,ain,load,rst,ready,bout,ok); input clk; input ain; input load; input rst; output ready; output 7:0bout; output ok; reg ready; reg 7:0bout; reg 7:0temp; reg ok; always (posedge clk or posedge rst)begin bout=8bxxxxxxxx; if(rst)begin temp=8bxxxxxxxx; bout=8bxxxxxxxx; ready=1; ok=0;end

溫馨提示

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

評論

0/150

提交評論