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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.