spice_probe_dynamic.sym added to devices, retrieves node voltages with a pull method, so always updated, "@@pin" syntax in translate(), same as in format string for netlisting,print hilight nodes (ctrl-alt-j) will print .save instructions if netlist mode set to spice

This commit is contained in:
Stefan Schippers 2020-10-20 01:05:40 +02:00
parent c84d71b859
commit 72e45216c2
9 changed files with 155 additions and 58 deletions

View File

@ -1032,6 +1032,10 @@ void draw_hilight_net(int on_window)
}
/* show == 0 ==> create pins from highlight nets */
/* show == 1 ==> print list of highlight net */
/* show == 2 ==> create labels with i prefix from hilight nets */
/* show == 3 ==> print list of highlight net with path and label expansion */
/* show == 4 ==> create labels without i prefix from hilight nets */
void print_hilight_net(int show)
{
int i;
@ -1099,8 +1103,15 @@ void print_hilight_net(int show)
/* before invoking this function, in this case --> skip */
if(node_entry && !strcmp(xctx->sch_path[xctx->currsch], entry->path)) {
if(show==3) {
if(netlist_type == CAD_SPICE_NETLIST)
fprintf(fd, ".save v(%s%s)\n",
entry->path + 1,
entry->token[0] == '#' ? entry->token + 1 : entry->token );
else
fprintf(fd, "%s%s\n",
entry->path + 1,
entry->token[0] == '#' ? entry->token + 1 : entry->token );
fprintf(fd, "%s%s\n", !strcmp(entry->path, ".") ? "" : entry->path, entry->token);
} else if(show==1) {
fprintf(fd, "%s\n", entry->token);

View File

@ -21,7 +21,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
proc read_ngspice_raw {arr fp} {
namespace eval ngspice {
# Create a variable inside the namespace
variable ngspice_data
}
proc ngspice::read_ngspice_raw {arr fp} {
upvar $arr var
unset -nocomplain var
@ -59,7 +64,7 @@ proc read_ngspice_raw {arr fp} {
}
}
proc get_voltage {arr n } {
proc ngspice::get_voltage {arr n } {
upvar $arr var
set m "v($n)"
if { ! [info exists var([string tolower $m])] } {
@ -73,7 +78,7 @@ proc get_voltage {arr n } {
# return DELETE
}
proc get_diff_voltage {arr p m } {
proc ngspice::get_diff_voltage {arr p m } {
upvar $arr var
set pp "v($p)"
set mm "v($m)"
@ -87,8 +92,7 @@ proc get_diff_voltage {arr p m } {
# return DELETE
}
proc get_current {arr n } {
global current_probe
proc ngspice::get_current {arr n } {
upvar $arr var
if { [xschem get currsch] > 0 } {
set n "i(v.$n)"
@ -104,9 +108,18 @@ proc get_current {arr n } {
}
proc get_ngspice_node {n} {
set n [string tolower $n]
set err [catch {set ::ngspice::ngspice_data($n)} res]
if { $err } {
puts $res
set res {}
}
return $res
}
proc annotate {} {
upvar ::ngspice::ngspice_data arr
set rawfile "[xschem get netlist_dir]/[file rootname [file tail [xschem get schname 0]]].raw"
if { ![file exists $rawfile] } {
puts "no raw file found: $rawfile"
@ -116,7 +129,7 @@ proc annotate {} {
fconfigure $fp -translation binary
set op_point_read 0
while 1 {
read_ngspice_raw arr $fp
ngspice::read_ngspice_raw arr $fp
if { [info exists arr(n\ points)] } {
if { $arr(n\ points) == 1 } {
set op_point_read 1; break
@ -136,22 +149,22 @@ proc annotate {} {
for { set i 0 } { $i < $lastinst } {incr i } {
set name [xschem getprop instance $i name]
set type [xschem getprop instance $i cell::type]
if { [regexp {(^|/)probe$} $type ] } {
if { $type eq {probe} } {
set net $path[xschem instance_net $i p]
if {[catch {xschem setprop $i voltage [get_voltage arr $net] fast} err]} {
puts "Error 1: ${err}, net: $net"
if {[catch {xschem setprop $i voltage [ngspice::get_voltage arr $net] fast} err]} {
puts "Warning 1: ${err}, net: $net"
}
}
if { [regexp {current_probe$} $type ] } {
if {[catch {xschem setprop $i current [get_current arr $path$name] fast} err]} {
puts "Error 2: $err"
if { $type eq {current_probe} } {
if {[catch {xschem setprop $i current [ngspice::get_current arr $path$name] fast} err]} {
puts "Warning 2: $err"
}
}
if { [regexp {differential_probe$} $type ] } {
if { $type eq {differential_probe} } {
set netp $path[xschem instance_net $i p]
set netm $path[xschem instance_net $i m]
if {[catch {xschem setprop $i voltage [get_diff_voltage arr $netp $netm] fast} err]} {
puts "Error 3: $err"
if {[catch {xschem setprop $i voltage [ngspice::get_diff_voltage arr $netp $netm] fast} err]} {
puts "Warning 3: $err"
}
}
# puts "$i $name $type"

View File

@ -11,7 +11,7 @@ BEGIN{
# LDYMS[12]
{
line[lines++] = $1 " " hash_string($1)
line[lines++] = $0 " " hash_string($1)
}
@ -22,8 +22,8 @@ END{
print line[i] > FILENAME
}
close(FILENAME)
system("sort -k 2 " FILENAME " | awk '{ print $1}' > " FILENAME ".xxxxx")
system("mv " FILENAME ".xxxxx " FILENAME)
system("sort -k 2 " FILENAME " | awk '{$NF=\"\"; print $0}' > " "." FILENAME ".xxxxx")
system("mv ." FILENAME ".xxxxx " FILENAME)
}

View File

@ -2601,7 +2601,22 @@ const char *translate(int inst, const char* s)
STR_ALLOC(&result, tmp + result_pos, &size);
memcpy(result+result_pos,tmp_sym_name, tmp+1);
result_pos+=tmp;
} else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
int i, mult;
int no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
prepare_netlist_structs(0);
for(i=0;i<no_of_pins;i++) {
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
if (!strcmp( get_tok_value(prop,"name",0), token+2)) {
if(strcmp(get_tok_value(prop,"spice_ignore",0), "true")) {
const char *str_ptr = net_name(inst,i, &mult, 0);
tmp = strlen(str_ptr) +100 ;
STR_ALLOC(&result, tmp + result_pos, &size);
result_pos += my_snprintf(result + result_pos, tmp, "%s", str_ptr);
}
break;
}
}
} else if(token[0]=='@' && token[1]=='#') {
int n;
char *pin_attr = my_malloc(532, sizetok * sizeof(char));

View File

@ -1866,11 +1866,12 @@ proc tclpropeval {s instname symname} {
# this hook is called in translate() if whole string is contained in a tcleval(...) construct
proc tclpropeval2 {s} {
# puts "tclpropeval2: $s $instname $symname"
set path [string range [xschem get sch_path] 1 end]
regsub {^tcleval\(} $s {} s
regsub {\)([ \n\t]*)$} $s {\1} s
if { [catch {subst $s} res] } {
puts "tclpropeval2: $res"
set res $s
puts "tclpropeval2 warning: $res"
set res {?}
}
return $res
}

View File

@ -0,0 +1,14 @@
v {xschem version=2.9.8 file_version=1.2}
G {}
K {type=raw_data_show
vhdl_ignore=true
spice_ignore=false
verilog_ignore=true
tedax_ignore=true
template="name=r1"}
V {}
S {}
E {}
L 15 -0 -0 5 -5 {}
B 5 -0.46875 -0.46875 0.46875 0.46875 {name=p dir=xxx}
T {tcleval( [format %.4g [ get_ngspice_node v([set path]@@p\\) ] ] )} 6.875 -13.59375 0 0 0.2 0.2 {vcenter=true layer=15}

View File

@ -103,6 +103,9 @@ write cmos_example.raw
set appendwrite
let cap = cap + 2e-12
end
op
write cmos_example.raw
.endc
** ngspice
@ -111,3 +114,12 @@ end
** xyce, not needed if -r given om cmdline
* .print tran format=raw v(diffout) v(plus) v(minus)
" net_name=true}
C {spice_probe_dynamic.sym} 430 -350 0 0 {name=r1}
C {spice_probe_dynamic.sym} 480 -430 0 0 {name=r2}
C {spice_probe_dynamic.sym} 550 -500 0 0 {name=r3}
C {spice_probe_dynamic.sym} 620 -360 0 0 {name=r4}
C {spice_probe_dynamic.sym} 330 -180 0 0 {name=r5}
C {spice_probe_dynamic.sym} 30 -370 0 0 {name=r6}
C {spice_probe_dynamic.sym} 30 -240 0 0 {name=r7}
C {spice_probe_dynamic.sym} 30 -520 0 0 {name=r8}
C {spice_probe_dynamic.sym} 500 -210 0 0 {name=r9}

View File

@ -147,8 +147,8 @@ C {lab_pin.sym} 340 -970 0 1 {name=p23 lab=E2}
C {lab_pin.sym} 560 -970 0 1 {name=p28 lab=E6}
C {lab_pin.sym} 840 -1000 0 0 {name=p29 lab=E4}
C {lab_pin.sym} 180 -1120 0 0 {name=p34 lab=VBOOST}
C {ammeter.sym} 1110 -540 0 0 {name=vd net_name=true current=0.2093}
C {ammeter.sym} 1110 -640 0 0 {name=vu net_name=true current=0.2336}
C {ammeter.sym} 1110 -540 0 0 {name=vd net_name=true current=0.2229}
C {ammeter.sym} 1110 -640 0 0 {name=vu net_name=true current=0.2165}
C {lab_pin.sym} 60 -1180 0 0 {name=p27 lab=VPP}
C {pnp.sym} 200 -950 0 1 {name=Q1 model=q2n2907p area=1 net_name=true}
C {pnp.sym} 360 -790 0 1 {name=Q2 model=q2n2907p area=1 net_name=true}
@ -230,34 +230,30 @@ C {lab_pin.sym} 180 -690 0 0 {name=p8 lab=C7}
C {lab_pin.sym} 340 -710 0 1 {name=p31 lab=C2}
C {title.sym} 160 -30 0 0 {name=l2 author="Stefan Schippers"}
C {lab_pin.sym} 930 -700 0 0 {name=p32 lab=SA}
C {ammeter.sym} 1110 -350 0 0 {name=v0 net_name=true current=0.2288}
C {ammeter.sym} 1110 -350 0 0 {name=v0 net_name=true current=0.2423}
C {lab_pin.sym} 930 -380 0 0 {name=p35 lab=SB}
C {ammeter.sym} 560 -890 0 0 {name=v1 net_name=true current=0.01956}
C {ammeter.sym} 340 -890 0 0 {name=v2 net_name=true current=0.01947}
C {ammeter.sym} 260 -310 0 0 {name=v3 net_name=true current=0.03924}
C {ammeter.sym} 770 -440 3 0 {name=v4 net_name=true current=0.01942}
C {ammeter.sym} 690 -680 0 0 {name=v5 net_name=true current=0.006271}
C {ammeter.sym} 180 -870 0 1 {name=v6 net_name=true current=0.01955}
C {ammeter.sym} 840 -890 0 0 {name=v7 net_name=true current=0.0195}
C {spice_probe.sym} 1010 -440 0 0 {name=p36 analysis=tran voltage=-46.31}
C {spice_probe_vdiff.sym} 930 -410 0 0 {name=p37 analysis=tran voltage=3.689}
C {spice_probe_vdiff.sym} 930 -730 0 0 {name=p38 analysis=tran voltage=3.691}
C {spice_probe.sym} 1010 -760 0 0 {name=p39 analysis=tran voltage=3.814}
C {spice_probe.sym} 1220 -590 0 0 {name=p40 analysis=tran voltage=0.1231}
C {spice_probe.sym} 380 -530 0 0 {name=p41 analysis=tran voltage=21.3}
C {spice_probe.sym} 140 -530 0 1 {name=p42 analysis=tran voltage=21.3}
C {spice_probe.sym} 250 -470 0 1 {name=p43 analysis=tran voltage=20.61}
C {spice_probe.sym} 440 -790 0 0 {name=p44 analysis=tran voltage=48.22}
C {spice_probe.sym} 280 -950 0 0 {name=p45 analysis=tran voltage=48.22}
C {spice_probe.sym} 730 -810 0 0 {name=p46 analysis=tran voltage=25.21}
C {spice_probe.sym} 610 -1180 0 0 {name=p47 analysis=tran voltage=50}
C {spice_probe.sym} 760 -1120 0 0 {name=p48 analysis=tran voltage=50}
C {ammeter.sym} 1300 -590 3 0 {name=v8 net_name=true current=0.03055}
C {spice_probe.sym} 1110 -280 0 0 {name=p49 analysis=tran voltage=-50}
C {spice_probe.sym} 280 -630 0 1 {name=p50 analysis=tran voltage=42.36}
C {spice_probe.sym} 340 -820 0 1 {name=p51 analysis=tran voltage=49.03}
C {spice_probe.sym} 120 -210 0 1 {name=p52 analysis=tran voltage=-42.58}
C {spice_probe.sym} 130 -70 0 1 {name=p53 analysis=tran voltage=-50}
C {ammeter.sym} 560 -890 0 0 {name=v1 net_name=true current=0.01959}
C {ammeter.sym} 340 -890 0 0 {name=v2 net_name=true current=0.01949}
C {ammeter.sym} 260 -310 0 0 {name=v3 net_name=true current=0.03924}
C {ammeter.sym} 770 -440 3 0 {name=v4 net_name=true current=0.01944}
C {ammeter.sym} 690 -680 0 0 {name=v5 net_name=true current=0.006183}
C {ammeter.sym} 180 -870 0 1 {name=v6 net_name=true current=0.01952}
C {ammeter.sym} 840 -890 0 0 {name=v7 net_name=true current=0.01947}
C {spice_probe.sym} 1010 -440 0 0 {name=p36 analysis=tran voltage=-46.14}
C {spice_probe_vdiff.sym} 930 -410 0 0 {name=p37 analysis=tran voltage=3.693}
C {spice_probe_vdiff.sym} 930 -730 0 0 {name=p38 analysis=tran voltage=3.685}
C {spice_probe.sym} 1010 -760 0 0 {name=p39 analysis=tran voltage=3.548}
C {spice_probe.sym} 1220 -590 0 0 {name=p40 analysis=tran voltage=-0.1372}
C {spice_probe.sym} 380 -530 0 0 {name=p41 analysis=tran }
C {spice_probe.sym} 140 -530 0 1 {name=p42 analysis=tran }
C {spice_probe.sym} 250 -470 0 1 {name=p43 analysis=tran voltage=20.38}
C {spice_probe.sym} 440 -790 0 0 {name=p44 analysis=tran voltage=48.05}
C {spice_probe.sym} 280 -950 0 0 {name=p45 analysis=tran voltage=47.26}
C {spice_probe.sym} 730 -810 0 0 {name=p46 analysis=tran voltage=24.6}
C {ammeter.sym} 1300 -590 3 0 {name=v8 net_name=true current=-2.1207e-04}
C {spice_probe.sym} 280 -630 0 1 {name=p50 analysis=tran voltage=42.18}
C {spice_probe.sym} 340 -820 0 1 {name=p51 analysis=tran voltage=48.86}
C {spice_probe.sym} 120 -210 0 1 {name=p52 analysis=tran voltage=-42.41}
C {opin.sym} 600 -130 0 0 {name=p5 lab=OUT}
C {ipin.sym} 530 -180 0 0 {name=p1 lab=MINUS}
C {ipin.sym} 530 -140 0 0 {name=p4 lab=VSS}
@ -287,3 +283,8 @@ tclcommand="
xschem redraw
"
}
C {spice_probe_dynamic.sym} 750 -1120 0 0 {name=p54}
C {spice_probe.sym} 690 -1180 0 0 {name=p47 analysis=tran }
C {spice_probe.sym} 1110 -280 0 0 {name=p49 analysis=tran }
C {spice_probe_dynamic.sym} 180 -760 0 0 {name=p53}
C {spice_probe_dynamic.sym} 560 -710 0 0 {name=p55}

View File

@ -102,7 +102,7 @@ vvss vss 0 dc 0
.param frequ=20k
.param gain=42
* .op
.op
.tran 6e-7 0.009 uic
@ -111,6 +111,7 @@ vvss vss 0 dc 0
** referenced file in simulation directory.
.include \\"models_poweramp.txt\\"
.save all
.option savecurrents
* .FOUR 20k v(outm,outp)
* .probe i(*)
* .probe p(r*) p(v*)
@ -181,8 +182,37 @@ C {lab_pin.sym} 350 -270 0 0 {name=p19 lab=FB}
C {lab_pin.sym} 350 -730 0 0 {name=p25 lab=FBN}
C {title.sym} 160 -30 0 0 {name=l2 author="Stefan Schippers"}
C {lab_pin.sym} 880 -1250 0 0 {name=p27 lab=IN_INT}
C {ammeter.sym} 340 -1250 3 0 {name=vcurrvpp current=0.5636 net_name=true}
C {spice_probe.sym} 790 -700 0 0 {name=p40 analysis=tran voltage=-0.1372}
C {spice_probe.sym} 770 -240 0 0 {name=p29 analysis=tran voltage=-0.1372}
C {ammeter.sym} 340 -1090 3 0 {name=vcurrvnn current=-0.5715 net_name=true}
C {ammeter.sym} 340 -1170 3 0 {name=vcurrvss current=0.007914 net_name=true}
C {ammeter.sym} 340 -1250 3 0 {name=vcurrvpp net_name=true current=0.5636}
C {spice_probe.sym} 790 -700 0 0 {name=p40 analysis=tran voltage=-0.1372}
C {spice_probe.sym} 770 -240 0 0 {name=p29 analysis=tran voltage=-0.1372}
C {ammeter.sym} 340 -1090 3 0 {name=vcurrvnn net_name=true current=-0.5715}
C {ammeter.sym} 340 -1170 3 0 {name=vcurrvss net_name=true current=0.007914}
C {launcher.sym} 780 -120 0 0 {name=h2
descr="Ctrl-Click
Clear all probes"
tclcommand="
xschem push_undo
xschem set no_undo 1
xschem set no_draw 1
set lastinst [xschem get instances]
for \{ set i 0 \} \{ $i < $lastinst \} \{incr i \} \{
set type [xschem getprop instance $i cell::type]
if \{ [regexp \{(^|/)probe$\} $type ] \} \{
xschem setprop $i voltage fast
\}
if \{ [regexp \{current_probe$\} $type ] \} \{
xschem setprop $i current fast
\}
if \{ [regexp \{differential_probe$\} $type ] \} \{
xschem setprop $i voltage fast
\}
\}
xschem set no_undo 0
xschem set no_draw 0
xschem redraw
"
}
C {spice_probe.sym} 250 -220 0 0 {name=p30 analysis=tran voltage=21.07}
C {spice_probe.sym} 250 -680 0 0 {name=p33 analysis=tran voltage=21.07}
C {spice_probe_dynamic.sym} 350 -810 0 1 {name=p55}