實(shí)驗(yàn)一 1.設(shè)計(jì)功能描述
在 DE0 開發(fā)板上,設(shè)計(jì)一個(gè)變換計(jì)數(shù)最大值的循環(huán)計(jì)數(shù)器:在電路復(fù)位后會(huì)循環(huán)的從0值遞增計(jì)數(shù)到最大值,第一次計(jì)數(shù)最大值是6,然后是7、8、9,然后計(jì)數(shù)最大值又變成6,如此往復(fù)循環(huán); 計(jì)數(shù)數(shù)值以十進(jìn)制數(shù)在最右側(cè)的 HEX LED 數(shù)碼管上顯示,變化的時(shí)間間隔是1秒 ,復(fù)位時(shí),數(shù)碼管熄滅。 2.手工繪制的RTL圖 
3.Quartus Ⅱ9.0 編譯生成的RTL電路圖

(1)時(shí)間基準(zhǔn)電路

(2)計(jì)數(shù)器模塊

(3)數(shù)碼管譯碼模塊

4.程序源代碼
///////////////時(shí)間基準(zhǔn)電路/////////////module cnt_sync( CLK , CNTVAL, OV ); input CLK; output [32-1:0] CNTVAL; output OV; parameter MAX_VAL = 25_000_000;reg [32-1:0] CNTVAL; reg OV; always @ (posedge CLK) begin if(CNTVAL >= MAX_VAL) CNTVAL <= 0; else CNTVAL <= CNTVAL + 1'b1; end always @ (CNTVAL) begin if(CNTVAL == MAX_VAL) OV = 1'b1; else OV = 1'b0; end endmodule //////////////計(jì)數(shù)器模塊///////////////// module counter( //對(duì)1s基本信號(hào)計(jì)數(shù)EN, //計(jì)數(shù)使能控制CLK,COU,RST);input RST, EN, CLK;output reg [3:0] COU; reg [1:0] M;reg [3:0] MAX = 4'b0110;always @ (posedge CLK) if (RST == 1) if (EN == 1) if (COU != MAX) begin COU <= COU + 1'b1; M <= M; end else begin COU <= 4'b0000; M <= M + 1'b1; end else COU <= COU; else //清零 begin M <= 2'b00; COU <= 4'b0000; endalways @ (COU) case (M) //計(jì)數(shù)最值控制 2'b00 : MAX = 4'b0110; 2'b01 : MAX = 4'b0111; 2'b10 : MAX = 4'b1000; 2'b11 : MAX = 4'b1001; endcaseendmodule ////////////////數(shù)碼顯示管譯碼///////////////////// module dec_4to8(IN , //計(jì)數(shù)值輸入RST ,OUT);input [4-1:0] IN ;input RST ;output [8-1:0] OUT ;reg [8-1:0] OUT ;always @ (IN) begin if(RST) OUT = 8'b11111111; else case(IN) 4'b0000: OUT = 8'b11000000; 4'b0001: OUT = 8'b11111001; 4'b0010: OUT = 8'b10100100; 4'b0011: OUT = 8'b10110000; 4'b0100: OUT = 8'b10011001; 4'b0101: OUT = 8'b10010010; 4'b0110: OUT = 8'b10000010; 4'b0111: OUT = 8'b11111000; 4'b1000: OUT = 8'b10000000; 4'b1001: OUT = 8'b10010000; endcaseendendmodule // module dec_4to8;5.Signal Tap 分析

實(shí)驗(yàn)內(nèi)容二 1、設(shè)計(jì)要求
設(shè)計(jì)一個(gè)變換計(jì)數(shù)最大值的循環(huán)計(jì)數(shù)器在 DE0 開發(fā)板的從左到右的 4個(gè)HEX LED 數(shù)碼管上,進(jìn)行計(jì)數(shù)并用十進(jìn)制數(shù)進(jìn)行顯示:左1 LED,顯示 0、1、2 ~6 ,然后熄滅;左2 LED,顯示 0、1、2 ~7 ,然后熄滅;左3 LED,顯示 0、1、2 ~8 ,然后熄滅;最右側(cè) LED,顯示 0、1、2 ~9 ,然后熄滅 然后再開始左1 LED, 顯示 0、1、2~6 如此一直循環(huán);所有情況下,計(jì)數(shù)數(shù)值變化的時(shí)間間隔是1秒,復(fù)位時(shí),所有數(shù)碼管熄滅,復(fù)位后,重新開始計(jì)數(shù)顯示。
2.手工繪制RTL圖
3.Quartus Ⅱ9.0 編譯生成的RTL電路圖

