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

von XaBla (Guest)

Rate this post
0 useful
not useful
Hello, I'd like to write a value in a file. This is the code I have 
task speed;
    input [23:0] v;
    input [23:0] s;
    integer f;
          f = $fopen("test.txt","w");
              if (!f) begin
                $display("Could not open \"test.txt\"");
              end else begin
                for(int i=0; i<24; i++) begin
                  $fwrite(f,"%b", s[i]);
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 

von Vancouver (Guest)

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.

von Duke Scarring (Guest)

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.



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
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.