verilogのデータをモニターして結果をcsvファイルにダンプしようと思った。 データを取得開始するタイミングは、if($realtime >= 時間)で行うようにした。
module dut( input clk, input rst_n, input [3:0] add, input we, input [7:0] wdata, output [7:0] rdata ); reg [7:0] array [0:15]; reg [4:0] i; reg [7:0] rdata_r; initial begin for (i=0; i<=15; i=i+1)begin array[i] = 8'h0; end end always@(posedge clk or negedge rst_n)begin if(we)begin array[add] <= wdata; rdata_r <= array[add]; end end assign rdata = rdata_r; endmodule
module top( ・ ・ ・ bind dut monitor u_monitor(.*); endmodule module monitor ( input clk, input rst_n, input we, input [3:0] add, input [7:0] rdata_r ); //monitor integer fp; logic [3:0] add_1dly; int cnt_x=0; int cnt_y=0; initial begin fp = $fopen("data_1.csv"); $fdisplay(fp,"Output data monitor,"); end always@(posedge clk or negedge rst_n)begin add_1dly <= add; if($realtime >= 3.5us && $realtime <= 16.1us)begin $fdisplay(fp,"%t,%d,%d,%h,%h",$realtime,cnt_x,cnt_y,add_1dly,rdata_r); if (cnt_x == 15)begin cnt_x = 0; cnt_y +=1; end else begin cnt_x +=1; end end end endmodule