I am try to do something like the following in a spectre library file:
//
parameters useothermodel=0
if (useothermodel==1) {
model mymodel othermodel
} else {
model mymodel normalmodel
}
//
But spectre gives me a syntax error on the line after "model mymodel othermodel". A line which should not even have been read ! It turns out that instances or subcircuits are accepted in an if-then-else statement, but not models (dammit!).
In my real case, there are many (many) models to be defined inside these if statements. Besides, the files that bear the "model" statements are foundry-owned, so I should keep my hands off of that. And the structure of the library has nested if-then-else's , includes and subsections ;it is more complicated than the above example. So I cannot use an "inline subckt" trick.
Can anyone think of a way around this limitation ?
One approach is to do:
inline subckt mymodel (d g s b)
// device instance parameters
parameters w=1u l=1u ad=1p as=1p pd=1u ps=1u
if (useothermodel==1) {
mymodel (d g s b) othermodel w=w l=l ad=ad as=as pd=pd ps=ps
} else {
mymodel (d g s b) normalmodel w=w l=l ad=ad as=as pd=pd ps=ps
}
ends mymodel
That way you are switching between two instances, and all is OK (I'm assuming
othermodel and normalmodel are defined somewhere else). By making it
an inline subckt (note, the instance name needs to match the subckt name
for the benefits of inline subckt to occur), the extra level of hierarchy
doesn't appear in the results data, and so backannotation to the schematic
occurs as if it were an ordinary model.
The other way of doing conditional model inclusion by parameter is
to combine all your models, and make them of this form:
model mymodel bsim3v3 param1=useothermodel==1?val1:val2 \
param2=useothermodel==1?val3:val4 ...
i.e. use the ternary expression to conditionally select one of two (or more)
values for each model parameter. With a bit of perl you could easily combine
your multiple models into a single model file written like this.
Finally, you could abandon the parameterisation, and use sections in a
model file:
library mylib
section modelset1
model mymodel bsim3v3 ... one set of params ...
endsection modelset1
section modelset2
model mymodel bsim3v3 ... other set of params ...
endsection modelset2
endlibrary mylib
and then you'd do:
include "/path/to/modelfile.scs" section=modelset2
say. You can choose the section on the ADE model library form, or use the
corners tool. I've got an enhancement request in to allow the section name on
such an include to be parameterisable, and then potentially it could be swept
over a set of values - but this is an idea for the future.
Regards,
Andrew.
--
Andrew Beckett
Senior Technical Leader
Custom IC Solutions
Cadence Design Systems Ltd
inline subckt mymodel (d g s b)
// device instance parameters
parameters w=1u l=1u ad=1p as=1p pd=1u ps=1u
if (useothermodel==1) {
alter_mymodel alter param=modelname value="normalmodel"
} else {
alter_mymodel alter param=modelname value="othermodel"
}
mymodel (d g s b) analogmodel modelname=modelname w=w l=l ad=ad as=as
pd=pd ps=ps
ends mymodel
But spectre somehow doesnt like to see both alter's with the same
instance name. I wonder if that can make it possible to have normalmodel
a bsim3 and othermodel a bsim4.
Do I really have to pass parameters explicitly (youknow how lazy I am
by now) ? I wish I could have :
//
inline subckt mymodel (d g s b)
mymodel (d g s b) analogmodel modelname="normalmodel"
ends
M0 (1 2 3 4) mymodel l=100u
//
and not have to pass "l=l"
It is true that it would be added value to sweep/step the sections. But
maybe a bit too much mess if spectre needs to have enumated types
introduced in the style of section[]={"section1" "section2"}
I am not using perl yet, but the bunch of shell/awk/sed/cut/grep I have
put in there makes it just as unreadable.
Error found by spectre during alter
`Q0.Q1.alter_NPN'.
Real value expected for parameter `modelname'.
Good morning number 6.
Also, I don't think alter can be used to change string parameters (like the
modelname in an analogmodel component).
In general switching one model for another model (if it is a different type) is
a problem because it results in a topology change (the matrix size may change,
because of different numbers of internal nodes). The reason why it
doesn't like multiple things with the same instance name in different branches
of a structural if is if a topology change results.
Yes, you do have to pass parmaeters explicitly in the example I gave.
I think adding support for sweeping sections wouldn't be too bad from a parser
point of view - a sweep such as:
mysweep param=section values=["typ","best","worst"] {
tran tran ...
}
The issues are that the include statement takes the section as a literal, and
doesn't allow it to be parameterised. Also, there may be topology change issues
so it may have to do an altergroup underneath - so it's not as simple as it
might sound. The vector of values in the above example is already supported,
although I don't think it is with string values...
One day it will all work beautifully!
Regards,
Andrew.
(These are of course my own views, and not the view of my employer).