StefanSchippers / xschem

A schematic editor for VLSI/Asic/Analog custom designs, netlist backends for VHDL, Spice and Verilog. The tool is focused on hierarchy and parametric designs, to maximize circuit reuse.
Other
329 stars 20 forks source link

Simulations with differen corner-library (`.lib ../.../cornerMOSlv_psp.lib mos_tt and ...ss ...ff ...fs ...sf`), what would You do? #144

Closed StefanSchippers closed 8 months ago

StefanSchippers commented 11 months ago

@olisnr

if You want to make some simulations with differen corner-library (.lib ../.../cornerMOSlv_psp.lib mos_tt and ...ss ...ff ...fs ...sf), what would You do? i can use a launcher.sym to set a lib-variable and then xschem netlist; xschem simulate but i didnt figured out, how to wait of the end of the simulation before update the lib-variable, and simulate again. or i could use TCL to write different spice-netlists and run them in parallel (also without knowing when it ended)...

now it looks like:

corner

and the possibility to load different .raw-files is REALLY great!

Originally posted by @olisnr in https://github.com/StefanSchippers/xschem/issues/141#issuecomment-1816409510

olisnr commented 11 months ago

something i really dont get is the handling of " in xschems evaltcl. if i try some lines in tclsh:

    puts test
    puts {test test}
    puts "test test test"
    puts [return "test test test test"]
    puts [subst "test test test test test"]
    puts "\"test test test test test test test\""
    puts eval [return "test test test test test test test test"]

i get

test
test test
test test test
test test test test
test test test test test
"test test test test test test test"
test test test test test test test test

as result.

but in Xschem i get for:

value="tcleval(
    test
    {test test}
    "test test test"
    [return "test test test test"]
    [subst "test test test test test"]
    "\"test test test test test test test\""
    eval [return "test test test test test test test test"]
)"

this: tcl

is this correct? and how is it possible to print a substituted line (or even multiline) in tcleval() ?

StefanSchippers commented 11 months ago

To test what you get from a tcleval() you can use the tcl subst command:

the displayed values are correct:

the sequence:

value="tcleval(
    test
    {test test}
    "test test test"
    [return "test test test test"]
    [subst "test test test test test"]
    "\"test test test test test test test\""
    eval [return "test test test test test test test test"]
)"

is interpreted as:

value="tcleval(
    test
    {test test}
    "test

the double quote closes the opening double quote. Since the following test word has no spaces it is also considered. Anything following is discarded. If you want to use double quotes inside a "tcleval(.....)" you must escape them:

If you use this:

