我已经为 fifo 编写了 verilog 代码,使用 fillcount 作为检查它是满还是空的方法。相同的代码有 2 个版本。一个是我有一个单独的总是阻塞读取,写入,空/满,填充计数,一个用于递增指针。这很好用,我已经测试过了,它很好用。
module FIFO (clk, reset, data_in, put, get, data_out, fillcount, empty, full);
parameter DEPTHP2 = 8 ;
parameter WIDTH = 8 ;
input [WIDTH-1:0] data_in;
input put, get, reset, clk;
output fillcount;
output reg [WIDTH-1:0] data_out;
output reg empty, full;
reg [3:0]fillcount ;
reg [WIDTH-1:0] fifo_1[0:DEPTHP2-1];
reg [2:0] rp,wp;
always@(posedge clk or posedge reset)
begin
if( reset )
begin
wp <= 0;
rp <= 0;
end
else
begin
if( !full && put ) wp <= wp + 1;
else wp <= wp;
if( !empty && get ) rp <= rp + 1;
else rp <= rp;
end
end
always @(fillcount)
begin
if(fillcount==0)
empty =1 ;
else
empty=0;
if(fillcount==8)
full=1;
else
full=0;
end
always @(posedge clk or posedge reset)
begin
if( reset )
fillcount <= 0;
else if( (!full && put) && ( !empty && get ) )
fillcount <= fillcount;
else if( !full && put )
fillcount <= fillcount + 1;
else if( !empty && get )
fillcount <= fillcount - 1;
else
fillcount <= fillcount;
end
always @( posedge clk or posedge reset)
begin:Reading
if( reset )
data_out <= 0;
else
begin
if( get && !empty )
data_out <= fifo_1[rp];
else
data_out <= data_out;
end
end
always @(posedge clk)
begin:Writing
if( put && !full )
fifo_1[ wp ] <= data_in;
else
fifo_1[ wp ] <= fifo_1[ wp ];
end
endmodule
另一种方法是我将几个总是影响逻辑的块组合在一起(在我的理解中!!)但它不适用于我在立即写入后尝试读取数据的情况。它通过了所有其他测试用例。
我不确定出了什么问题。如果有人能指出我哪里出错了,那就太好了。
//The code that is not working
always@(posedge clk or posedge reset)
begin:Writing
if(reset)
wp<=0;
else
if( put && !full)
begin
fifo1[wp]<=data_in;
wp<=wp+1;
end
else
begin
fifo1[wp]<=fifo1[wp];
wp<=wp;
end
end
always@(posedge clk or posedge reset)
begin:Reading
if(reset)
begin
rp<=0;
data_out<=0;
end
else
if(get && !empty)
begin
data_out<=fifo1[rp];
rp<=rp+1;
end
else
begin
fifo1[rp]<=fifo1[rp];
rp<=rp;
end
end
always@(posedge clk or posedge reset)
begin:Fillcount
if(reset)
fillcount<=0;
else
if((!full && put ) && ( !empty && get))
fillcount<=fillcount;
else if(!full && put)
fillcount<=fillcount+1;
else if(!empty && get)
fillcount<=fillcount-1;
else
fillcount<=fillcount;
end
always@(fillcount)
begin
full=(fillcount==8);
empty=(fillcount==0);
end
endmodule
另一个问题:据我所知,在verilog中编码的一般方法是使用fsm绘制状态图并使用它们..但是当我尝试为fifo、Tcam或双时钟先进先出。是否有任何方法或方式为这些元素进行编码。
对不起,很长的问题