The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 11th, 2024, 6:54pm
Pages: 1
Send Topic Print
How to parameterize a string variable (Read 4605 times)
naone
New Member
*
Offline



Posts: 2
San Diego
How to parameterize a string variable
Dec 15th, 2006, 11:41am
 
I am trying to pass a string parameter into a verilogA file to use as the filename for an include file:

This is what I am trying but have syntax errors:

parameter filename = "incfile.txt"

`include filename


This does not work.  I also tried `include(filename) and this did not work either.

Any help is greatly appreciated.

Naone
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: How to parameterize a string variable
Reply #1 - Dec 18th, 2006, 6:31am
 
I'm almost sure you can't do this at all; the problem is that `include is a preprocessor directive, handled by the compiler, well before anything else happens.

What are you trying to bring in in that include file, though?  Usually, include files tell the compiler something about how to compile; I guess you're trying to bring in some information for simulation, so you may be able to bring in the data another way (eg, $table_model).

-Geoffrey
Back to top
 
 

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



Posts: 378
Silicon Valley
Re: How to parameterize a string variable
Reply #2 - Feb 9th, 2007, 3:13am
 
If you want to set some variables from the file, you can use

parameter string myFile = "default file name"
then
FH = $fopen( myFile, r): <- I don't remember how this works
var1 = $fscanf(FH);
Back to top
 
 

jbdavid
Mixed Signal Design Verification
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: How to parameterize a string variable
Reply #3 - Feb 9th, 2007, 6:19am
 
jbdavid wrote on Feb 9th, 2007, 3:13am:
If you want to set some variables from the file, you can use

parameter string myFile = "default file name"


In what simulator?  I know it's in the LRM; I'm not aware of any simulators that support it yet ...
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Andrew Beckett
Senior Fellow
******
Offline

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

Posts: 1742
Bracknell, UK
Re: How to parameterize a string variable
Reply #4 - Feb 22nd, 2007, 11:09am
 
Spectre does. I filed a PCR a while ago because string parameters weren't working in case statements, but that works now (in MMSIM60 and MMSIM61 versions for about a year). I just took the example I had with a case statement, and tried it out with fopen too - and that worked:

Code:
`include "discipline.h"
`include "constants.h"
module resexample (a,b);

inout  a,b;
electrical  a,b;
branch (a,b) resbr;
parameter real w=1u,l=1u,rsh1=1000.0,rsh2=400.0,rsh3=200.0;
parameter string rtype="M1";
real rval;
integer FH;

analog begin

    case (rtype)
    "M1": rval=rsh1*w/l;
    "M2": rval=rsh2*w/l;
    default: rval=rsh3*w/l;
    endcase
    $strobe("rtype is %s, rval is %g",rtype,rval);
    FH=$fopen(rtype,"w");
    $fstrobe(FH,"rtype is %s, rval is %g",rtype,rval);
    $fclose(FH);

    V(resbr) <+ rval*I(resbr);

end

endmodule 



with this netlist:

Code:
//

r1 (1 0) resexample w=2u l=0.5u rtype="M2"
v1 (1 0) vsource type=dc dc=1

ahdl_include "resexample.va"

dc dc write=stuff.dc 



It wrote out:

 rtype is M2, rval is 1600

both to the screen, and into a file called "M2".

Regards,

Andrew.
Back to top
 
 
View Profile WWW   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.