ask confirmation if pressing "s" for simulate; node lists in graph dialog box are returned as they are with no tcleval() resolution; poweramp.sch now can be simulated unchanged with Xyce

This commit is contained in:
Stefan Frederik 2022-09-13 00:31:20 +02:00
parent e2846daca5
commit 75db846e58
6 changed files with 106 additions and 74 deletions

View File

@ -1556,7 +1556,12 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key,
}
if(key=='s' && (state == 0) ) /* simulate */
{
tcleval("[xschem get top_path].menubar.simulate invoke");
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] "
"-message {Run circuit simulation?}");
if(strcmp(tclresult(),"ok")==0) {
tcleval("[xschem get top_path].menubar.simulate invoke");
}
break;
}
if(key=='s' && (state == ControlMask) ) /* save 20121201 */
@ -2108,8 +2113,8 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key,
else if(xctx->netlist_type == CAD_TEDAX_NETLIST)
global_tedax_netlist(1);
else
if(has_x) tcleval("tk_messageBox -type ok -parent [xschem get topwindow] "
"-message {Please Set netlisting mode (Options menu)}");
tcleval("tk_messageBox -type ok -parent [xschem get topwindow] "
"-message {Please Set netlisting mode (Options menu)}");
dbg(1, "callback(): -------------\n");
}
@ -2131,8 +2136,8 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key,
else if(xctx->netlist_type == CAD_TEDAX_NETLIST)
global_tedax_netlist(0);
else
if(has_x) tcleval("tk_messageBox -type ok -parent [xschem get topwindow] "
"-message {Please Set netlisting mode (Options menu)}");
tcleval("tk_messageBox -type ok -parent [xschem get topwindow] "
"-message {Please Set netlisting mode (Options menu)}");
dbg(1, "callback(): -------------\n");
}
break;

View File

@ -301,12 +301,10 @@ static int read_dataset(FILE *fd)
char line[PATH_MAX], varname[PATH_MAX];
char *ptr;
int n = 0, done_header = 0;
int simtype, exit_status = 0;
int exit_status = 0;
xctx->graph_sim_type = 0;
tcleval("sim_is_xyce");
simtype = atoi( tclresult() );
while((ptr = fgets(line, sizeof(line), fd)) ) {
while((fgets(line, sizeof(line), fd)) ) {
/* after this line comes the binary blob made of nvars * npoints * sizeof(double) bytes */
if(!strcmp(line, "Values:\n") || !strcmp(line, "Values:\r\n")) { /* this is an ASCII raw file. We don't handle this (yet) */
free_rawfile(0);
@ -400,12 +398,11 @@ static int read_dataset(FILE *fd)
return 1;
}
strtolower(varname);
if(simtype) { /* Xyce uses : as path separator */
char *ptr = varname;
while(*ptr) {
if(*ptr == ':') *ptr = '.';
ptr++;
}
/* transform ':' hierarchy separators (Xyce) to '.' */
ptr = varname;
while(*ptr) {
if(*ptr == ':') *ptr = '.';
ptr++;
}
if(xctx->graph_sim_type == 3) { /* AC */
my_strcat(415, &xctx->graph_names[i << 1], varname);
@ -561,6 +558,13 @@ int get_raw_index(const char *node)
my_snprintf(vnode, S(vnode), "v(%s)", inode);
entry = int_hash_lookup(xctx->graph_raw_table, vnode, 0, XLOOKUP);
}
if(!entry && strstr(inode, "i(v.x")) {
char *ptr = inode;
inode[2] = 'i';
inode[3] = '(';
ptr += 2;
entry = int_hash_lookup(xctx->graph_raw_table, ptr, 0, XLOOKUP);
}
if(entry) return entry->value;
}
return -1;

View File

@ -1170,7 +1170,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
} else {
int c = atoi(argv[3]);
int n = atoi(argv[4]);
Tcl_SetResult(interp, (char *)get_tok_value(xctx->rect[c][n].prop_ptr, argv[5], 0), TCL_VOLATILE);
Tcl_SetResult(interp, (char *)get_tok_value(xctx->rect[c][n].prop_ptr, argv[5], 2), TCL_VOLATILE);
}
}
}

View File

