From 3bbba8601f289f7a858834b8e07624fbccd0154b Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Tue, 20 Oct 2020 12:44:10 +0200 Subject: [PATCH] added ngspiec_probe.sym and ngspice_get_value.sym that use a pull method to fetch values from ngspice .raw datafile, fixed a long standing bug that changed bounding boxes of symbols that were selected for a copy if they were copied and copy operation involved rotations of flips. --- src/move.c | 17 ++-- src/ngspice_backannotate.tcl | 8 +- xschem_library/devices/ngspice_get_value.sym | 13 +++ ...ce_probe_dynamic.sym => ngspice_probe.sym} | 2 +- xschem_library/examples/cmos_example.sch | 23 +++-- xschem_library/examples/mos_power_ampli.sch | 98 ++++++++++--------- xschem_library/examples/poweramp.sch | 2 +- 7 files changed, 97 insertions(+), 66 deletions(-) create mode 100644 xschem_library/devices/ngspice_get_value.sym rename xschem_library/devices/{spice_probe_dynamic.sym => ngspice_probe.sym} (67%) diff --git a/src/move.c b/src/move.c index 4dd3ec24..722c8b59 100644 --- a/src/move.c +++ b/src/move.c @@ -169,7 +169,7 @@ void check_collapsing_objects() } } -void update_symbol_bboxes() +void update_symbol_bboxes(int rot, int flip) { int i, n, save_flip, save_rot; @@ -527,7 +527,7 @@ void copy_objects(int what) my_strdup(225, &str, user_conf_dir); my_strcat(226, &str, "/.selection.sch"); xunlink(str); - update_symbol_bboxes(); + update_symbol_bboxes(rot, flip); my_free(818, &str); } if(what & RUBBER) /* draw objects while moving */ @@ -543,13 +543,13 @@ void copy_objects(int what) if(what & ROTATE) { draw_selection(gctiled,0); rot= (rot+1) & 0x3; - update_symbol_bboxes(); + update_symbol_bboxes(rot, flip); } if(what & FLIP) { draw_selection(gctiled,0); flip = !flip; - update_symbol_bboxes(); + update_symbol_bboxes(rot, flip); } if(what & END) /* copy selected objects */ { @@ -855,6 +855,9 @@ void copy_objects(int what) break; case ELEMENT: if(k==0) { + /* if the copy operation involved flip or rotations the original element bboxes were changed. + restore them now */ + update_symbol_bboxes(0, 0); if(firsti) { prepared_hash_instances = 0; firsti = 0; @@ -990,7 +993,7 @@ void move_objects(int what, int merge, double dx, double dy) rot=flip=deltax=deltay=0; ui_state &= ~STARTMOVE; ui_state &= ~PLACE_SYMBOL; - update_symbol_bboxes(); + update_symbol_bboxes(0, 0); } if(what & RUBBER) /* abort operation */ { @@ -1005,13 +1008,13 @@ void move_objects(int what, int merge, double dx, double dy) if(what & ROTATE) { draw_selection(gctiled,0); rot= (rot+1) & 0x3; - update_symbol_bboxes(); + update_symbol_bboxes(rot, flip); } if(what & FLIP) { draw_selection(gctiled,0); flip = !flip; - update_symbol_bboxes(); + update_symbol_bboxes(rot, flip); } if(what & END) /* move selected objects */ { diff --git a/src/ngspice_backannotate.tcl b/src/ngspice_backannotate.tcl index e6005db6..aeee7880 100644 --- a/src/ngspice_backannotate.tcl +++ b/src/ngspice_backannotate.tcl @@ -110,10 +110,16 @@ proc ngspice::get_current {arr n } { proc get_ngspice_node {n} { set n [string tolower $n] + if { [regexp -all \\. $n] == 1} { + regsub {@.\.} $n {@} n + } + set err [catch {set ::ngspice::ngspice_data($n)} res] if { $err } { - puts $res + # puts "get_ngspice_node: $res" set res {} + } else { + set res [ format %.4g $res ] } return $res } diff --git a/xschem_library/devices/ngspice_get_value.sym b/xschem_library/devices/ngspice_get_value.sym new file mode 100644 index 00000000..2df165d3 --- /dev/null +++ b/xschem_library/devices/ngspice_get_value.sym @@ -0,0 +1,13 @@ +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 node=xxx"} +V {} +S {} +E {} +T {tcleval([ get_ngspice_node [subst -nocommand \{@node\\\}] ] )} 6.875 -8.59375 0 0 0.25 0.25 {vcenter=true layer=15} +T {tcleval([regsub \{\\@(.*\\\\.)?\} [subst -nocommand \{@node\\\}] \{\} ] )} 6.875 -23.59375 0 0 0.25 0.25 {vcenter=true layer=15} diff --git a/xschem_library/devices/spice_probe_dynamic.sym b/xschem_library/devices/ngspice_probe.sym similarity index 67% rename from xschem_library/devices/spice_probe_dynamic.sym rename to xschem_library/devices/ngspice_probe.sym index e3a1bd93..a2fc99aa 100644 --- a/xschem_library/devices/spice_probe_dynamic.sym +++ b/xschem_library/devices/ngspice_probe.sym @@ -11,4 +11,4 @@ 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} +T {tcleval( [ get_ngspice_node v([set path]@@p\\) ] )} 6.875 -13.59375 0 0 0.2 0.2 {vcenter=true layer=15} diff --git a/xschem_library/examples/cmos_example.sch b/xschem_library/examples/cmos_example.sch index 8fb1d2ac..ae973d72 100644 --- a/xschem_library/examples/cmos_example.sch +++ b/xschem_library/examples/cmos_example.sch @@ -92,6 +92,7 @@ value=" ** models are generally not free: you must download ** SPICE models for active devices and put them into the below ** referenced file in netlist/simulation directory. +.option savecurrents .include \\"models_cmos_example.txt\\" .control let cap = 2e-12 @@ -114,12 +115,16 @@ write cmos_example.raw ** 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} +C {ngspice_probe.sym} 430 -350 0 0 {name=r1} +C {ngspice_probe.sym} 480 -430 0 0 {name=r2} +C {ngspice_probe.sym} 550 -500 0 0 {name=r3} +C {ngspice_probe.sym} 620 -360 0 0 {name=r4} +C {ngspice_probe.sym} 330 -180 0 0 {name=r5} +C {ngspice_probe.sym} 30 -370 0 0 {name=r6} +C {ngspice_probe.sym} 30 -240 0 0 {name=r7} +C {ngspice_probe.sym} 30 -520 0 0 {name=r8} +C {ngspice_probe.sym} 500 -210 0 0 {name=r9} +C {ngspice_get_value.sym} 590 -440 0 0 {name=r10 node=i(@m6[id])} +C {ngspice_get_value.sym} 410 -440 0 1 {name=r11 node=i(@m6[id])} +C {ngspice_get_value.sym} 530 -180 0 0 {name=r12 node=i(@m1[id])} +C {ngspice_get_value.sym} 210 -180 0 1 {name=r13 node=i(@m3[id])} diff --git a/xschem_library/examples/mos_power_ampli.sch b/xschem_library/examples/mos_power_ampli.sch index 80fc2fdd..bad6077c 100644 --- a/xschem_library/examples/mos_power_ampli.sch +++ b/xschem_library/examples/mos_power_ampli.sch @@ -59,7 +59,7 @@ N 1105 -1125 1115 -1125 {lab=VBOOST} N 1115 -1125 1120 -1120 {lab=VBOOST} N 840 -1120 1100 -1120 {lab=VBOOST} N 560 -1180 1110 -1180 {lab=VPP} -N 900 -440 1070 -440 {lab=GB} +N 830 -440 1070 -440 {lab=GB} N 560 -460 560 -440 {lab=C8} N 1200 -1120 1330 -1120 {lab=VBOOST} N 1200 -900 1200 -870 {lab=#net4} @@ -82,8 +82,8 @@ N 50 -70 180 -70 {lab=VNN} N 690 -600 1110 -600 {lab=#net1} N 180 -470 260 -470 {lab=E9} N 1110 -610 1110 -600 {lab=#net1} -N 1030 -380 1110 -380 {lab=SB} -N 1030 -700 1110 -700 {lab=SA} +N 960 -380 1110 -380 {lab=SB} +N 960 -700 1110 -700 {lab=SA} N 1200 -1120 1200 -960 {lab=VBOOST} N 1110 -410 1110 -380 {lab=SB} N 1110 -730 1110 -700 {lab=SA} @@ -102,19 +102,19 @@ N 560 -860 560 -820 {lab=#net6} N 560 -1020 560 -920 {lab=E6} N 340 -1020 340 -920 {lab=E2} N 260 -280 260 -240 {lab=C3} -N 800 -440 840 -440 {lab=#net7} -N 560 -440 740 -440 {lab=C8} +N 730 -440 770 -440 {lab=#net7} +N 560 -440 670 -440 {lab=C8} N 690 -650 690 -600 {lab=#net1} N 690 -730 690 -710 {lab=#net8} N 180 -840 180 -660 {lab=C7} N 840 -860 840 -840 {lab=E11} N 1200 -810 1200 -590 {lab=#net1} -N 930 -760 930 -750 {lab=GA} -N 930 -710 930 -700 {lab=SA} -N 930 -700 1030 -700 {lab=SA} -N 930 -440 930 -430 {lab=GB} -N 930 -390 930 -380 {lab=SB} -N 930 -380 1030 -380 {lab=SB} +N 860 -760 860 -750 {lab=GA} +N 860 -710 860 -700 {lab=SA} +N 860 -700 960 -700 {lab=SA} +N 860 -440 860 -430 {lab=GB} +N 860 -390 860 -380 {lab=SB} +N 860 -380 960 -380 {lab=SB} N 1200 -590 1270 -590 {lab=#net1} C {ipin.sym} 530 -160 0 0 {name=p0 lab=PLUS} C {ipin.sym} 530 -120 0 0 {name=p2 lab=VPP} @@ -123,14 +123,14 @@ C {nmos3.sym} 1090 -440 0 0 {name=xm2 model=irf540 m=1 program=evince url="https://www.vishay.com/docs/91021/91021.pdf" net_name=true} -C {res.sym} 1030 -410 0 1 {name=R7 m=1 value=190 net_name=true} +C {res.sym} 960 -410 0 1 {name=R7 m=1 value=190 net_name=true} C {nmos3.sym} 1090 -760 0 0 {name=xm1 model=irf540 m=1 program=evince url="https://www.vishay.com/docs/91021/91021.pdf" net_name=true} -C {res.sym} 1030 -730 0 1 {name=R0 m=1 value=190 net_name=true} +C {res.sym} 960 -730 0 1 {name=R0 m=1 value=190 net_name=true} C {lab_pin.sym} 1390 -590 0 1 {name=p14 lab=OUT} C {lab_pin.sym} 1110 -280 0 0 {name=p18 lab=VNN} -C {lab_wire.sym} 990 -440 0 0 {name=l8 lab=GB} +C {lab_wire.sym} 920 -440 0 0 {name=l8 lab=GB} C {res.sym} 340 -1050 0 1 {name=R2 m=1 value=50 net_name=true} C {res.sym} 180 -1050 0 1 {name=R3 m=1 value=50 net_name=true} C {lab_pin.sym} 340 -1080 0 0 {name=p10 lab=VPP} @@ -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.2229} -C {ammeter.sym} 1110 -640 0 0 {name=vu net_name=true current=0.2165} +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 {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} @@ -161,6 +161,7 @@ only_toplevel=true value=".option PARHIER=LOCAL RUNLVL=6 post MODMONTE=1 warn maxwarn=6000 .option sampling_method = SRS ingold=1 .option method=gear +.option savecurrents .temp 30 @@ -191,8 +192,8 @@ rload out 0 4 .op *.probe dc v(plus,vdc) "} -C {lab_wire.sym} 990 -760 0 0 {name=l1 lab=GA} -C {res.sym} 870 -440 1 1 {name=R11 m=1 value=1300 net_name=true} +C {lab_wire.sym} 920 -760 0 0 {name=l1 lab=GA} +C {res.sym} 800 -440 1 1 {name=R11 m=1 value=1300 net_name=true} C {pnp.sym} 540 -490 0 0 {name=Q8 model=q2n2907p area=1 net_name=true} C {capa.sym} 1200 -930 0 0 {name=C12 m=1 value="40u" net_name=true} C {diode.sym} 1200 -1150 0 0 {name=D0 model=d1n4148 area=1 @@ -229,31 +230,31 @@ C {npn.sym} 200 -630 0 1 {name=Q7 model=q2n2222 area=1 net_name=true} 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.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.01959} -C {ammeter.sym} 340 -890 0 0 {name=v2 net_name=true current=0.01949} +C {lab_pin.sym} 860 -700 0 0 {name=p32 lab=SA} +C {ammeter.sym} 1110 -350 0 0 {name=v0 net_name=true current=0.2288} +C {lab_pin.sym} 860 -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.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 {ammeter.sym} 700 -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} 940 -440 0 0 {name=p36 analysis=tran voltage=-46.31} +C {spice_probe_vdiff.sym} 860 -410 0 0 {name=p37 analysis=tran voltage=3.689} +C {spice_probe_vdiff.sym} 860 -730 0 0 {name=p38 analysis=tran voltage=3.691} +C {spice_probe.sym} 940 -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 {ammeter.sym} 1300 -590 3 0 {name=v8 net_name=true current=0.03055} +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 {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} @@ -283,8 +284,11 @@ 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} +C {ngspice_probe.sym} 750 -1120 0 0 {name=p54} +C {spice_probe.sym} 690 -1180 0 0 {name=p47 analysis=tran voltage=50} +C {spice_probe.sym} 1110 -280 0 0 {name=p49 analysis=tran voltage=-50} +C {ngspice_probe.sym} 180 -760 0 0 {name=p53} +C {ngspice_probe.sym} 560 -710 0 0 {name=p55} +C {ngspice_get_value.sym} 965 -710 0 0 {name=r48 node=i(@r.$\{path\}r0[i])} +C {ngspice_get_value.sym} 815 -955 0 1 {name=r1 node=i(@q.$\{path\}q4[ib])} +C {ngspice_get_value.sym} 845 -985 0 0 {name=r2 node=i(@q.$\{path\}q4[ic])} diff --git a/xschem_library/examples/poweramp.sch b/xschem_library/examples/poweramp.sch index a5b992d1..c0cac053 100644 --- a/xschem_library/examples/poweramp.sch +++ b/xschem_library/examples/poweramp.sch @@ -215,4 +215,4 @@ tclcommand=" } 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} +C {ngspice_probe.sym} 350 -810 0 1 {name=p55}