Write in a file with verilog

Guest #5918382
Rate this post
useful
not useful
Hello, I'd like to write a value in a file. This is the code I have 
implemented:
1
task speed;
2
    input [23:0] v;
3
    input [23:0] s;
4
    integer f;
5
      begin
6
          f = $fopen("test.txt","w");
7
              if (!f) begin
8
                $display("Could not open \"test.txt\"");
9
              end else begin
10
              #70000;
11
                 
12
                for(int i=0; i<24; i++) begin
13
                  $fwrite(f,"%b", s[i]);
14
                end
15
              end
16
              #10000
17
          $fclose(f);  
18
     end
19
  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?
Guest #5918409
Rate this post
useful
not useful
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.

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now