@ -1569,7 +1569,7 @@ proc graph_update_nodelist {} {
set col [xschem getprop rect 2 $graph_selected color]
set col [string trim $col " \n"]
set regx {(?:"[^"]+")|(?:[^\n \t]+)}
set regx {(?:(tcleval\()?"[^"]+"\)?)|(?:(tcleval\()?[^\n \t]+\)?)}
set txt [.graphdialog.center.right.text1 get 1.0 {end - 1 chars}]
set tt {}
set cc {}

View File

@ -1,4 +1,5 @@
v {xschem version=3.0.0 file_version=1.2 }
v {xschem version=3.1.0 file_version=1.2
}
G {}
K {}
V {}
@ -11,8 +12,8 @@ y1=-47
y2=50
divy=4
subdivy=4
x1=0.0436647
x2=0.045091
x1=0.00763563
x2=0.00893547
divx=8
subdivx=1
dataset=0
@ -29,8 +30,8 @@ y1=0.94
y2=160
divy=4
subdivy=9
x1=0.0436647
x2=0.045091
x1=0.00763563
x2=0.00893547
divx=8
subdivx=9
dataset=0
@ -38,7 +39,7 @@ unitx=m
color="4 7"
color="8 7"
node="tcleval(\\"Xm1 power;vpp $\{path\}outi - i(v.$\{path\}vu) *\\"
\\"Average;vpp $\{path\}outi - i(v.$\{path\}vu) * 2e-4 ravg()\\")"
}
@ -47,16 +48,14 @@ y1=-0.05
y2=150
divy=4
subdivy=9
x1=0.0436647
x2=0.045091
x1=0.00763563
x2=0.00893547
divx=8
subdivx=9
dataset=0
unitx=m
color="4 7"
color="8 7"
node="tcleval(\\"Xm2 Power;$\{path\}outi vnn - i(v.$\{path\}vd) *\\"
\\"Average;$\{path\}outi vnn - i(v.$\{path\}vd) * 2e-4 ravg()\\")"
}

View File

