UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor vivian07593
Visitor
321 Views
Registered: ‎03-21-2019

write file about output data

I want to write a txt file to store the output data. In the past, I used $fwrite to write the file, it could be wrok. In this time, I use the same way but it's not work.

0 Kudos
8 Replies
Scholar dgisselq
Scholar
310 Views
Registered: ‎05-21-2015

Re: write file about output data

@vivian07593,

That $fwrite call only ever works in simulation.  You'll need to find another method to get data in or out of your design when its actually within an FPGA.  Some popular options include:

  • Verifying that your design works using a combination of formal verification and simulation, and then dropping the need for file I/O entirely
  • Exporting your data over a network
  • Using a CPU to copy memory from within your design to a file on an SD-card or some such on your board
  • Or even my own personal favorite: using a debugging bus, basically a serial port to internal WB bus, that you can then read or write via software from your host computer external to your board.  (You might need a WB to AXI bridge ...)

Dan

0 Kudos
Explorer
Explorer
306 Views
Registered: ‎03-17-2011

Re: write file about output data

Hello @vivian07593 ,

you don't give much details when saying it doesn't work. Is your file created but empty?

Moreover, did you simulate this and opened the waveforms? How's the clock? I think there is a problem as the reg clk is driven in 2 different processes.

I'd add some $display statement in your TB.

 

--Sebastien
0 Kudos
Visitor vivian07593
Visitor
296 Views
Registered: ‎03-21-2019

Re: write file about output data

Yes, my file is created but is empty and I checked the waveform it has correct output data
0 Kudos
Explorer
Explorer
278 Views
Registered: ‎03-17-2011

Re: write file about output data

As I said, try using the $display to debug. Is your task LHwrite executed at each clock period? maybe display "L"-(bin[i]*8'h4) as well.

--Sebastien
0 Kudos
Visitor vivian07593
Visitor
262 Views
Registered: ‎03-21-2019

Re: write file about output data

I have  checked the data through $display. And the task is executed at each clock cycle successfuly. And I have found out a problem in $fwrite. If I write $fwrite(write_out_file,"%s ", "L"-(bin[i]*8'h4)); then file will be empty. But if I write  $fwrite(write_out_file,"%s %s ", ".. ", "L"-(bin[i]*8'h4)); then the file will be written with two dots ".." along with H and L. So this won't write file unless there is another string added in the line along with H and L. Is there any work around this issue? I can print ..H..L..H..L etc. but I want to save as HLHL etc.

 

0 Kudos
Explorer
Explorer
246 Views
Registered: ‎03-17-2011

Re: write file about output data

I gues you're missing how a $fwrite should be used.

try this. (there might be a nicer way to do it but i have no time to check.

 

 

    task LHwrite (input integer bin, input integer length);
    integer i;
        for (i=length-1; i>=0; i=i-1)
        begin
          if (bin[i] === 1'b1)
             $fwrite(write_out_file,"H");
          else
             $fwrite(write_out_file,"L");
          if(i==0)
            $fwrite(write_out_file,"\n");
        end
    
    endtask 
    

 

--Sebastien
0 Kudos
226 Views
Registered: ‎10-06-2018

Re: write file about output data

if your output is keep on changing on every clock, you can not use  $fwrite, that time you should use $fmonitor.

you just reffer sample code to save your output either in text or excel sheet, (for text file just replace file extention with <filename.txt>)


initial begin
file=$fopen("C:\\VIVADO\\work_space\\out.csv"); // decalare file location, open file and file name named as out.csv
$fdisplay(file, "time_stamp, out1, out2"); // decclare what signal going to save in file
$fmonitor(file, "%t, %d, %d\t" ,$time, out1, out2); // declare what signal output to be store in file
#1000000000 // sufficient delay ( you should not give minimal delay)
$fclose(file); // close file after delay
end

 

0 Kudos
Explorer
Explorer
222 Views
Registered: ‎03-17-2011

Re: write file about output data

$fmonitor displays the values of its parameters EVERY time ANY of its parameter changes value.It might not be what he wants...

--Sebastien
0 Kudos