fillcount를 사용하여 fifo에 대해 verilog 코드를 작성하여 전체 또는 비어 있는지 확인하는 수단으로 확인했습니다. 동일한 코드에는 두 가지 버전이 있습니다. 하나는 항상 읽기, 쓰기, 빈/전체, fillcount 및 포인터를 증가시키기위한 블록으로 항상 seprate를 가지고 있습니다. 이것은 정상적으로 작동하고 테스트를 거쳤습니다. 나는 (나의 이해!에서) 논리를 effectng하는 함께 블록 항상 몇 가지를 조합 한 곳다른 스타일로 작성된 Verilog FIFO 코드 .. 작동하지 않는 코드와 작동하지 않는 코드가 있습니다. 누군가가 설명 할 수 있습니다.
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;
[email protected](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
또 다른 방법은하지만 immediately.It 통과 작성 후 데이터를 읽을 때이 경우 작동하지 않습니다 다른 모든 테스트 케이스.
내가 무엇이 잘못되었는지 잘 모르겠다. 누군가 내가 잘못 가고있는 부분을 지적 할 수 있다면 좋을 것이다.
//The code that is not working
[email protected](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
[email protected](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
[email protected](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
[email protected](fillcount)
begin
full=(fillcount==8);
empty=(fillcount==0);
end
endmodule
또 다른 질문 : 지금까지 내가 배운대로를 Verilog 코딩의 일반적인 방법은 상태 다이어그램을 그리고 I가 코딩 할 때 내가 힘든 시간을했다 them..But 사용하는 FSM을 사용하는 것입니다 FIFO, Tcam 또는 double clock fifo와 같은 메모리 요소. 이러한 요소에 대한 코딩 방법이나 접근 방법이 있습니까?
fifo1[rp]<=fifo1[rp];
당신이 일이 괜찮 작동해야처럼 보이는 것을 제거하는 경우 : 긴 질문 당신이 우발적으로 당신의 FIFO 메모리에 작성하는 당신의 "읽기"과정에서