名稱:通用FIFO設(shè)計(jì)深度8寬度64,verilog仿真(代碼在文末付費(fèi)下載)
軟件:Quartus
語言:verilog
代碼功能:
本代碼為FIFO通用代碼,其他深度和位寬可簡(jiǎn)單修改以下參數(shù)得到:
reg?[63:0]?ram?[7:0];//RAM。深度8,寬度64
使用verilog編寫FIFO,
FIFO為先入先出隊(duì)列,
FIFO深度為8,數(shù)據(jù)寬度為64,
FIFO具有clk,rst_n(異步復(fù)位),wr_en,rd_en,data_in[63:0], data_out[63:0], empty, full信號(hào),
寫數(shù)據(jù)下拍生效,讀數(shù)據(jù)當(dāng)拍生效,
空滿信號(hào)下拍生效,
用verilog編寫簡(jiǎn)單Testbench對(duì)實(shí)驗(yàn)1的FIFO進(jìn)行驗(yàn)證,隨機(jī)生成讀寫信號(hào)(滿足空滿要求),寫數(shù)據(jù)等,通過看波形以及打印判斷讀數(shù)據(jù)正確性。
演示視頻:
FPGA代碼資源下載網(wǎng):hdlcode.com
部分代碼展示
//FIFO深度為8,數(shù)據(jù)寬度為64 module?a_fifo ( input?clk,//時(shí)鐘 input?rst_n,//復(fù)位 input?[63:0]?data_in,//fifo寫數(shù)據(jù) input?wr_en,//寫使能 input?rd_en,//讀使能 output?[63:0]?data_out,//讀數(shù)據(jù) output?empty,//空信號(hào) output?full//滿信號(hào) ); reg?[63:0]?ram?[7:0];//RAM。深度8,寬度64 reg?[3:0]?count=4'd0; reg?[3:0]?rp=4'd0; reg?[3:0]?wp=4'd0; integer?i; always@(posedge?clk?or?negedge?rst_n) if(!rst_n)begin//復(fù)位 wp<=4'd0; rp<=4'd0; count<=4'd0; for(i=0;i<8;i=i+1) ram[i]<=64'b0;//清零 end else case({rd_en,wr_en}) 2'b00:count<=count; 2'b01://單寫FIFO if(~full)begin//未滿 ram[wp]<=data_in;//存入fifo if(wp>=4'd7) wp<=4'd0;//寫地址循環(huán)累加 else wp<=wp+4'd1; count<=count+4'd1; rp<=rp; end 2'b10://單讀FIFO if(~empty)begin//未空 if(rp>=4'd7) rp<=4'd0;//讀地址循環(huán)累加 else rp<=rp+4'd1; count<=count-4'd1; end 2'b11://同時(shí)讀寫FIFO if(empty)begin//FIFO為空,只能寫 ram[wp]<=data_in; if(wp>=4'd7) wp<=4'd0;
設(shè)計(jì)文檔:
1. 工程文件
2. 程序文件
3. 程序編譯
4. Testebnch
5. 仿真圖
仿真圖依次仿真了如下功能:
具體功能1/2/3對(duì)應(yīng)如下:
1.寫FIFO 4次,再讀4次,F(xiàn)IFO讀空
2.寫FIFO 5次,然后同時(shí)讀寫5次,最后讀5次,F(xiàn)IFO讀空
3.連續(xù)寫FIFO 8次,F(xiàn)IFO寫滿
打印信息: