这是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