• 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
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    Which simulator are you using and which version? I just took your code and added a little extra to make it complete:

    `include "disciplines.vams"

    module forum35 (a);
    output a;
    electrical a;

    real A,B,C,D;
    integer fid,retval;

    analog initial begin
      fid=$fopen("forumresults.csv","r");
      retval=4;
      while(retval == 4) begin
        retval = $fscanf(fid, "%e,%e,%e,%e", A, B, C, D);
        $display("%e,%e,%e,%e", A, B, C, D);
      end
    end

    endmodule

    It then worked fine (I changed the filename). I see:

    Reading file: /export/home/username/tools/spectre/forumresults.csv
    3.290000e-06,1.280000e+06,4.957780e-01,1.940000e-07
    3.320000e-06,1.290000e+06,4.948000e-01,1.920000e-07
    3.420000e-06,1.330000e+06,4.956510e-01,1.870000e-07
    3.420000e-06,1.330000e+06,4.956510e-01,1.870000e-07

    The last line would be a duplicate because retval would probably have been -1 for end of file (I didn't check).

    This is using Spectre16.1 - but would be a bit surprised if this is particularly fussy about the version...

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 8 years ago

    Which simulator are you using and which version? I just took your code and added a little extra to make it complete:

    `include "disciplines.vams"

    module forum35 (a);
    output a;
    electrical a;

    real A,B,C,D;
    integer fid,retval;

    analog initial begin
      fid=$fopen("forumresults.csv","r");
      retval=4;
      while(retval == 4) begin
        retval = $fscanf(fid, "%e,%e,%e,%e", A, B, C, D);
        $display("%e,%e,%e,%e", A, B, C, D);
      end
    end

    endmodule

    It then worked fine (I changed the filename). I see:

    Reading file: /export/home/username/tools/spectre/forumresults.csv
    3.290000e-06,1.280000e+06,4.957780e-01,1.940000e-07
    3.320000e-06,1.290000e+06,4.948000e-01,1.920000e-07
    3.420000e-06,1.330000e+06,4.956510e-01,1.870000e-07
    3.420000e-06,1.330000e+06,4.956510e-01,1.870000e-07

    The last line would be a duplicate because retval would probably have been -1 for end of file (I didn't check).

    This is using Spectre16.1 - but would be a bit surprised if this is particularly fussy about the version...

    Andrew.

    • 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