The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Read from a file
https://designers-guide.org/forum/YaBB.pl?num=1132915963

Message started by Zorro on Nov 25th, 2005, 2:52am

Title: Read from a file
Post by Zorro on Nov 25th, 2005, 2:52am

Hello Everybody,

I have a .txt file (for example) containing information that I need to load into a module. Let's say I have a file like this:

0:5
1:32
2:40
9:17
etc

where the left side refers to the addresses of a memory(rom) and the right side refers to the information to be written to every address.

Is there a way to do that? Is there a way to read from an external file?  ???

I've seen some topics with information about how to write to a file. But, in this case, it's just in the other direction.

Thanks for your suggestions.





Title: Re: Read from a file
Post by Andrew Beckett on Nov 27th, 2005, 8:43am

See previous discussion on this:

http://www.designers-guide.org/Forum/?board=verilogams;action=display;num=1083635544;start=3#3

Regards,

Andrew.

Title: Re: Read from a file
Post by Zorro on Dec 1st, 2005, 12:46am

hello Andrew,

thanks for the link. I've tried the $table_model  function and it worked fine. I loaded a simple table describing the behavior of a resistor

# this is the file resistor.tbl file
# using r = 5 Ohms
#      V(a, b)      I(a, b)
     1      0.2
     2      0.4

// resistor_table.vams
module resistor_table (a, b );
     inout a, b;
     electrical a, b;
     analog begin
           I(a, b) <+ $table_model(V(a, b), "resistor.tbl", "L");
     end
endmodule

I would like to know if you or somebody has used the fscanf function (va or vams). It's the form:

$fscanf (multi_channel_descriptor , "format" { , storage_arg } )

The problem I have is that the multi_chanel_descriptor must have a value associated with a currently open file. If a use for example:

integer i;
i = $fopen("file.txt");
...
$fscanf (i, "format" { , storage_arg } )

the information in file.txt will be erased because of the $fopen but I need to open this file in read only mode.

Thanks for any suggestion.

Title: Re: Read from a file
Post by Geoffrey_Coram on Dec 1st, 2005, 3:57am

I think (digital) Verilog supports mode arguments to $fopen, a la C:
$fopen("file.txt", "r");

and thus, many of the AMS simulators from the major EDA vendors support this, even though it is not in the AMS LRM.

Title: Re: Read from a file
Post by Zorro on Dec 1st, 2005, 4:39am

Thanks Geoffrey,

I've found something in internet (but in verilog-PLI) using something like:

i = $fopenr("file.txt");

and I thought that "r" comes from read only (I mean, open without editing). But in the LRM for verilogA/AMS I didn't find nothing about it.

I'm gonna try your suggestion: $fopen("file.txt", "r");


Regards,

Douglas

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.