Sirius丶天狼星 2025-11-17 22:02 采纳率: 0%
浏览 5

想问问用vivado仿真FIR滤波器时输出波形一直value为x怎么办?

这是fir_top.v文件

// fir_top.v
module fir_top (
    input        clk,
    input        rst,
    input        ce,          
    input  [15:0] din,
    output [15:0] dout,
    output       m_tvalid_debug,
    output [23:0] fir_dout_full_debug
);

wire [23:0] fir_dout_full; 
wire        tready;
wire        m_tvalid;

fir_compiler_0 your_fir_inst (
    .aclk(clk),
    .s_axis_data_tvalid(ce),
    .s_axis_data_tready(tready),
    .s_axis_data_tdata(din),
    .m_axis_data_tvalid(m_tvalid),
    .m_axis_data_tdata(fir_dout_full)
);


assign dout = fir_dout_full[23:8]; 
assign m_tvalid_debug = m_tvalid;
assign fir_dout_full_debug = fir_dout_full;

endmodule

这是tb_fir_top.sv文件

// tb_fir_top.sv
`timescale 1ns / 1ps

module tb_fir_top;  

logic clk = 0;
logic rst = 0;
logic ce = 0;
logic signed [15:0] din;
logic signed [15:0] dout;

logic m_tvalid;
logic [23:0] m_tdata;

// 50 MHz clock (20 ns period)
always #10 clk = ~clk;

// Counter for 48 kHz sample enable
logic [31:0] counter = 0;
always @(posedge clk) begin
    if (counter >= 20832) begin
        ce <= 1'b1;
        counter <= 32'd0;
    end else begin
        ce <= 1'b0;
        counter <= counter + 1;
    end
end

fir_top uut (
    .clk(clk),
    .rst(rst),
    .ce(ce),
    .din(din),
    .dout(dout),
    .m_tvalid_debug(m_tvalid),
    .fir_dout_full_debug(m_tdata)
);

// === Signal generation ===
integer i = 0;
real t, sample_real;
parameter real FS = 48000.0;
parameter real F1 = 10000.0;
parameter real F2 = 20000.0;

always @(posedge clk) begin
    if (ce) begin
        t = real'(i) / FS;
        sample_real = 0.8 * ($sin(2 * 3.14159265 * F1 * t) + $sin(2 * 3.14159265 * F2 * t));
        din <= shortint'($rtoi(sample_real * 32767.0));
        i <= i + 1;
    end
end

// Simulation control
initial begin
    rst = 1'b1;
    #100;
    rst = 1'b0;
    #10_000_000;
    $display("Simulation finished.");
    $finish;
end

// File I/O
integer din_file, dout_file;
initial begin
    din_file = $fopen("din.txt", "w");
    dout_file = $fopen("dout.txt", "w");
    if (!din_file || !dout_file) begin
        $display("Error: Cannot open output files!");
        $finish;
    end
end

always @(posedge clk) begin
    if (ce) begin
        $fdisplay(din_file, "%d", $signed(din));
        $fdisplay(dout_file, "%d", $signed(dout));
    end
end

always @(posedge clk) begin
    if (m_tvalid && !$isunknown(m_tdata)) begin
        $display("Time=%0t | Output Valid | Value=%d", $time, m_tdata);
    end
end
// ===================================================================

final begin
    $fclose(din_file);
    $fclose(dout_file);
end

endmodule

创建的IP核他的Coefficient Vector为-23, 24, 0, -31, 37, 0, -55, 67, 0, -98, 117, 0, -164, 193, 0, -263, 305, 0, -406, 468, 0, -622, 719, 0, -977, 1156, 0, -1709, 2180, 0, -4479, 9017, 21855, 9017, -4479, 0, 2180, -1709, 0, 1156, -977, 0, 719, -622, 0, 468, -406, 0, 305, -263, 0, 193, -164, 0, 117, -98, 0, 67, -55, 0, 37, -31, 0, 24, -23
为什么我仿真出来的输出波形是一条直线value为x

  • 写回答

3条回答 默认 最新

  • 紫雾凌寒 新星创作者: 人工智能技术领域 2025-11-17 22:11
    关注

    让 “紫雾凌寒” 来帮你回答,本回答结合 DeepSeek

    如果还有问题,请评论或点击头像私信,如果有帮助到您, 请关注、采纳、点赞

    1. 关键点分析
      - 从提供的代码来看,模块fir_top定义不完整。缺少输入信号的完整定义以及输出信号的定义。
      - 输出波形一直为x,可能原因有:
      • 电路存在未初始化或未驱动的信号。
      • 仿真激励设置不正确,没有给模块提供有效的输入信号来驱动其正常工作。
      • 模块内部逻辑存在错误,例如组合逻辑中存在锁存器,或者时序逻辑的状态转移不正确等。
    2. 解决方案
      - 补充完整模块定义
      verilog module fir_top ( input clk, input rst, input [N - 1:0] in_data, // 假设输入数据位宽为N output reg [M - 1:0] out_data // 假设输出数据位宽为M ); // FIR滤波器系数数组,假设系数个数为K reg [15:0] coeffs[K - 1:0]; // 延迟线数组,假设延迟阶数为N reg [15:0] delays[N - 1:0]; always @(posedge clk or posedge rst) begin if (rst) begin for (int i = 0; i < N; i = i + 1) begin delays[i] <= 16'd0; end end else begin delays[0] <= in_data; for (int i = 1; i < N; i = i + 1) begin delays[i] <= delays[i - 1]; end end end always @(*) begin out_data = 16'd0; for (int i = 0; i < K; i = i + 1) begin out_data = out_data + delays[i] * coeffs[i]; end end endmodule
      - 编写正确的仿真激励
      verilog module tb_fir_top; reg clk; reg rst; reg [15:0] in_data; wire [15:0] out_data; fir_top uut ( .clk(clk), .rst(rst), .in_data(in_data), .out_data(out_data) ); initial begin clk = 0; forever #5 clk = ~clk; // 10ns周期的时钟 end initial begin rst = 1; in_data = 16'd0; #20; rst = 0; // 提供一系列输入数据进行测试 for (int i = 0; i < 100; i = i + 1) begin in_data = i; #10; end $stop; end endmodule
    3. 不同解决方案的优缺点
      - 补充完整模块定义
      • 优点:使模块功能完整,能够正确实现FIR滤波器的功能逻辑。
      • 缺点:需要对FIR滤波器的原理有深入理解,准确设置系数数组、延迟线等参数。
      • 编写正确的仿真激励
      • 优点:可以验证模块在不同输入情况下的输出是否正确,便于调试。
      • 缺点:激励的设计依赖于对模块功能的了解,如果模块功能复杂,激励编写可能会比较繁琐。
    4. 总结
      - 首先要确保fir_top模块定义完整,包括正确的输入输出信号以及内部逻辑的实现。
      - 然后编写合适的仿真激励来驱动模块,观察输出波形。通过逐步检查模块内部逻辑和激励设置,找出导致输出波形为x的原因并进行修正。

    请注意,上述代码中的位宽NM以及系数个数K等是假设值,实际应用中需要根据具体的FIR滤波器设计进行调整。

    希望以上解答对您有所帮助。如果您有任何疑问,欢迎在评论区提出。

    评论

报告相同问题?

问题事件

  • 创建了问题 11月17日