• 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
  • Alifa
    Alifa over 11 years ago

    Hi Lawrence

    I fixed the problem. Thank you. Here comes the code:

     analog begin

        @ (initial_step)
            fileHandle = $fopen(fileName, "r");
        @ (final_step)
            $fclose(fileHandle);
        @ (cross (V(clk) - vtrans,+1)) begin
             decimal_output = $fscanf(fileHandle,"%d", captured_data);
             x = ( captured_data > vtrans);
                                  
        end
        
        V(out1) <+ transition( vlogic_high*x + vlogic_low*!x,tdel, trise, tfall );
    end

    endmodule

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

    Hi Lawrence

    I fixed the problem. Thank you. Here comes the code:

     analog begin

        @ (initial_step)
            fileHandle = $fopen(fileName, "r");
        @ (final_step)
            $fclose(fileHandle);
        @ (cross (V(clk) - vtrans,+1)) begin
             decimal_output = $fscanf(fileHandle,"%d", captured_data);
             x = ( captured_data > vtrans);
                                  
        end
        
        V(out1) <+ transition( vlogic_high*x + vlogic_low*!x,tdel, trise, tfall );
    end

    endmodule

    • 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