简体   繁体   中英

How to save data using $fwrite() command from verilog test bench such that the values of the multiple outputs save in adjacent columns of a csv file?

I am trying to write 256 different outputs of a Verilog module through testbench using $fwrite . I do not know how to save these 256 outputs in 256 columns. If there's an option to put headings on the top of each column, that would help a lot.

I have tried to do it myself, but all the outputs save in a single column with a space in between.

fft uut(
.fft0_r(fft0_r),
.fft1_r(fft1_r),
.fft2_r(fft2_r),
.fft3_r(fft3_r),
.fft4_r(fft4_r),
.fft5_r(fft5_r),
.fft6_r(fft6_r),
.fft7_r(fft7_r),
.fft8_r(fft8_r)
);

wire [13:0] fft0_r;
wire [13:0] fft1_r;
wire [13:0] fft2_r;
wire [13:0] fft3_r;
wire [13:0] fft4_r;
wire [13:0] fft5_r;
wire [13:0] fft6_r;
wire [13:0] fft7_r;
wire [13:0] fft8_r;

integer out_rfft;

out_rfft =$fopen("out_rfft.csv");

$fwrite(out_rfft,"%d %d %d %d %d %d %d %d %d", fft0_r, fft1_r, fft2_r, fft3_r, fft4_r,fft5_r,fft6_r,fft7_r,fft8_r);

Expected Result: 8x outputs saving in 8 columns of out_rfft.csv

Actual Result: 8x outputs saving in 1 columns of out_rfft.csv

There is nothing in Verilog that does automatic CSV generation—you need to write out every needed character. Just changes the spaces in your format string to commas.

$fwrite(out_rfft,"%d,%d,%d,%d,%d,%d,%d,%d,%d\n", fft0_r, fft1_r, fft2_r, fft3_r, fft4_r,fft5_r,fft6_r,fft7_r,fft8_r);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM