我无法将输出写入verilog中的文本文件。请检查有什么问题

我无法将输出写入verilog中的文本文件。请检查有什么问题,verilog,fwrite,xilinx,test-bench,Verilog,Fwrite,Xilinx,Test Bench,$fclose()关闭文件;通常会忽略进一步写入$fclose()通常是您希望在模拟器中调用的最后一个操作之一;通常在$finish语句之前 module fir_tb; // Inputs reg clk; reg reset; reg [7:0] inp; reg [15:0]rom[1:8001]; reg [15:0]addr=0; // Outputs wire [7:0] outp; // Instant

$fclose()
关闭文件;通常会忽略进一步写入
$fclose()
通常是您希望在模拟器中调用的最后一个操作之一;通常在
$finish
语句之前

module fir_tb;

    // Inputs
    reg clk;
    reg reset;
    reg [7:0] inp;
     reg [15:0]rom[1:8001];
    reg [15:0]addr=0;

    // Outputs
    wire [7:0] outp;

    // Instantiate the Unit Under Test (UUT)
    fir uut (
        .clk(clk), 
        .reset(reset), 
        .inp(inp), 
        .outp(outp)
    );




    initial 
  begin
      $readmemb("file_out_flute.txt",rom);
      reset=0;

      inp ='b0;
      #60;

      //$display("rom size is ",rom);
  end
  always @(posedge clk)begin
      inp = rom[addr]>>1;
      addr = addr + 1;
      if (addr==8000) ;//$finish;
  end
       initial 
  begin
      clk=1'b1;
      forever #10 clk=~clk;
  end


    integer f;
  initial begin
   f = $fopen("filter_output.txt","w");
     end

     always @(posedge clk)
     begin
     $fwrite(f,"%b\n",outp);

    $fclose(f);  


  end
endmodule
整数f;
初始开始
f=$fopen(“filter_output.txt”,“w”);

#100; // 您正使用此语句在
initial
块的最开始处触发
posedge clk
。将其更改为
clk=1'b0并重试。同时改进代码缩进并添加更多详细信息。
integer f;初始开始f=$fopen(“filter_output.txt”,“w”)//#100; // 您可以将
$fclose(f)放入$完成在不同位置或更改模拟延迟。关键是一旦调用了
$fclose
,您将无法写入该文件。
integer f;
initial begin
  f = $fopen("filter_output.txt","w");
  #100; // <== simulation run time
  $fclose(f);
  $finish; // <== end simulation
end

always @(posedge clk)
begin
  $fwrite(f,"%b\n",outp);
end