標(biāo)題: 步長(zhǎng)可變的加減計(jì)數(shù)器 [打印本頁(yè)]
作者: WeTiGY 時(shí)間: 2016-11-25 23:21
標(biāo)題: 步長(zhǎng)可變的加減計(jì)數(shù)器
本帖最后由 WeTiGY 于 2016-11-25 23:28 編輯
實(shí)驗(yàn)六 步長(zhǎng)可變的加減計(jì)數(shù)器一、實(shí)驗(yàn)?zāi)康?/font>
1、掌握加減法計(jì)數(shù)器以及特殊功能計(jì)數(shù)器的設(shè)計(jì)原理;
2、用HDL語(yǔ)言設(shè)計(jì)多功能計(jì)數(shù)器。
二、硬件需求
EDA/SOPC實(shí)驗(yàn)箱一臺(tái)。
三、實(shí)驗(yàn)原理
計(jì)數(shù)器的步長(zhǎng)是指計(jì)數(shù)器每次的改變量。在很多應(yīng)用場(chǎng)合,都希望計(jì)數(shù)器的步長(zhǎng)可變。所謂步長(zhǎng)可變,也就是計(jì)數(shù)器的步長(zhǎng)是一個(gè)不定值,具體是多少是要靠外部干預(yù)的,比如外部給定其步長(zhǎng)為5,那么該計(jì)數(shù)器每次要么增加5,要么減少5,也就是說(shuō)計(jì)數(shù)器每次的改變量是5。這種步長(zhǎng)可變的計(jì)數(shù)器才具有一定的實(shí)際意義,比如在直接數(shù)字頻率合成DDFS中的地址累加器就是一個(gè)步長(zhǎng)可變的遞增計(jì)數(shù)器。
四、實(shí)驗(yàn)內(nèi)容
本實(shí)驗(yàn)要完成的任務(wù)就是設(shè)計(jì)一個(gè)8位的計(jì)數(shù)器,步長(zhǎng)的改變量要求從0~15,實(shí)驗(yàn)中用撥擋開(kāi)關(guān)模塊的SW1A~SW4A來(lái)作為步長(zhǎng)改變量的輸入,用按鍵F1來(lái)控制計(jì)數(shù)器的增減,具體要求為:當(dāng)F1輸入為高時(shí),計(jì)數(shù)器為步長(zhǎng)可變的加計(jì)數(shù)器;當(dāng)F1輸入為低時(shí),計(jì)數(shù)器為步長(zhǎng)可變的減計(jì)數(shù)器。計(jì)數(shù)器輸出的Q值用七段數(shù)碼管模塊來(lái)表示。實(shí)驗(yàn)中計(jì)數(shù)器的時(shí)鐘頻率為了便于眼睛觀察,同上個(gè)實(shí)驗(yàn)一樣用1Hz的時(shí)鐘。
第一個(gè)為分頻模塊:
- module divider_module
- (
- CLK,f_Out
- );
- input CLK;
- output f_Out;
-
- parameter T1s=26'd50_000_000;
- reg [25:0]Count1;
-
- always @ ( posedge CLK )
- if( Count1 == T1s)
- Count1 <= 26'd0;
- else
- Count1 <= Count1 + 1'b1;
-
- reg rf_Out;
- always @ ( posedge CLK )
- if( Count1 >= 26'd0 && Count1 <= 26'd25_000_000)
- rf_Out <= 1'b0;
- else
- rf_Out <= 1'b1;
- assign f_Out = rf_Out;
- endmodule
復(fù)制代碼
第二個(gè)為數(shù)碼管模塊:
- module hex_module
- (
- f_Out,hex_one,hex_two,Q
- );
- input f_Out;
- input [7:0] Q;
- output [6:0] hex_one;
- output [6:0] hex_two;
- parameter _0=7'b0000001, _1=7'b1111001, _2=7'b0010010, _3=7'b0000011, _4=7'b1001100, _5=7'b0100100,
- _6=7'b0100000, _7=7'b0001111, _8=7'b0000000, _9=7'b0000100, _A=7'b0001000, _B=7'b1100000,
- _C=7'b0110001, _D=7'b1000010, _E=7'b0110000, _F=7'b0111000;
-
- reg [7:0] i;
- reg [7:0] u;
- reg [6:0] rhex_one;
- reg [6:0] rhex_two;
- always@(posedge f_Out)
- begin
- i<=Q>>4;
- case(i)
- 8'd0 : rhex_one<=_0; //0
- 8'd1 : rhex_one<=_1; //1
- 8'd2 : rhex_one<=_2; //2
- 8'd3 : rhex_one<=_3; //3
- 8'd4 : rhex_one<=_4; //4
- 8'd5 : rhex_one<=_5; //5
- 8'd6 : rhex_one<=_6; //6
- 8'd7 : rhex_one<=_7; //7
- 8'd8 : rhex_one<=_8; //8
- 8'd9 : rhex_one<=_9; //9
- 8'd10: rhex_one<=_A; //A
- 8'd11: rhex_one<=_B; //B
- 8'd12: rhex_one<=_C; //C
- 8'd13: rhex_one<=_D; //D
- 8'd14: rhex_one<=_E; //E
- 8'd15: rhex_one<=_F; //F
-
- default: rhex_one<=_F; //F
- endcase
- u<=Q&8'h0f;
- case(u)
- 8'd0 : rhex_one<=_0; //0
- 8'd1 : rhex_one<=_1; //1
- 8'd2 : rhex_one<=_2; //2
- 8'd3 : rhex_one<=_3; //3
- 8'd4 : rhex_one<=_4; //4
- 8'd5 : rhex_one<=_5; //5
- 8'd6 : rhex_one<=_6; //6
- 8'd7 : rhex_one<=_7; //7
- 8'd8 : rhex_one<=_8; //8
- 8'd9 : rhex_one<=_9; //9
- 8'd10: rhex_one<=_A; //A
- 8'd11: rhex_one<=_B; //B
- 8'd12: rhex_one<=_C; //C
- 8'd13: rhex_one<=_D; //D
- 8'd14: rhex_one<=_E; //E
- 8'd15: rhex_one<=_F; //F
-
- default: rhex_one<=_F; //F
- endcase
- end
- assign hex_one=rhex_one;
- assign hex_two=rhex_two;
- endmodule
復(fù)制代碼
第三個(gè)為計(jì)數(shù)模塊:
- module ecount_module
- (
- f_Out,F1,D,Q
- );
- input f_Out;
- input F1;
- input [3:0] D;
- output [7:0] Q;
-
- reg [7:0] Q;
- always@(posedge f_Out)
- case(F1)
- 1'b1: begin
- if(Q<8'd255) Q<=Q+D;
- else Q<=8'b0;
- end
- 1'b0: begin
- if(Q>8'd0) Q<=Q-D;
- else Q<=8'd255;
- end
- default: Q<=8'd255;
- endcase
- endmodule
-
-
-
-
復(fù)制代碼
第四個(gè)為頂層模塊:
- module top_module
- (
- CLK,F1,D,hex_one,hex_two
- );
- input CLK;
- input F1;
- input [3:0] D;
- output [6:0] hex_one;
- output [6:0] hex_two;
-
- divider_module u1
- (
- .CLK(CLK),
- .f_Out(f_Out)
- );
-
- wire f_Out;
- ecount_module u2
- (
- .f_Out(f_Out),
- .D(D),
- .F1(F1),
- .Q(Q)
- );
-
- wire [7:0] Q;
- hex_module u3
- (
- .f_Out(f_Out),
- .hex_one(hex_one),
- .hex_two(hex_two),
- .Q(Q)
- );
-
- endmodule
復(fù)制代碼
注:仿真使用20分頻
仿真圖:
snjnsoi.jpg (61.35 KB, 下載次數(shù): 97)
下載附件
2016-11-25 23:20 上傳
作者: dlq0000 時(shí)間: 2019-11-14 14:42
為什么我的仿真結(jié)果都是0啊
作者: 17509086609 時(shí)間: 2019-12-30 00:57
有沒(méi)有安裝包
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |