I would like to write an internal reg to a txt file.

I have tried something like:

    f = $fopen("conv2_tb_output.txt","w");
    $fmonitor(f, value=%d\n", mat_out);

But since mat_out is an internal reg, I got an error: is not declared.

Does anyone body know how to write internal regs to a txt file?

Thanks in advance


I presume you're trying to access a register inside a module from a testbench that instantiates that module. In this case, I think what you need to do is use a hierarchical reference. Instead of using mat_out, use module_instance_name.mat_out where module_instance_name is the name of the instance of the module that contains mat_out.

| improve this answer | |
  • \$\begingroup\$ That's it. Now I don't get any error, but conv2_tb_output.txt does not contain anything. I have to say that mat_out is a matrix. edaplayground.com/x/6G7h# \$\endgroup\$ – user204415 Jan 22 '18 at 9:22
  • \$\begingroup\$ Try it with a simple integer and see if that works. Or try accessing a single element of the matrix. You may need to do a bit more work to print out a whole matrix (i.e. you may need to use a for loop and iterate over it). \$\endgroup\$ – alex.forencich Jan 22 '18 at 9:34
  • 1
    \$\begingroup\$ Also, maybe try closing the file at the end of the testbench instead of immediately after opening it. \$\endgroup\$ – alex.forencich Jan 22 '18 at 9:36
  • \$\begingroup\$ It's really weird, but, if after $fmonitor(f, "time=%5d, valor=%d\n", $time, uut.mat_out); I write anything like: $fmonitor(f, "time=%5d, valor=%d\n", $time, uut.mat_out); fdsfdsfdfsd. The simulation fails but the txt file contains mat_out!!! Can you explain that? lol \$\endgroup\$ – user204415 Jan 22 '18 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.