EmbDev.net

Forum: FPGA, VHDL & Verilog Write in a file with verilog


von XaBla (Guest)


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?

von Vancouver (Guest)


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.

von Duke Scarring (Guest)


Rate this post
useful
not useful
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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.