OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 231|回复: 1

[XILINX] 新手学习vivado软件的ip_FIFO使用,仿真波形有问题

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
5
金钱
5
注册时间
2025-9-14
在线时间
1 小时
发表于 2025-10-11 17:46:46 | 显示全部楼层 |阅读模式
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


{4C9DCB47-9B02-4401-BDA4-FB0D5D394B10}.png
回复

使用道具 举报

4

主题

2134

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
6008
金钱
6008
注册时间
2018-10-21
在线时间
1758 小时
发表于 2025-10-13 09:39:32 | 显示全部楼层
从仿真波形图来看,sys_clk和sys_rst_n波形有问题,一直处于高阻态,这两个信号抓的是哪个模块的,你可以重点检查下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


关闭

原子哥极力推荐上一条 /1 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-10-28 10:36

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表