首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >verilog异步FIFO向导

verilog异步FIFO向导
EN

Stack Overflow用户
提问于 2014-06-28 04:02:30
回答 1查看 562关注 0票数 0

如何使用“读启用”将信号正确地输出到引脚上?我使用的是ZyBo板和FIFO生成器向导。我需要一个异步的,连续的写入一个FIFO和从FIFO读取。这就是为什么我需要一个write_enable信号和read_enable信号。但是,我无法从FIFO中读到。我检查以确保FIFO不是空的,并且read_enable是断言的。我通过将32位字串行化到数据引脚上来读取FIFO。(它交替从序列化到引脚I和引脚Q)。如何确保我正在读取FIFO并将序列化的数据输出到一个引脚上?以下是我的代码:

代码语言:javascript
复制
// Wires and registers related to data capturing 
wire        capture_clk;
reg [31:0]  capture_data;
wire        capture_en;
reg [4:0]   slowdown;
wire        capture_full;

reg            capture_open;
reg            capture_open_cross;
reg            capture_has_been_full;
reg            capture_has_been_nonfull;
reg            has_been_full_cross;
reg            has_been_full;

// Data capture section
// ====================

always @(posedge capture_clk)
  begin
if (capture_en)
  capture_data <= user_w_write_32_data; // Data source being read from a file

// The slowdown register limits the data pace to 1/32 the bus_clk
// when capture_clk = bus_clk. This is necessary, because the
// core in the evaluation kit is configured for simplicity, and
// not for performance. Sustained data rates of 200 MB/sec are
// easily reached with performance-oriented setting.
// The slowdown register has no function in a real-life application.
slowdown <= slowdown + 1;

// capture_has_been_full remembers that the FIFO has been full
// until the file is closed. capture_has_been_nonfull prevents
// capture_has_been_full to respond to the initial full condition
// every FIFO displays on reset.

if (!capture_full)
  capture_has_been_nonfull <= 1;
else if (!capture_open)
  capture_has_been_nonfull <= 0;

if (capture_full && capture_has_been_nonfull)
  capture_has_been_full <= 1;
else if (!capture_open)
  capture_has_been_full <= 0;

  end

// The dependency on slowdown is only for bogus data
assign capture_en = capture_open && !capture_full && 
             !capture_has_been_full &&
             (slowdown == 0);

// Clock crossing logic: bus_clk -> capture_clk
always @(posedge capture_clk)
  begin
capture_open_cross <= user_r_read_32_open;
capture_open <= capture_open_cross;
  end

// Clock crossing logic: capture_clk -> bus_clk
always @(posedge bus_clk)
  begin
has_been_full_cross <= capture_has_been_full;
has_been_full <= has_been_full_cross;
  end

// The user_r_read_32_eof signal is required to go from '0' to '1' only on
// a clock cycle following an asserted read enable, according to Xillybus'
// core API. This is assured, since it's a logical AND between
// user_r_read_32_empty and has_been_full. has_been_full goes high when the
// FIFO is full, so it's guaranteed that user_r_read_32_empty is low when
// that happens. On the other hand, user_r_read_32_empty is a FIFO's empty
// signal, which naturally meets the requirement.

assign user_r_read_32_eof = user_r_read_32_empty && has_been_full;
assign user_w_write_32_full = 0;

// The data capture clock here is bus_clk for simplicity, but clock domain
// crossing is done properly, so capture_clk can be an independent clock
// without any other changes.

assign capture_clk = bus_clk;

async_fifo_32x512 fifo_32 //FIFO created using Xilinx FIFO Generator Wizard
  (
    .rst(!user_r_read_32_open),
    .wr_clk(capture_clk),
    .rd_clk(bus_clk),
    .din(capture_data),
    .wr_en(capture_en),
    .rd_en(user_r_read_32_rden),
    .dout(user_r_read_32_data),
    .full(capture_full),
    .empty(user_r_read_32_empty)
    );

    reg Q_en = 1'b0; //starting value is 0 because first 32bit is I
    reg [31:0] data_outI = 32'd0;
    reg [31:0] data_outQ = 32'd0;
    reg I = 1'b0;
    reg Q = 1'b0;
    reg counter_32_shift = 6'b000000;
    reg temp = 1'b0;

    always @(posedge bus_clk) begin
        if(user_r_read_32_empty == 1'b0 && user_r_read_32_rden == 1'b1)begin //if something in FIFO
            if(Q_en == 1'b0) begin //output onto pin I
                if(counter_32_shift == 6'b000000) begin
                    data_outI <= user_r_read_32_data;
                end else if(counter_32_shift != 5'd32) begin
                    I <= data_outI[0];
                    data_outI <= (data_outI >> 1);
                    Q <= data_outQ[0];
                    data_outQ <= (data_outQ >> 1);
                    counter_32_shift <= counter_32_shift + 1'b1;
                end else begin //counter_32_shift == 32
                    I <= data_outI[0];
                    data_outI <= (data_outI >> 1);
                    Q <= data_outQ[0];
                    data_outQ <= (data_outQ >> 1);
                    counter_32_shift <= 6'd0;
                    Q_en <= ~Q_en;
                end
            end else if(Q_en == 1'b1) begin //Output onto pin Q
                if(counter_32_shift == 6'd0) begin
                    data_outQ <= user_r_read_32_data;
                end else if(counter_32_shift != 6'd32) begin
                    I <= data_outI[0];
                    data_outI <= (data_outI >> 1);
                    Q <= data_outQ[0];
                    data_outQ <= (data_outQ >> 1);
                    counter_32_shift <= counter_32_shift + 1'b1;
                end else begin //counter_32_shift == 32
                    I = data_outI[0];
                    data_outI <= (data_outI >> 1);
                    Q = data_outQ[0];
                    data_outQ <= (data_outQ >> 1);
                    counter_32_shift <= 6'd0;
                    Q_en <= ~Q_en;
                end
            end// end Q_en compare
        end //end check if FIFO empty
    end //end always

提前感谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-29 19:00:16

您需要更好地设计您编写时钟逻辑的方式。

例如,在您的代码中,只有当fifo不为空时才会写入I和Q,这是不正确的。

您需要一个模块:

  • 从fifo获取32位值,存储它,然后将它序列化成一个32周期的引脚。
  • 一旦从fifo读取了一个值,它就需要继续序列化,而不管fifo是否为空(当您输入一个新的32位值时,您只关心fifo的状态)。
  • 只有在当前不执行序列化时才接受新值。

从你的上一个问题开始,设计看起来正在取得进展,但是你还没有得到正确的逻辑。尝试使用波形调试器,以更好地理解为什么它的工作方式不符合您的预期。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24463454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档