名稱:可調(diào)定時器設(shè)計Verilog代碼Quartus仿真
軟件:Quartus
語言:Verilog
代碼功能:
設(shè)計一個可調(diào)的定時器,定時時間默認(rèn)為x秒(x=個人學(xué)號%10+5),定時器具有啟動,復(fù)位,到時警告功能(比如點(diǎn)亮一個LED燈)。
要求
1.寫出設(shè)計文件xx(xx命名規(guī)則為tmer姓名首字母2位學(xué)號,如 timer jl12)。
2.會用Quartus軟件建工程并進(jìn)行編譯(編譯完成截圖保存,圖片命名為編譯結(jié)果)。
3.仿真結(jié)果截圖(仿真完成截圖保存,圖片命名為仿真結(jié)果)。
4.工程文件的提交。
FPGA代碼Verilog/VHDL代碼資源下載:www.hdlcode.com
演示視頻:
設(shè)計文檔:
1. 工程文件
2. 程序文件
3. 程序編譯
4. Testbench
5. 仿真圖
部分代碼展示:
//默認(rèn)7秒 module?timer_fjd_42( input?clk,//1KHz時鐘 input?rst_p,//復(fù)位 input?set_key,//按鍵調(diào)時間1~60秒 input?start_key,//啟動 output?reg?led,//led到時警告 output?reg?[1:0]?SEL,//數(shù)碼管位選 output?[7:0]?SEG//數(shù)碼管段選,低電平亮 ); reg?[2:0]?state=3'd0; parameter?s_idle=3'd0; parameter?s_start=3'd1; parameter?s_end=3'd2; wire?[7:0]?second; reg?[7:0]?second_set=8'd7; //按鍵設(shè)計定時時間 always@(posedge?clk?or?posedge?rst_p) if(rst_p==1) second_set<=8'd7;//默認(rèn)7秒 else?if(set_key==1)//按鍵調(diào)時間1~60秒 if(second_set==8'd60) second_set<=8'd1; else second_set<=second_set+8'd1;//累計數(shù) reg?[7:0]?second_cnt=8'd0; always@(posedge?clk?or?posedge?rst_p) if(rst_p==1) state<=s_idle;//復(fù)位 else case(state) s_idle://空閑狀態(tài) if(start_key==1)//啟動按鍵 state<=s_start;//計時 else state<=s_idle; s_start://計時狀態(tài) if(second_cnt==second_set) state<=s_end;//結(jié)束 else state<=s_start;//倒計時 s_end://結(jié)束狀態(tài) state<=s_end;//結(jié)束 default:; endcase always@(posedge?clk?or?posedge?rst_p) if(rst_p==1) led<=0; else if(state==s_end)//結(jié)束狀態(tài) led<=1;//led到時警告 else led<=0; //分頻到1Hz reg?[31:0]?count=32'd0; always@(posedge?clk?or?posedge?rst_p) if(rst_p==1) count<=32'd0; else if(state==s_start)//計時狀態(tài) if(count==32'd1000)//1KHz計數(shù)1000就是1秒 count<=32'd0; else count<=count+32'd1;//計數(shù) else count<=count;//不計數(shù) always@(posedge?clk?or?posedge?rst_p) if(rst_p==1) second_cnt<=8'd0;//復(fù)位,計數(shù)值回到0 else if(state==s_start)//計時狀態(tài) if(count==32'd1000)//1秒計時1次 second_cnt<=second_cnt+8'd1; else second_cnt<=second_cnt; else second_cnt<=second_cnt; assign?second=second_cnt;//秒計時
點(diǎn)擊鏈接獲取代碼文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=546