1.创建 FIFO
其他一路默认即可, Finish后, 打开FIFO_Ctrl.v就可以看到FIFO接口了,如下图:
2. FIFO接口解说
module FIFO_CTRL (
clock, //FIFO所使用clock
data, //准备写进FIFO的数据
rdreq, //FIFO读取请求, 高有效
wrreq, //FIFO写入请求, 高有效
empty, //FIFO空标志, 高有效
full, //FIFO满标志, 高有效
q, //准备读取FIFO的数据
usedw); //FIFO中所存数据的数量,当FIFO进入的时候,会增加;当FIFO读取的时候,
3. 测试FIFO
我采用友晶的DE0 FPGA Board来测试的,使用Quartus II 10.1 Tool编译
module DE0_TOP
(
Clock Input
CLOCK_50, // 50 MHz
CLOCK_50_2, // 50 MHz
Push Button
BUTTON, // Pushbutton[2:0]
DPDT Switch
SW, // Toggle Switch[9:0]
7-SEG Dispaly
HEX0_D, // Seven Segment Digit 0
HEX0_DP, // Seven Segment Digit DP 0
HEX1_D, // Seven Segment Digit 1
HEX1_DP, // Seven Segment Digit DP 1
HEX2_D, // Seven Segment Digit 2
HEX2_DP, // Seven Segment Digit DP 2
HEX3_D, // Seven Segment Digit 3
HEX3_DP, // Seven Segment Digit DP 3
LED
LEDG, // LED Green[9:0]
);
Clock Input
input CLOCK_50; // 50 MHz
input CLOCK_50_2; // 50 MHz
Push Button
input [2:0] BUTTON; // Pushbutton[2:0]
DPDT Switch
input [9:0] SW; // Toggle Switch[9:0]
7-SEG Dispaly
output [6:0] HEX0_D; // Seven Segment Digit 0
output HEX0_DP; // Seven Segment Digit DP 0
output [6:0] HEX1_D; // Seven Segment Digit 1
output HEX1_DP; // Seven Segment Digit DP 1
output [6:0] HEX2_D; // Seven Segment Digit 2
output HEX2_DP; // Seven Segment Digit DP 2
output [6:0] HEX3_D; // Seven Segment Digit 3
output HEX3_DP; // Seven Segment Digit DP 3
LED
output [9:0] LEDG; // LED Green[9:0]
//=======================================================
// REG/WIRE declarations
//=======================================================
//=======================================================
// Structural coding
//=======================================================
wire [7:0] writedata;
wire read_request;
wire write_request;
wire fifo_empty;
wire fifo_full;
wire [7:0] readdata;
wire rst_n;
wire [7:0] fifo_usedw;
assign rst_n = BUTTON[0];
reg [23:0] cnt;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt <= 0;
else
cnt <= cnt + 1;
end
wire fifo_clk;
assign fifo_clk = cnt[23];
FIFO_CTRL u0(
.clock(fifo_clk),
.data(writedata),
.rdreq(read_request),
.wrreq(write_request),
.empty(fifo_empty),
.full(fifo_full),
.q(readdata),
.usedw(fifo_usedw));
assign clk = CLOCK_50;
assign read_request = SW[0];
assign write_request = ~SW[0];
assign LEDG[0] = fifo_empty;
assign LEDG[1] = fifo_full;
assign writedata[7:0] = SW[8:1];
SEG7_LUT u1(
.oSEG(HEX0_D),
.oSEG_DP(),
.iDIG(fifo_usedw[3:0]));
SEG7_LUT u2(
.oSEG(HEX1_D),
.oSEG_DP(),
.iDIG(fifo_usedw[7:4]));
SEG7_LUT u3(
.oSEG(HEX2_D),
.oSEG_DP(),
.iDIG(readdata[3:0]));
SEG7_LUT u4(
.oSEG(HEX3_D),
.oSEG_DP(),
.iDIG(readdata[7:4]));
assign HEX0_DP = 1'bz;
assign HEX1_DP = 1'bz;
assign HEX2_DP = 1'bz;
assign HEX3_DP = 1'bz;
endmodule
4. 测试结果:
当SW[0] = 0时,把SW[8:1]的值写入FIFO, {HEX1,HEX0} 显示FIFO已经存在的数据量, 写够256个后, LEDG[1]亮
当SW[0] = 1时,读取FIFO中的数据到{HEX3,HEX2}中去, {HEX1,HEX0}显示剩余的数据量, 读取完后, LEDG[0]亮