09-10-2019 04:11 AM
09-10-2019 04:22 AM
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:
09-10-2019 04:24 AM
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.
09-10-2019 04:53 AM
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.
09-10-2019 05:27 AM
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.
09-10-2019 08:09 AM
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
09-11-2019 01:17 AM - edited 09-11-2019 02:12 AM
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>)
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
09-11-2019 01:24 AM
$fmonitor displays the values of its parameters EVERY time ANY of its parameter changes value.It might not be what he wants...