EmbDev.net

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


Author: XaBla (Guest)
Posted on:

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

Author: Vancouver (Guest)
Posted on:

Rate this post
0 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.

Author: Duke Scarring (Guest)
Posted on:

Rate this post
0 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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig