Hello, I'd like to write a value in a file. This is the code I have implemented:
task speed; input [23:0] v; input [23:0] s; integer f; begin f = $fopen("test.txt","w"); if (!f) begin $display("Could not open \"test.txt\""); end else begin #70000; for(int i=0; i<24; i++) begin $fwrite(f,"%b", s[i]); end end #10000 $fclose(f); end endtask
Unfortunately, what I read is "xxxxxxxxxxxxxxxxxxxxxxxx". I was thinking that this happens since the date is not available when I try to write it, so I put a delay, but it's not still working. Can anyone help me please?
Put $display() inside the for loop to check if input data is defined while writing to the file. Not sure if the delay in your code has any effect if the input data is undefined at the point when the task is called. Remember that a task is a pure software function that is executed by the simulator at the time when it is called, not permanently like an 'always' construct.
XaBla wrote: > Unfortunately, what I read is "xxxxxxxxxxxxxxxxxxxxxxxx". I think the problem is not in the code you have showed us. Also long as your "input [23:0] s" is undefined you will get the 'x'es. Duke