(1)時(shí)間基準(zhǔn)電路
(2)循環(huán)計(jì)數(shù)模塊
(3)計(jì)數(shù)值譯碼顯示模塊

4.程序源代碼
//////////////////////時(shí)間基準(zhǔn)電路/////////////////////// module cnt_sync( CLK , // clock CNTVAL, // counter value OV ); // overflowinput CLK;output [32-1:0] CNTVAL;output OV;parameter MAX_VAL = 50_000_000;reg [32-1:0] CNTVAL;reg OV;always @ (posedge CLK) begin if(CNTVAL >= MAX_VAL) CNTVAL <= 0; else CNTVAL <= CNTVAL + 1'b1;endalways @ (CNTVAL) begin if(CNTVAL == MAX_VAL) OV = 1'b1; else OV = 1'b0;endendmodule ///////////////循環(huán)計(jì)數(shù)模塊/////////////////////////module counter( //對(duì)1s信號(hào)計(jì)數(shù)EN,RST,CLK,M,COU);input RST,EN, CLK;output reg [3:0] COU;output reg [1:0] M;reg [3:0] MAX = 4'b0110;always @ (posedge CLK)if (RST == 1) if (EN == 1) if (COU != MAX) begin COU <= COU + 1'b1; M <= M; end else begin COU <= 4'b0000; M <= M + 1'b1; end else COU <= COU;else begin COU <= 4'b0000; M <= 2'b00; endalways @ (COU) case (M) 2'b00 : MAX = 4'b0110; 2'b01 : MAX = 4'b0111; 2'b10 : MAX = 4'b1000; 2'b11 : MAX = 4'b1001; endcaseendmodule///////////////////計(jì)數(shù)值譯碼顯示模塊///////////////////////module dec_seg( //顯示譯碼M,COU_IN,SEG0,SEG1,SEG2,SEG3);input [1:0] M;input [3:0] COU_IN;output reg [7:0] SEG0;output reg [7:0] SEG1;output reg [7:0] SEG2;output reg [7:0] SEG3;reg [7:0] SEG_data [3:0];always @ (COU_IN)case(COU_IN) //系統(tǒng)輸出編碼表 4'b0000 : SEG_data[M] = 8'b1100_0000; 4'b0001 : SEG_data[M] = 8'b1111_1001; 4'b0010 : SEG_data[M] = 8'b1010_0100; 4'b0011 : SEG_data[M] = 8'b1011_0000; 4'b0100 : SEG_data[M] = 8'b1001_1001; 4'b0101 : SEG_data[M] = 8'b1001_0010; 4'b0110 : SEG_data[M] = 8'b1000_0010; 4'b0111 : SEG_data[M] = 8'b1111_1000; 4'b1000 : SEG_data[M] = 8'b1000_0000; 4'b1001 : SEG_data[M] = 8'b1001_0000; 4'b1010 : SEG_data[M] = 8'b1000_1000; 4'b1011 : SEG_data[M] = 8'b1000_0011; 4'b1100 : SEG_data[M] = 8'b1100_0110; 4'b1101 : SEG_data[M] = 8'b1010_0001; 4'b1110 : SEG_data[M] = 8'b1000_0110; 4'b1111 : SEG_data[M] = 8'b1000_1110;endcasealways @ (M)case (M) //根據(jù)當(dāng)前的計(jì)數(shù)值COU選擇顯示的數(shù)碼管,并關(guān)閉其他數(shù)碼管 2'b00 : begin SEG0 = SEG_data[M];SEG3 = 8'b1111_1111; SEG1 = 8'b1111_1111; SEG2 = 8'b1111_1111; end 2'b01 : begin SEG1 = SEG_data[M];SEG0 = 8'b1111_1111; SEG2 = 8'b1111_1111; SEG3 = 8'b1111_1111; end 2'b10 : begin SEG2 = SEG_data[M];SEG1 = 8'b1111_1111; SEG0 = 8'b1111_1111; SEG3 = 8'b1111_1111; end 2'b11 : begin SEG3 = SEG_data[M];SEG0 = 8'b1111_1111; SEG1 = 8'b1111_1111; SEG2 = 8'b1111_1111; endendcaseendmodule5.Signal Tap 分析

6.視頻鏈接
視頻鏈接
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注