新手入门
积分 5
金钱 5
注册时间 2025-9-14
在线时间 1 小时
1 金钱
跟着正点原子视频学习的ip核之FIFO,仿真阶段有问题不知道怎么解决。这是顶层模块代码,例化了两个ip核和读写模块。
module ip_fifo(
input sys_clk,
input sys_rst_n
);
wire clk_50m ;
wire clk_100m ;
wire locked ;
wire rst_n ;
wire [7:0] fifo_wr_data ;
wire fifo_wr_en ;
wire fifo_rd_en ;
wire [7:0] fifo_rd_data ;
wire full ;
wire almost_full ;
wire empty ;
wire almost_empty ;
wire [7:0] rd_data_count ;
wire [7:0] wr_data_count ;
wire wr_rst_busy ;
wire rd_rst_busy ;
assign rst_n=sys_rst_n&locked;
clk_wiz_0 u_clk_wiz_0(
.clk_out1 (clk_50m), // output clk_out1
.clk_out2 (clk_100m), // output clk_out2
.locked (locked), // output locked
.clk_in1 (sys_clk)
);
fifo_generator_0 u_fifo_generator_0 (
.rst (~rst_n), // input wire rst
.wr_clk (clk_50m), // input wire wr_clk
.rd_clk (clk_100m), // input wire rd_clk
.din (fifo_wr_data), // input wire [7 : 0] din
.wr_en (fifo_wr_en), // input wire wr_en
.rd_en (fifo_rd_en), // input wire rd_en
.dout (fifo_rd_data), // output wire [7 : 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
.rd_data_count (rd_data_count), // output wire [7 : 0] rd_data_count
.wr_data_count (wr_data_count), // output wire [7 : 0] wr_data_count
.wr_rst_busy (wr_rst_busy), // output wire wr_rst_busy
.rd_rst_busy (rd_rst_busy) // output wire rd_rst_busy
);
fifo_wr u_fifo_wr(
. clk_wr ( clk_50m ),
. rst_n ( rst_n ),
. empty ( empty ),
. wr_rst_busy ( wr_rst_busy ),
. almost_full ( almost_full ),
. fifo_wr_data ( fifo_wr_data),
. fifo_wr_en ( fifo_wr_en )
);
fifo_rd u_fifo_rd(
.clk_rd (clk_100m ),
.rst_n (rst_n ),
.full (full ),
.almost_empty (almost_empty),
.rd_rst_busy (rd_rst_busy),
.fifo_rd_data (fifo_rd_data),
.fifo_rd_en (fifo_rd_en )
);
endmodule
这是写模块代码。
module fifo_wr(
input clk_wr ,
input rst_n ,
input empty ,
input wr_rst_busy ,
input almost_full ,
output reg [7:0] fifo_wr_data ,
output reg fifo_wr_en
);
reg empty_d0;
reg empty_d1;
always @(posedge clk_wr or negedge rst_n)begin
if(!rst_n)begin
empty_d0<=1'b0;
empty_d1<=1'b0;
end
else begin
empty_d0<=empty;
empty_d1<=empty_d0;
end
end
always @(posedge clk_wr or negedge rst_n)begin
if(!rst_n)
fifo_wr_en<=1'b0;
else if(!wr_rst_busy&&empty_d1)
fifo_wr_en<=1'b1;
else if(almost_full)
fifo_wr_en<=1'b0;
end
always @(posedge clk_wr or negedge rst_n)begin
if(!rst_n)
fifo_wr_data<=8'b0;
else if(fifo_wr_en&&fifo_wr_data<8'd253)
fifo_wr_data<=fifo_wr_data+8'b1;
else fifo_wr_data<=8'b0;
end
endmodule
这是读模块代码。
module fifo_rd(
input clk_rd,
input rst_n,
input full,
input almost_empty,
input rd_rst_busy,
input [7:0] fifo_rd_data,
output reg fifo_rd_en
);
reg full_d0;
reg full_d1;
always @(posedge clk_rd or negedge rst_n)begin
if(!rst_n)begin
full_d0<=1'b0;
full_d1<=1'b0;
end
else begin
full_d0<=full;
full_d1<=full_d0;
end
end
always @(posedge clk_rd or negedge rst_n)begin
if(!rst_n)
fifo_rd_en<=1'b0;
else if(!rd_rst_busy&&full_d1)
fifo_rd_en<=1'b1;
else if(almost_empty)
fifo_rd_en<=1'b0;
end
endmodule
这是testbench
`timescale 1ns / 1ps
module tb_ip_fifo( );
reg sys_clk;
reg sys_rst_n;
initial begin
sys_clk=1'b0;
sys_rst_n=1'b0;
#200
sys_rst_n=1'b1;
end
always #10 sys_clk=~sys_clk;
ip_fifo u_ip_fifo(
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n)
);
endmodule
我来回答