<@U01819B63HP>: Here's a new question for you. I...
# xschem
t
@Stefan Schippers: Here's a new question for you. I've been working on this CACE system for automatic characterization. It was developed on the Efabless platform years ago when we were using Electric for schematic entry and hadn't heard of xschem. So I was trying to introduce variables and equations into the netlists to be resolved by direct substitution. For the variables I used the usual standard of
${name}
; for the equations I introduced a stack notation with the odd looking variables
${*}
${/}
${+}
${-}
and suchlike; so
${A} ${B} ${+} 2 ${/}
would resolve to
(A+B)/2
. This notation can get rather cumbersome. I think I can replace the whole system with just a call to xschem to generate a netlist if I pass all the variable names to xschem, but I would also need to replace the stack notation stuff. I think it is a straightforward matter of replacing it with calls to
tcleval
. I've attached a schematic for a CACE testbench. How should I write the device parameters with
tcleval
(or any other syntax that works) so that xschem would do the work of variable substitution and produce the output I'm currently doing with python code inside CACE? (FYI, the variable notation on pins is also being handled inside CACE but I do not think this is needed and I can dispense with it altogether).)
👍 1
s
@Tim Edwards a couple of examples below show how xschem tcl substitution works. If something is wrapped inside
tcleval(...)
the content
...
will be passed to the tcl
subst
command. That means all tcl
$variables
are replaced with their values and all tcl
[commands]
are replaced with the command return values. If I set a voltage source value attribute this way:
value="tcleval([expr {$val + 3}])"
the voltage source will be netlisted with a value of 6 if
val
is a tcl variable set to
3
. SInce
$
and
[]
have a special meaning to tcleval() they need to be escaped if you want them literally: if you need a literal
[
use `\\[`:
value="tcleval(\\$val=$val)" --> $val=3
The following line:
meas tran vhigh1 FIND V(inp) WHEN V(out) = ${Vvdd} 2 ${/} CROSS=1
will change to:
meas tran vhigh1 FIND V(inp) WHEN V(out) = [expr ${Vvdd} / 2.0] CROSS=1
if you wrap the whole text inside tcleval():
Copy code
value="tcleval(.control
tran [expr ${risetime} * 2. / 100.] [expr ${risetime} * 4.]
...
meas tran vhigh1 FIND V(inp) WHEN V(out) = [expr ${Vvdd} / 2.0] CROSS=1
...
)"
t
@Stefan Schippers: Perfect, thanks! And is the approved (best) way to pass all the variables to xschem to run, e.g.,
xschem --command "set temperature 100; set vvdd 3.0; ..."
?
s
For setting the variables to xschem you should call xschem like:
xschem --tcl 'set var1 xxx; set var2 yyy; ...' cmrr.sch
or
xschem --script setvars.tcl cmrr.sch
if variable definitions are in an external file
yes --command is ok too:
xschem --command 'set var1 xxx; set var2 yyy; ...' cmrr.sch
there are 3 ways to pass tcl commands:
--preinit 'tcl_commands'
: do these commands in a very early stage, before loading xschemrc
--tcl 'tcl_commands'
: do the commands right after sourcing xschemrc, before building the GUI `--command 'tcl_commands'`: do the commands after completing startup. This makes all 'xschem' tcl commands available. Setting TCL variables can be done with any of the 3 above.
1
t
I'm actually leaning toward the
--script
option, because then I can optionally keep the script files and use them to re-run the simulation without having to reconstruct a long command line. The goal is to get away from a "special format" in the schematic and have a schematic that can be netlisted and simulated with or without the CACE system.
s
ok, I was also considering to let ngspice do all the math, defining .param lines, but it seems in some contexts expressions are not allowed, for example
.tran 'risetime / 50' 'risetime *4'
t
Also depending on ngspice to do the math makes everything harder to port to Xyce.
1
s
Yes, probably Xyce is even more pity about allowing expressions
same thing as passing a $PDK_ROOT to a spice netlist. Impossible AFAIK
A note: If you see some tcleva() expressions not being evaluated (you see a ?) a great help is setting this at the xschem terminal:
set debug_tcleval 1
If you redraw the screen failing tcl evaluations will be printed: tclpropeval2 warning: DC ${Vvsdd} --> can't read "Vvsdd": no such variable
1