The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 1st, 2024, 9:09am
Pages: 1
Send Topic Print
Read from a file (Read 4309 times)
Zorro
Community Member
***
Offline



Posts: 63

Read from a file
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.




Back to top
 
 
View Profile   IP Logged
Andrew Beckett
Senior Fellow
******
Offline

Life, don't talk to
me about Life...

Posts: 1742
Bracknell, UK
Re: Read from a file
Reply #1 - Nov 27th, 2005, 8:43am
 
Back to top
 
 
View Profile WWW   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: Read from a file
Reply #2 - 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.
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Read from a file
Reply #3 - 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.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: Read from a file
Reply #4 - 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
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.