value="tcleval(
    test
    {test test}
    \"test test test\"
    [return \"test test test test\"]
    [subst \"test test test test test\"]
    \"test test test test test test test\"
    eval [return \"test test test test test test test test\"]
)"

you get 1

StefanSchippers commented 11 months ago

Remember subst (the command that is applied on the string inside tcleval(...) does only variable ($xxx) and command ([cmd]) substitution, anything else is returned as is. So a tcl command like eval or puts is not considered special by subst, it becomes a command to be substituted if it appears inside [...]

olisnr commented 11 months ago

thanks a lot!

StefanSchippers commented 11 months ago

I found the reason for the stuck tooltips and the fix. See video.

https://github.com/StefanSchippers/xschem/assets/69359491/902eb266-1474-4523-8a7c-7f3a04488221

StefanSchippers commented 11 months ago

If you find other usages where the stupid thing (the tk_messageBox) causes problems let me know, I am slowly getting rid of it everywhere. Unfortunately there are many such messageboxes around. I think This evening I will go for the final solution and get rid of tk_messageBox everywhere. It has caused too many problems everywhere, I am really pissed off and will remove this stupid thing.

olisnr commented 11 months ago

sometimes the "File" menue is on the other screen, but only on the left one.

menue

olisnr commented 11 months ago

i played a bit around, but i have no idea how to force this. normally the menus open under the mouse click...

StefanSchippers commented 11 months ago

May be the menu goes in the other screen if the left border of the xschem window is outside the monitor and goes (may be by one pixel) in the other screen? Don't know.

StefanSchippers commented 11 months ago

I remember you asked a way to generate netlists with different names, I was looking at it but can't find the post. Can you explain again?

olisnr commented 11 months ago

I remember you asked a way to generate netlists with different names, I was looking at it but can't find the post. Can you explain again?

thanks for the help, but i found out in the end and so i deleted the post. i did change the spice-code and the launcher:

name=h13 
descr="netlist simulate corners ALL" 
tclcommand="
    set schematic [file rootname [file tail [xschem get current_name]]]

    foreach corner $corners { # write different netlists
        set mos_corner ${corner}
        xschem netlist ${schematic}_mos${corner}.spice
    }

    puts netlists_written;

    foreach corner $corners { # simulate all netlists
        xschem set netlist_name ${schematic}_mos${corner}.spice
        set id_${corner} [simulate ]
    }

    puts sims_started;

    while {true} {
        set info_exists false;
        foreach corner $corners {
            set test_cmd [string cat {execute(cmd,} [set [string cat {id_} ${corner}]] \)]
            if {[info exists $test_cmd]} {
                set info_exists true;
            }
        }
        if {!$info_exists} {
            puts sim_ended;

            break;
        }
        puts -nonewline .; flush stdout;

        delay 99;
    }

    if {true} {
        xschem raw_clear;
        xschem annotate_op ${netlist_dir}/${schematic}_mostt.raw
    }

    puts done
"
name="NGSPiCE TCL"
simulator=ngspice
only_toplevel=true 

value="tcleval(
    .option rshunt = 1.0e9
    .option rseries = 1.0e-6

    .control
        pre_osdi ../IHP-Open-PDK-main/ihp-sg13g2/libs.tech/ngspice/openvaf/psp103_nqs.osdi
        pre_set strict_errorhandling **destroys ac simulation with .option savecurrents

        unset ngdebug

        .option maxwarns

        .param nw=$nw
        .param nl=$nl
        .param pw=$pw
        .param pl=$pl

        .param rset=1

        save all
        op
        write [rawfilestart]_mos${mos_corner}.raw
        write [rawfilestart]_dc_mos${mos_corner}.raw
        write [rawfilestart]_ac_mos${mos_corner}.raw
        write [rawfilestart]_temp_mos${mos_corner}.raw

        set appendwrite

        [return {* foreach begin}]
        [
            set code {};
            foreach r $r_list {
                append code \" \
                alterparam rset = $r \
                reset \
                save all \
                dc VDD 0 5.5 0.01 \
                write [rawfilestart]_dc_mos${mos_corner}.raw \
                ac dec 10 $fstart $fend \
                remzerovec \
                write [rawfilestart]_ac_mos${mos_corner}.raw \
                dc temp -40 160 20 \
                write [rawfilestart]_temp_mos${mos_corner}.raw \
                \";
            }
            return $code;
        ]
        [return {* end}]

        quit 
    .endc
)"

and there are some constants to control it:

name=COMMANDS
simulator=none
only_toplevel=false 

value="tcleval(

mosfet corners: [set corners [list tt ss ff sf fs]]

ac [set fstart 1e3]..[set fend 1e9]Hz;  do trans = [set do_trans 0]
r [set r_list [list 30k 100k 300k 1000k]]Ohm

pmos w/l = [set pw 20u]/[set pl 1u]
nmos w/l = [set nw 10u]/[set nl 1u]

[proc rawfilestart {} {
  global netlist_dir
  return ${netlist_dir}/[file rootname [file tail [xschem get current_name]]]
}]

[proc sim_is_none {} { return 0}] #proc to ignore "simulator=none" evaluation for ngspice

.raw-file path and namebase: [rawfilestart] 
)"

the hint about the \" was the salvation!

StefanSchippers commented 11 months ago

Don't know if you find this interesting. the set local_netlist_dir 1 will create a simulation/ directory where netlists and simulation data will go. There is now another setting: set local_netlist_dir 2. This will add one directory level as follows: library_dir/simulation/schematic_name/

example:

schippes@asus:~/.xschem/xschem_library/olisnr2$ ls -l simulation
total 12
drwxr-xr-x 2 schippes schippes 4096 Dec  1 17:38 aa_opamp_p_test03.sch
drwxr-xr-x 2 schippes schippes 4096 Dec  1 17:38 aa_opamp_p_testi03.sch
drwxr-xr-x 2 schippes schippes 4096 Dec  1 17:38 ihp_mos_gms_ngspice_05.sch

This way all simulation data will be in separate directories. Beware if you do a .include ../something this will probably need to be changed to .include ../../something. This was asked by some users doing doing lot of simulation on many sub-blocks of a big design and wanted to avoid cluttering the simulation directories with too many unrelated files.

olisnr commented 11 months ago

yes thats interesting. it should go into xschemrc? and .spiceinit stays in ../ ?

StefanSchippers commented 11 months ago

Yes, set local_netlist_dir 2 Or in Simulation menu.

olisnr commented 11 months ago

a bit a problem in my code is right now, that all the different launcher.sym and simulator_command.sym mutual overwrite the global variables. i think i have to put all the code in procedures.

there is some other thing i would like: if You are drawing wire or lines, it would be nice if You need as few keybord-buttons as possible. how would it be if You go in a wire or line mode and be able to edit like this: w 1st point click 2nd point click 3th point esc end of line (until now its like You implemented it) click 1st point next wire click 2nd point click 3th point... ups a bit wrong... del delet 3th point but stay in wireing mode click 3th point esc end of line esc end of wireing mode

instead of esc You also could use right-click (would be even better) but then there could be a conflict with the context-menue.

now clicking is selecting as bevore. what do You think?

StefanSchippers commented 11 months ago

a bit a problem in my code is right now, that all the different launcher.sym and simulator_command.sym mutual overwrite the global variables. i think i have to put all the code in procedures.

Yes if you need more variables instead of writing numerous commands in the global scope you can create a procedure and execute it:

proc myproc {} { cmd1 cmd2 cmd3 } myproc

For some mysterious reason tcl executes also faster this way (may be because looking up variables in a local namespace is faster). Remember to use a global varname statement at the beginning of the procedure if you need to access global variables from within a procedure, or use the syntax $::varname

StefanSchippers commented 11 months ago

for lines and wires when in persistent command mode the first escape clears the ongoing placement, the second escape ends the lining or wiring command. The delete function requires a little more work.

StefanSchippers commented 11 months ago

instead of esc You also could use right-click (would be even better) but then there could be a conflict with the context-menue.

Left button Double-Click does exactly that.

olisnr commented 11 months ago

instead of esc You also could use right-click (would be even better) but then there could be a conflict with the context-menue.

Left button Double-Click does exactly that.

yes. i didnt got it. its exactly what i wanted.

the command as procedure is also working now.

olisnr commented 11 months ago

can i also get rid of the messageboxes about the missing symbols.sch from symbols.sym, that have a schematic attribute?

missing sch

very effective is the menue "Properties - Edit file"

StefanSchippers commented 11 months ago

can i also get rid of the messageboxes about the missing symbols.sch from symbols.sym, that have a schematic attribute?

This can now be done by adding the attribute: default_schematic=ignore in the symbol. so if you have a placement of symbol.symdescend into the symbol and add default_schematic=ignore. Symbols with this attribute set will never be traversed so instances MUST specify a schematic attribute (schematic=symbol_rtl.sch or even schematic=symbol.sch if that specific instance wants the default schematic normally associated to symbol)

Symbols with this attribute become like virtual functions in C++, they will not be used directly by default.

olisnr commented 11 months ago

there is an other thing with the spice netlist. for some reason the line-lenght is limited. and this makes problems with the write command. as example the first is working but the second not:

                writes  /ALL/Xschem/design/simulation/aa_opamp_dual_supply_RjBaker_05_zoom_dc_mostt.raw
                ...
                writes 
+ /ALL/Xschem/design/simulation/aa_opamp_dual_supply_RjBaker_05_zoom_dc_mostt.raw
                ...
StefanSchippers commented 11 months ago

Thank you this is now fixed. User code is not touched now. Xschem needs to run a line breaker at the very end of the netlist generation, because many simulators have a maximum line length limit (and component blocks with [1023:0] bits I/O ports can generate very long lines). But breaking code written by the user definitely not good. I have also incremented the line length from 100 to 130 (less breaks)

olisnr commented 11 months ago

... But breaking code written by the user definitely not good. I have also incremented the line length from 100 to 130 (less breaks)

yes i think its better to let the user limit the line-size, because i had also problems using a spice library with many + linebreaks: Xschem made a mess with it, so that i had to remove all "\n+" and replace it with " ", to allow Xschem to brake the code it self. this isnt necessary further. and why did You change to 130? 130

then i have an other question. why is it necessary to declare default_schematic=ignore in thesymbol.sym file and why isnt it possible to write this per q in the schematic.sch ?

olisnr commented 11 months ago

im not sure how to do calculations on graphs from different files:

dB wtf dlg

should all be the same. i tried also () and ;; without luck...

StefanSchippers commented 11 months ago

the format is : "alias_name; expression [% [dataset] rawfile sim_type]" Example: "del; diffout 0.1u del() % 0 /home/schippes/.xschem/simulations/cmos_example_ngspice.raw tran"

It is not possible to pick one node from one file and do math operations with another node from another file, since the number of points is different (and on top of that transient timesteps are not uniform, it is very difficult to do).

Calculations on graphs are done point by point

1

StefanSchippers commented 11 months ago

and why did You change to 130?

previous limit was 100 and it seems too low. Using 130 will less likely introduce breaks for reasonable wide texts. Anyway the updated xschem will not touch any more texts brought into the netlist by code.sym elements.

StefanSchippers commented 11 months ago

then i have an other question. why is it necessary to declare default_schematic=ignore in thesymbol.sym file and why isnt it possible to write this per q in the schematic.sch ?

Because you may have a super big design with 10 levels of hierarchy developed by many people. One team has developed a part of the design and is using symbol.sym inside sub-schematic team_A.schand expects the corresponding symbol.sch is used in the netlist.

Another team places symbol.sym in sub-schematic team_B.sch and sets default_schematic=ignore on the instance (using the q key) and sets schematic=symbol_B.sch

If xschem takes team_B setting it will not expand symbol.sch, will add symbol_B.sch and team A is fucked. (symbol.sch is not in the netlist)

If xschem takes team_A setting it will netlist symbol.sch and team_B will complain because there is an unused symbol.sch in the netlist. They will manually edit the netlist, delete the symbol.sch definition and team_A is fucked again.

Of course it should be possible to analyze the full hierarchy and at the end decide what to do. This requires a 2 pass full hierarchy traverse and this is Cadence-ish style, very inefficient.

Adding default_schematic=ignore in the symbol everyone using it knows that a schematic attribute MUST be specified (even schematic=symbol.sch is good if they just want the default).

olisnr commented 11 months ago

Of course it should be possible to analyze the full hierarchy and at the end decide what to do. This requires a 2 pass full hierarchy traverse and this is Cadence-ish style, very inefficient.

thats a good reason...

olisnr commented 11 months ago

the ! command dont work correct on multi-selections. only the wires that crosses the pins of one part are cut. and would it be ok to remove the dialogbox after the y command? if the user should be aware of the mode, maybe it would be better to put the information in the status line at the bottom of the window?

StefanSchippers commented 11 months ago

I have tried, but cutting on multiple selections just works.

https://github.com/StefanSchippers/xschem/assets/69359491/65b9b4e9-1210-4629-b838-0268af00c6ce

olisnr commented 11 months ago

yes it is strange. i saw this a few times, when i wanted to cut "antennas" after moving transistors around, but now i cant reproduce it reliable. it did show up only one time, while i tried to find a case i could record... may be it appears in future, and then i will report. maybe i have to verify that all things are on a the grid?

StefanSchippers commented 11 months ago

One of the reason is if devices are (even by s small amount) offgrid

StefanSchippers commented 11 months ago

would it be ok to remove the dialogbox after the y command?

This is now done. info shown in status bar. Thank you.

olisnr commented 11 months ago

at the moment my parts-preview is broken:

preview

olisnr commented 11 months ago

is there a reason, why the graphdialog needs "" for calculations? wouldent it be easier to put the "" over every line?

olisnr commented 11 months ago

One of the reason is if devices are (even by s small amount) off grid

it happens again a few times, but only after some time of editing, and i couldent repeat it. most of the time i used cntr-a first, and then !. one time i looked in the text of the *.sch file, but found only parts and wires in decadic-coordinates. the thing is: if i save the schematics and reload, it works again...

StefanSchippers commented 11 months ago

is there a reason, why the graphdialog needs "" for calculations? wouldent it be easier to put the "" over every line?

This could be done, however expression or list of nodes (for wide buses) can span multiple lines. "" are only required to allow spaces (and a newline is considered as a separator like space) You can also use \ to escape spaces and avoid quotes (but the text looks ugly in my opinion)

This is a valid expression that does not use quotes.

FILTERED_CIN;cin\ 10n\ ravg()

If you don't use spaces you can avoid "", but for expressions you need to use quotes or escapes (because you need spaces to separate operands)

StefanSchippers commented 11 months ago

One of the reason is if devices are (even by s small amount) off grid

it happens again a few times, but only after some time of editing, and i couldent repeat it. most of the time i used cntr-a first, and then !. one time i looked in the text of the *.sch file, but found only parts and wires in decadic-coordinates. the thing is: if i save the schematics and reload, it works again...

I found the reason you sometimes don't see the wire removal. If wires are already broken at the symbol pins the inner part is not removed. The original decision was that if such a wire is placed across the symbol and lands exactly on symbol pins it has been placed deliberately and should thus not be removed. I will see if I can add an option to force removal or leave as it is now. In picture below the wire under the lower inductor will not be removed. 1

olisnr commented 11 months ago

my cases are a bit different, i typical see it on the gate of MOS transistors, if i want remove the "anntenas":

mycase

as example X26 is cutting the wire but X24 not.

StefanSchippers commented 11 months ago

In the case of X24 and X26 the wires are just cut, not removed. Removal occurs (by using Tools -> Remove wires running through selected inst. pins, or ctrl-!) only if wire runs all inside a component and touches 2 pins. The 'antennas' are cut at the gate pin but not removed. 1

StefanSchippers commented 11 months ago

I have improved a bit the 'antenna cutter' so wires touching pins all inside symbols will be deleted, as well as wires all inside touching one pin and touching nothing on the other side.

If you see cases where this does not happen on some instances remember the last operation you did immediately before, so I can try to figure out.

1

olisnr commented 10 months ago

is there a change in the trafficlight of newer versions? at a click to "Netlist" the "Simulation" looses the color, but the "Wave" not. if green means that waves are loaded, then maybe it would be more clear to switch "Wave" to yellow, showing, that the waves that are loaded are from an old simulation?

StefanSchippers commented 10 months ago

I have made the change. If waves are loaded (Green) then Waves button will turn to yellow upon pressing 'Netlist'.

olisnr commented 10 months ago

did You think about adding a vertical flip? (1 time flip and 2 times rotate). and would it be ok to set the cursor at opening the "Choose symbol" dialog to "File/Search"?

StefanSchippers commented 10 months ago

Vertical flip is done. Shift-V
Vertical flip in place is done. Alt-v The "change netlisting mode" command has been moved to key ctrl-shift-V Also when Insert component dialog is invoked focus the FIle/Search entry box.

Please test! :-)

olisnr commented 10 months ago

tanks! works great! & Happy New Year!

i think it would be a good idea to put the property * toggle into the context menue for devices. and if the plots dont have an file specified i would expect the same .raw name like in the -r "$n.raw" from the simulation command dialog.

olisnr commented 9 months ago

now i have a window with a "gost schematics"... i copy and pasted some parts... i never saw this before...

https://github.com/StefanSchippers/xschem/assets/120017377/ab8587fc-2952-4979-879c-ef3c25d99ec4

StefanSchippers commented 9 months ago

I think you have activated compare schematic. Normally you can set a second schematic file to compare with. If you don't set a file to compare with, the schematic will be compared with its own saved file on disk. Go to Highlight-> Compare schematics (ALt-x)

olisnr commented 9 months ago

yes! thats it! thanks