updated test schematics to use new xschem annotate_op instead of ngspice::annotate
This commit is contained in:
parent
9c89a08111
commit
6f907b5430
|
|
@ -24,9 +24,10 @@
|
|||
namespace eval ngspice {
|
||||
# Create a variable inside the namespace
|
||||
variable ngspice_data
|
||||
variable op_point_read
|
||||
}
|
||||
|
||||
proc ngspice::read_ngspice_raw {arr fp} {
|
||||
proc ngspice::read_raw_dataset {arr fp} {
|
||||
upvar $arr var
|
||||
|
||||
unset -nocomplain var
|
||||
|
|
@ -66,50 +67,38 @@ proc ngspice::read_ngspice_raw {arr fp} {
|
|||
}
|
||||
}
|
||||
|
||||
proc ngspice::get_voltage_probe {arr n } {
|
||||
upvar $arr var
|
||||
set m "v($n)"
|
||||
if { ! [info exists var([string tolower $m])] } {
|
||||
set m $n
|
||||
}
|
||||
if { abs($var([string tolower $m])) < 1e-3 } {
|
||||
return [format %.4e $var([string tolower $m])]
|
||||
} else {
|
||||
return [format %.4g $var([string tolower $m])]
|
||||
}
|
||||
# return DELETE
|
||||
}
|
||||
proc ngspice::read_raw {{f {}}} {
|
||||
upvar ngspice::ngspice_data arr
|
||||
|
||||
proc ngspice::get_diff_probe {arr p m } {
|
||||
upvar $arr var
|
||||
set pp "v($p)"
|
||||
set mm "v($m)"
|
||||
if { ! [info exists var([string tolower $pp])] } {
|
||||
set pp $p
|
||||
}
|
||||
if { ! [info exists var([string tolower $mm])] } {
|
||||
set mm $m
|
||||
}
|
||||
return [format %.4g [expr {$var([string tolower $pp]) - $var([string tolower $mm])} ] ]
|
||||
# return DELETE
|
||||
}
|
||||
|
||||
proc ngspice::get_curr_probe {arr n } {
|
||||
upvar $arr var
|
||||
if { [xschem get currsch] > 0 } {
|
||||
set n "i(v.$n)"
|
||||
if { $f eq {}} {
|
||||
set rawfile "$::netlist_dir/[file rootname [file tail [xschem get schname 0]]].raw"
|
||||
} else {
|
||||
set n "i($n)"
|
||||
set rawfile $f
|
||||
}
|
||||
if {abs($var([string tolower $n])) <1e-3} {
|
||||
return [format %.4e $var([string tolower $n])]
|
||||
} else {
|
||||
return [format %.4g $var([string tolower $n])]
|
||||
if { ![file exists $rawfile] } {
|
||||
puts "no raw file found: $rawfile"
|
||||
return
|
||||
}
|
||||
set fp [open $rawfile r]
|
||||
fconfigure $fp -translation binary
|
||||
set ngspice::op_point_read 0
|
||||
## not needed: done in ngspice::read_ngspice_raw
|
||||
# array unset ngspice::ngspice_data
|
||||
while 1 {
|
||||
ngspice::read_raw_dataset arr $fp
|
||||
if { [info exists arr(n\ points)] } {
|
||||
if { $arr(n\ points) == 1 } {
|
||||
set ngspice::op_point_read 1; break
|
||||
}
|
||||
} else break;
|
||||
}
|
||||
close $fp
|
||||
puts {Raw file read ...}
|
||||
if { !$ngspice::op_point_read } {
|
||||
puts "no operating point found!"
|
||||
}
|
||||
# return DELETE
|
||||
}
|
||||
|
||||
|
||||
proc ngspice::get_current {n} {
|
||||
global path graph_raw_level
|
||||
set path [string range [xschem get sch_path] 1 end]
|
||||
|
|
@ -148,6 +137,46 @@ proc ngspice::get_current {n} {
|
|||
return $res
|
||||
}
|
||||
|
||||
proc ngspice::get_diff_voltage {n m} {
|
||||
global path graph_raw_level
|
||||
set path [string range [xschem get sch_path] 1 end]
|
||||
# skip hierarchy components above the level where raw file has been loaded.
|
||||
# node path names to look up in raw file begin from there.
|
||||
set skip 0
|
||||
while { $skip < $graph_raw_level } {
|
||||
regsub {^[^.]*\.} $path {} path
|
||||
incr skip
|
||||
}
|
||||
set n [string tolower $n]
|
||||
set m [string tolower $m]
|
||||
set nn $path$n
|
||||
set mm $path$m
|
||||
set errn [catch {set ngspice::ngspice_data($nn)} resn]
|
||||
if {$errn} {
|
||||
set nn v(${path}${n})
|
||||
set errn [catch {set ngspice::ngspice_data($nn)} resn]
|
||||
}
|
||||
set errm [catch {set ngspice::ngspice_data($mm)} resm]
|
||||
if {$errm} {
|
||||
set mm v(${path}${m})
|
||||
set errm [catch {set ngspice::ngspice_data($mm)} resm]
|
||||
}
|
||||
if { $errn || $errm} {
|
||||
set res {?}
|
||||
} else {
|
||||
set res [expr {$resn - $resm}]
|
||||
if { abs($res) <1e-5} {
|
||||
set res 0
|
||||
} elseif { abs($res) <1e-3 && $res != 0.0} {
|
||||
set res [ format %.4e $res ]
|
||||
} else {
|
||||
set res [ format %.4g $res ]
|
||||
}
|
||||
}
|
||||
return $res
|
||||
}
|
||||
|
||||
|
||||
proc ngspice::get_voltage {n} {
|
||||
global path graph_raw_level
|
||||
set path [string range [xschem get sch_path] 1 end]
|
||||
|
|
@ -207,92 +236,4 @@ proc ngspice::get_node {n} {
|
|||
return $res
|
||||
}
|
||||
|
||||
proc ngspice::resetdata {} {
|
||||
array unset ngspice::ngspice_data
|
||||
}
|
||||
|
||||
proc ngspice::annotate {{f {}} {read_file 1}} {
|
||||
upvar ngspice::ngspice_data arr
|
||||
|
||||
|
||||
if { $read_file == 1} {
|
||||
if { $f eq {}} {
|
||||
set rawfile "$::netlist_dir/[file rootname [file tail [xschem get schname 0]]].raw"
|
||||
} else {
|
||||
set rawfile $f
|
||||
}
|
||||
if { ![file exists $rawfile] } {
|
||||
puts "no raw file found: $rawfile"
|
||||
return
|
||||
}
|
||||
set fp [open $rawfile r]
|
||||
fconfigure $fp -translation binary
|
||||
set op_point_read 0
|
||||
## not needed: done in ngspice::read_ngspice_raw
|
||||
# array unset ngspice::ngspice_data
|
||||
while 1 {
|
||||
ngspice::read_ngspice_raw arr $fp
|
||||
if { [info exists arr(n\ points)] } {
|
||||
if { $arr(n\ points) == 1 } {
|
||||
set op_point_read 1; break
|
||||
}
|
||||
} else break;
|
||||
}
|
||||
close $fp
|
||||
puts {Raw file read ...}
|
||||
} else {
|
||||
set op_point_read 1
|
||||
}
|
||||
|
||||
|
||||
if { $op_point_read } {
|
||||
### disable screen redraw and undo when looping to speed up performance
|
||||
### but save state on undo stack before doing backannotations.
|
||||
|
||||
if {0} {
|
||||
xschem push_undo
|
||||
xschem set no_undo 1
|
||||
xschem set no_draw 1
|
||||
set lastinst [xschem get instances]
|
||||
set path [string range [xschem get sch_path] 1 end]
|
||||
for { set i 0 } { $i < $lastinst } {incr i } {
|
||||
set name [xschem getprop instance $i name]
|
||||
set type [xschem getprop instance $i cell::type]
|
||||
if { $type eq {probe} } {
|
||||
set net $path[xschem instance_net $i p]
|
||||
if {[catch {xschem setprop instance $i voltage [ngspice::get_voltage_probe arr $net] fast} err]} {
|
||||
puts "Warning 1: ${err}, net: $net"
|
||||
}
|
||||
}
|
||||
if { $type eq {current_probe} } {
|
||||
if {[catch {xschem setprop instance $i current [ngspice::get_curr_probe arr $path$name] fast} err]} {
|
||||
puts "Warning 2: $err"
|
||||
}
|
||||
}
|
||||
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 instance $i voltage [ngspice::get_diff_probe arr $netp $netm] fast} err]} {
|
||||
puts "Warning 3: $err"
|
||||
}
|
||||
}
|
||||
# puts "$i $name $type"
|
||||
}
|
||||
|
||||
# re-enable undo and draw
|
||||
xschem set no_undo 0
|
||||
xschem set no_draw 0
|
||||
|
||||
### xschem setprop instructions have not altered circuit topology so
|
||||
### in this case a connectivity rebuild is not needed.
|
||||
# xschem rebuild_connectivity
|
||||
#
|
||||
#
|
||||
} ;# if {0}
|
||||
xschem redraw
|
||||
} else {
|
||||
puts "no operating point found!"
|
||||
}
|
||||
}
|
||||
|
||||
# if { [info exists ::has_x] } {bind .drw <Alt-a> {puts {Annotating...}; ngspice::annotate} }
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ S {}
|
|||
E {}
|
||||
B 5 -1.25 -1.25 1.25 1.25 {name=p dir=in}
|
||||
T {@lab} -2.5 -1.25 2 0 0.27 0.27 {}
|
||||
T {@spice_get_voltage} -1.875 10.15625 0 1 0.2 0.2 {vcenter=true layer=15 hide=true}
|
||||
T {@spice_get_voltage} 1.875 10.15625 0 0 0.2 0.2 {vcenter=true layer=15 hide=true}
|
||||
|
|
|
|||
|
|
@ -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 {type=differential_probe
|
||||
format=".save v(@@p\\\\) v(@@m\\\\)"
|
||||
|
|
@ -6,18 +7,9 @@ template="name=p1"}
|
|||
V {}
|
||||
S {}
|
||||
E {}
|
||||
L 15 0 -17.5 0 -12.5 {}
|
||||
L 15 -2.5 -15 2.5 -15 {}
|
||||
L 15 -2.5 15 2.5 15 {}
|
||||
L 15 -5 0 0 0 {}
|
||||
L 15 0 -3.75 0 0 {}
|
||||
L 15 0 -3.75 3.75 -3.75 {}
|
||||
L 15 3.75 -3.75 3.75 0 {}
|
||||
L 15 3.75 0 7.5 0 {}
|
||||
L 15 7.5 -3.75 7.5 0 {}
|
||||
L 15 7.5 -3.75 10.3125 -3.75 {}
|
||||
L 15 -7.5 -7.5 -7.5 6.25 {}
|
||||
L 15 -10 3.75 11.25 3.75 {}
|
||||
L 15 0 -15 0 -10 {}
|
||||
L 15 -2.5 -12.5 2.5 -12.5 {}
|
||||
L 15 -2.5 12.5 2.5 12.5 {}
|
||||
B 5 -1.25 -21.25 1.25 -18.75 {name=p dir=in}
|
||||
B 5 -1.25 18.75 1.25 21.25 {name=m dir=in}
|
||||
T {@voltage} 15 -5 0 0 0.2 0.2 {layer=15}
|
||||
T {tcleval([ngspice::get_diff_voltage @@p @@m ])} 1.875 -6.09375 0 0 0.2 0.2 {layer=15 hcenter=true}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ device="ceramic capacitor" net_name=true}
|
|||
C {lab_pin.sym} 500 -430 0 0 {name=p12 lab=G net_name=true}
|
||||
C {launcher.sym} 700 -60 0 0 {name=h1
|
||||
descr=Backannotate
|
||||
tclcommand="ngspice::annotate"}
|
||||
tclcommand="xschem annotate_op"}
|
||||
C {launcher.sym} 700 -110 0 0 {name=h2
|
||||
descr="View raw file"
|
||||
tclcommand="textwindow $netlist_dir/cmos_example.raw"}
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ C {ammeter.sym} 700 -440 3 0 {name=v4 net_name=true }
|
|||
C {ammeter.sym} 690 -680 0 0 {name=v5 net_name=true }
|
||||
C {ammeter.sym} 180 -870 0 1 {name=v6 net_name=true }
|
||||
C {ammeter.sym} 840 -890 0 0 {name=v7 net_name=true }
|
||||
C {spice_probe_vdiff.sym} 860 -410 0 0 {name=p37 voltage=3.688}
|
||||
C {spice_probe_vdiff.sym} 860 -410 0 0 {name=p37 }
|
||||
C {spice_probe_vdiff.sym} 860 -730 0 0 {name=p38 voltage=3.68}
|
||||
C {ammeter.sym} 1300 -590 3 0 {name=v8 net_name=true }
|
||||
C {opin.sym} 600 -130 0 0 {name=p5 lab=OUT}
|
||||
|
|
@ -456,7 +456,7 @@ C {spice_probe.sym} 180 -720 0 0 {name=p59 voltage=47.27}
|
|||
C {spice_probe.sym} 1020 -1120 0 0 {name=p62 voltage=49.04}
|
||||
C {launcher.sym} 770 -110 0 0 {name=h1
|
||||
descr=Backannotate
|
||||
tclcommand="ngspice::annotate"}
|
||||
tclcommand="xschem annotate_op"}
|
||||
C {launcher.sym} 770 -150 0 0 {name=h4
|
||||
descr="View Raw file"
|
||||
tclcommand="textwindow $netlist_dir/[file tail [file rootname [ xschem get schname 0 ] ] ].raw"
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
@ -184,5 +185,5 @@ m=1}
|
|||
C {lab_pin.sym} 1030 -760 0 0 {name=p17 lab=VSS}
|
||||
C {launcher.sym} 660 -350 0 0 {name=h1
|
||||
descr=Backannotate
|
||||
tclcommand="ngspice::annotate"}
|
||||
tclcommand="xschem annotate_op"}
|
||||
C {spice_probe.sym} 550 -620 0 0 {name=p19 analysis=tran voltage=21.07}
|
||||
|
|
|
|||
Loading…
Reference in New Issue