+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Full Member level 1
    Points: 1,014, Level: 7
    ashrafsazid's Avatar
    Join Date
    Sep 2016
    Location
    Germany
    Posts
    102
    Helped
    1 / 1
    Points
    1,014
    Level
    7

    reading a file in verilogA

    Hi,

    I need some helps regarding reading a file (say .txt, could be .csv as well) from a directory path and then generate a voltage signal based on the array of values from the file.

    There is a timing event, and the elements of the file array will be accessed based on timing events.

    Here is the VerilogA code:
    Code:
    `include "constants.vams"
    `include "disciplines.vams"
    
    module module_filereader (val);
    
    
    output val;
    electrical val;
    
    
    parameter real period = 1/10k ;
    parameter integer maxcount = 128 ;
    
    integer  dataread, cnt;
    real mydata1, mydata2;
    real datacol1 [maxcount-1:0];
    
    analog begin
    
    @(initial_step) begin
    	cnt = 0;
    	dataread = $fopen("/home/datafiles/data.txt","r"); //opening file readable access
    	end
    
    
    
    @(timer(0, period )) begin
        cnt = cnt+1;
    	end
    
    
    while( cnt < maxcount ) begin	
     	mydata1 = $fscanf(dataread,"%e", datacol1[cnt]);
    
          end
    
    $display ("| Transient:%g | data1: %g |", $realtime, mydata1) ;
    
    @(final_step) $fclose(dataread);
    
    
    
    // V(val) <+ transition(mydata1, 1n, 1n, 1n);
    
    end
    
    
    endmodule
    The input file is like this with many values depending on the count:
    Code:
    1
    4
    12
    3
    6
    2
    6
    7
    4
    10
    7
    9
    9
    ..... and so on
    The problem is I am getting some simulation error regarding the content of the file and it says

    Code:
    Fatal error found by spectre during IC analysis, during transient analysis `tran'.
        FATAL (ASL-3211): "/home/cadence_libs/mylib/module_filereader/veriloga/veriloga.va" 35: I225:  Digit not found in input file/string to match $fread/$fscanf/$sscanf format string. Change the format string to match the input file/string or correct the input file/string.
    
    Analysis `tran' was terminated prematurely due to an error.
    Please help me to solve this.
    Your life is all about ΔΣ, the narrow you estimate it, the precise it is ...

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 39,378, Level: 48

    Join Date
    Mar 2008
    Location
    USA
    Posts
    6,364
    Helped
    1855 / 1855
    Points
    39,378
    Level
    48

    Re: reading a file in verilogA

    Have you inspected the format string, relative to the
    data? First line? All lines? Number of lines / error trap
    for EOF?



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 1
    Points: 1,014, Level: 7
    ashrafsazid's Avatar
    Join Date
    Sep 2016
    Location
    Germany
    Posts
    102
    Helped
    1 / 1
    Points
    1,014
    Level
    7

    Re: reading a file in verilogA

    Quote Originally Posted by dick_freebird View Post
    Have you inspected the format string, relative to the
    data? First line? All lines? Number of lines / error trap
    for EOF?
    Found the issue, it is related to the filesystem difference between Unix and Windows text format. The difference of "Line end Character" which has to be a newline (\n) creates the issue.
    Your life is all about ΔΣ, the narrow you estimate it, the precise it is ...



--[[ ]]--