• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. How to read a text file in a VerilogA code

Stats

  • Locked Locked
  • Replies 7
  • Subscribers 126
  • Views 21713
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to read a text file in a VerilogA code

Alifa
Alifa over 11 years ago

 Hello every body!

I will greatly appreciate your help.

In order to test a serial DAC I need to input the DAC with serial bits ( any pattern like 01110001111), one bit at a clock cycle. So my text file (bit_sequence.txt) looks like this:

 1

0

 1

0

0

1

.

.

.

Basically, I want a VerilogA model that reads "bit_sequence.txt" and output one bit at a clock cycle to my DAC circuit. I tried the following code. It compiles with no error, but I can't see the above pattern in my simulation. Moreover, after running simulation, the bit_sequence.txt gets empty! :)

module fileReader_1output(out1, clk);
input clk;
output out1;
electrical out1, clk;

parameter real vtrans = 1.0;
parameter fileName = "~/bit_sequence.txt";

integer fileHandle;
integer decimal_output;
integer captured_data;

analog begin

    @ (initial_step)
        fileHandle = $fopen(fileName);
    @ (final_step)
        $fclose(fileHandle);
    @ (cross (V(clk) - vtrans,+1)) begin
                 
        decimal_output = $fscanf(fileHandle,"%d", captured_data);
        V(out1)<= decimal_output; //captured_data;    

     end
end

endmodule

  • Cancel
Parents
  • skillUser
    skillUser over 11 years ago

    Hi Alifa,

    When you use $fopen there is a second argument for the mode - I think that the default must be write (overwrite) and so you would need to specify read mode so that you don't clobber the file contents and so that you are able to read from the file.  I have not tried your example, but you may need to adjust the pattern to cope with possible spaces in the input file (your text above shows some preceeding space on some lines).

    Hopefully the first point is the only one that you need to account for and your code works after a minor adjustment. Good luck!

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • skillUser
    skillUser over 11 years ago

    Hi Alifa,

    When you use $fopen there is a second argument for the mode - I think that the default must be write (overwrite) and so you would need to specify read mode so that you don't clobber the file contents and so that you are able to read from the file.  I have not tried your example, but you may need to adjust the pattern to cope with possible spaces in the input file (your text above shows some preceeding space on some lines).

    Hopefully the first point is the only one that you need to account for and your code works after a minor adjustment. Good luck!

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information