@ -1,4 +1,5 @@
v {xschem version=3.0.0 file_version=1.2 }
v {xschem version=3.1.0 file_version=1.2
}
G {}
K {}
V {}
@ -18,8 +19,8 @@ B 2 1200 -500 1880 -310 {flags=graph
y1 = -0.0059
y2 = 11
divy = 6
x1=0.0119263
x2=0.0123791
x1=0.0125703
x2=0.0132608
divx=10
node="i(v.x1.vu)
i(v.x0.vu)
@ -31,8 +32,8 @@ B 2 1200 -830 1880 -520 {flags=graph
y1 = -49
y2 = 59
divy = 12
x1=0.0119263
x2=0.0123791
x1=0.0125703
x2=0.0132608
divx=10
node="outp
outm
@ -46,8 +47,8 @@ B 2 1200 -1020 1880 -830 {flags=graph
y1 = 2.4e-11
y2 = 840
divy = 6
x1=0.0119263
x2=0.0123791
x1=0.0125703
x2=0.0132608
divx=10
@ -59,8 +60,8 @@ B 2 1200 -310 1880 -120 {flags=graph
y1 = 0.0077
y2 = 850
divy = 6
x1=0.0119263
x2=0.0123791
x1=0.0125703
x2=0.0132608
divx=10
@ -172,37 +173,6 @@ N 240 -300 240 -270 { lab=INX}
N 160 -1220 180 -1220 {lab=#net3}
N 160 -1060 180 -1060 {lab=#net4}
N 70 -1140 180 -1140 {lab=#net5}
C {code.sym} 1020 -210 0 0 {name=STIMULI
only_toplevel=true
tclcommand="xschem edit_vi_prop"
value=".option PARHIER=LOCAL RUNLVL=6 post MODMONTE=1 warn maxwarns=400
.option ITL4=20000 ITL5=0
* .option sampling_method = SRS
* .option method=gear
vvss vss 0 dc 0
.temp 30
.param frequ=5k
.param gain=45
.option savecurrents
** models are generally not free: you must download
** SPICE models for active devices and put them into the below
** referenced file in simulation directory.
.include \\"models_poweramp.txt\\"
.control
save all
op
write poweramp.raw
set appendwrite
tran 8e-7 0.07 uic
* .FOUR 20k v(outm,outp)
* .probe i(*)
plot outp outm
save p(r*) p(v*)
write poweramp.raw
.endc
"}
C {vsource.sym} 70 -1170 0 0 {name=V1 value="dc 50 pwl 0 0 1m 50"}
C {vsource.sym} 70 -1110 0 0 {name=V0 value="dc 50 pwl 0 0 1m 50"}
C {lab_pin.sym} 310 -1220 0 1 {name=p5 lab=VPP}
@ -212,7 +182,7 @@ C {lab_pin.sym} 860 -240 0 1 {name=p14 lab=OUTP}
C {res.sym} 860 -490 0 1 {name=R1 m=1 value=8}
C {lab_pin.sym} 500 -1150 0 0 {name=p26 lab=VSS}
C {lab_pin.sym} 540 -1190 0 0 {name=p31 lab=IN}
C {vcvs.sym} 610 -1170 0 0 {name=E3 value='gain*0.99'}
C {vcvs.sym} 610 -1170 0 0 {name=E3 value=\{gain*0.99\}}
C {lab_pin.sym} 700 -1200 0 1 {name=p32 lab=REFP}
C {capa.sym} 260 -1100 0 0 {name=C3 m=1 value="100u"}
C {res.sym} 130 -1220 1 1 {name=R11 m=1 value=0.3}
@ -235,7 +205,7 @@ C {res.sym} 260 -160 0 1 {name=R7 m=1 value=100k}
C {lab_pin.sym} 260 -110 0 0 {name=p15 lab=VSS}
C {lab_pin.sym} 500 -1070 0 0 {name=p20 lab=VSS}
C {lab_pin.sym} 540 -1110 0 0 {name=p21 lab=IN}
C {vcvs.sym} 610 -1090 0 0 {name=E0 value='-gain*0.99'}
C {vcvs.sym} 610 -1090 0 0 {name=E0 value=\{-gain*0.99\}}
C {lab_pin.sym} 700 -1120 0 1 {name=p23 lab=REFM}
C {lab_pin.sym} 240 -250 0 0 {name=p8 lab=INX}
C {lab_pin.sym} 870 -1050 0 0 {name=p126 lab=VSS}
@ -249,7 +219,7 @@ C {res.sym} 550 -460 0 1 {name=R2 m=1 value='100k'}
C {res.sym} 550 -400 0 1 {name=R3 m=1 value="'100k/(gain-2)'"}
C {vsource.sym} 870 -1140 0 0 {name=V3
xvalue="dc 0 pulse -.1 .1 1m .1u .1u 10.1u 20u"
value="dc 0 sin 0 1 frequ 1m"
value="dc 0 sin 0 1 \{frequ\} 1m"
}
C {res.sym} 240 -810 0 1 {name=R4 m=1 value=100k}
C {lab_pin.sym} 240 -860 0 0 {name=p18 lab=VPP}
@ -356,12 +326,66 @@ tclcommand="textwindow $netlist_dir/[file tail [file rootname [ xschem get schna
C {spice_probe.sym} 300 -1220 0 0 {name=p45 analysis=tran voltage=49.84}
C {spice_probe.sym} 300 -1060 0 0 {name=p46 analysis=tran voltage=-49.86}
C {launcher.sym} 1145 -1165 0 0 {name=h5
descr="Select arrow and
Ctrl-Left-Click to load/unload waveforms"
descr="load ngspice waves"
tclcommand="
xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw
xschem raw_read $netlist_dir/poweramp.raw
"
}
C {launcher.sym} 1450 -30 0 0 {name=h6
descr="Graph Manual page"
url="https://xschem.sourceforge.io/stefan/xschem_man/graphs.html"}
C {simulator_commands.sym} 1020 -540 0 0 {name=COMMANDS
simulator=ngspice
only_toplevel=false
value="
.option ITL4=20000 ITL5=0
vvss vss 0 dc 0
.temp 30
.param frequ=5k
.param gain=45
.option savecurrents
** models are generally not free: you must download
** SPICE models for active devices and put them into the below
** referenced file in simulation directory.
.include \\"models_poweramp.txt\\"
.control
save all
op
write poweramp.raw
set appendwrite
tran 8e-7 0.07 uic
* .FOUR 20k v(outm,outp)
* .probe i(*)
plot outp outm
save p(r*) p(v*)
write poweramp.raw
.endc
"}
C {simulator_commands.sym} 1020 -740 0 0 {name=COMMANDS1
simulator=xyce
only_toplevel=false
value="
.option ITL4=20000 ITL5=0
vvss vss 0 dc 0
.temp 30
.param frequ=5k
.param gain=45
** models are generally not free: you must download
** SPICE models for active devices and put them into the below
** referenced file in simulation directory.
.include \\"models_poweramp.txt\\"
* .op
.tran 8e-7 0.07 uic
.print tran format=raw file=poweramp_xyce.raw v(*) i(*)
+ v(x1:*) v(x0:*) i(x1:*) i(x0:*)
"}
C {launcher.sym} 1495 -1165 0 0 {name=h7
descr="load Xyce waves"
tclcommand="
xschem raw_read $netlist_dir/poweramp_xyce.raw
"
}