4.异步fifo
(2)带同步复位信号和标志位
读写频率比为2:1
module ID_fifo1(rst,wr_clk,rd_clk,din,wr_en,rd_en,dout,full,empty,almost_full,almost_empty,valid);
input rst;
input wr_clk;
input rd_clk;
input [7:0] din;
input wr_en;
input rd_en;
output [3:0] dout;
output full;
output empty;
output almost_full;
output almost_empty;
output valid;
reg [7:0] din1;
always @(posedge wr_clk or posedge rst)//异步fifo只能异步复位
begin
if(rst)
din1 <= 8'd0;
else
din1 <= din;
end
fifo_8_16_rst f1 (
.rst(rst), // input wire rst
.wr_clk(wr_clk), // input wire wr_clk
.rd_clk(rd_clk), // input wire rd_clk
.din(din1), // input wire [7 : 0] din
.wr_en(wr_en), // input wire wr_en
.rd_en(rd_en), // input wire rd_en
.dout(dout), // output wire [3 : 0] dout
.full(full), // output wire full
.almost_full(almost_full), // output wire almost_full
.empty(empty), // output wire empty
.almost_empty(almost_empty), // output wire almost_empty
.valid(valid) // output wire valid
);
endmodule
module tb_ID_fifo1;
reg rst,wr_clk,rd_clk;
reg [7:0] din;
reg wr_en,rd_en;
wire [3:0] dout;
wire full,empty,almost_full,almost_empty,valid;
initial begin
rst=1'b1;
wr_clk=1'b0;
rd_clk=1'b0;
din=8'd0;
wr_en=1'b1;//写
rd_en=1'b0;
#160
rst=1'b0;
#400
wr_en=1'b0;//读
rd_en=1'b1;
end
always #20 wr_clk = ~wr_clk;
always #10 rd_clk = ~rd_clk;
always #40 din = din + 1'b1;
ID_fifo1 i1(.rst(rst),
.wr_clk(wr_clk),
.rd_clk(rd_clk),
.din(din),
.wr_en(wr_en),
.rd_en(rd_en),
.dout(dout),
.full(full),
.empty(empty),
.almost_full(almost_full),
.almost_empty(almost_empty),
.valid(valid));
endmodule
可以看出,在rst置零后的第4个写时钟上升沿(本来是3个,因为赋值语句增加了一级延时)才能开始写入,即300ns的位置;在540写入最后一个0c;在570开始读取,850读取结束;在rst异步复位有效的情况下,full、empty、almost_full、almost_empty都置1,dout置零;
读写频率比为4:3
一样是4个周期的写入延时;
(3)带同步复位信号和标志位+输出寄存器
加入寄存器后增加了一级延时;
(4)带同步复位信号和标志位+FWFT
valid信号提前置1