Dear Holger,
the "write" patch to ignore zero sized current vectors
I'm not sure, if this is the correct way to fix this problem, but it works for me. Maybe you can hav a look on it. Of course you are right - we should post patches to ngspice/patches!
Sorry for the confusion.
BR, Toni
the "write" patch to ignore zero sized current vectors
astx_ngspice_write_ignore_currents.diff
is included in zip file from post #30.
I'm not sure, if this is the correct way to fix this problem, but it works for me. Maybe you can hav a look on it. Of course you are right - we should post patches to ngspice/patches!
Sorry for the confusion.
BR, Toni
... using the adi.lib from ltspice we get 78 usable opamp models. Here the open loop gain results...
opamp stepping to the max ... 🙂 3 results shown here for example
opamp stepping to the max ... 🙂 3 results shown here for example
Code:
toni@tnserver01:~/pcb/simulations/ngspice/opamp> cat step_opamps_loopgain.sh
#!/bin/bash
#
# (c) astx (at) aws-it.at, 2018 - 2019
# and (c) others - see DIYaudio thread [URL="https://www.diyaudio.com/forums/software-tools/331656-installing-using-ngspice-opensource-simulator.html"]Installing and using ngspice - an opensource simulator[/URL]
#
# $Id: step_opamp_devices.sh 1579 2019-01-17 11:34:34Z sta $
#
echo ""; echo ""
echo "#-----------------------------------------------------------------------"
echo "NOTE: For successful run you need at least ngspice 30+ pre-master"
echo " astx_ngspice_write_ignore_currents.diff"
echo "After simulation run you can further explore the result data"
echo "Use 'quit' to exit simulation"
echo ""
echo "#-----------------------------------------------------------------------"
echo "If you want to run opamp stepping simulation now enter 'y' <ENTER>"
echo "#-----------------------------------------------------------------------"
read a
if [ "$a" == "y" ]; then
# change this to your preferred editor. vi nano joe ...
export SPICE_EDITOR="joe"
# temporary net list file
mynet="opamp_loopgain.net"
chead="\n.control\n"
cend="\n.endc\n"
echo -en "${chead}" > load_result_files0.inc
echo -en "${chead}" > load_result_files1.inc
echo -en "${chead}" > load_result_files2.inc
tianplots=''
count=1
for opamp in $(cat adi_opamps.lst)
do
opamp=$(echo $opamp|tr 'A-Z' 'a-z')
# load schematic and create a fresh netlist
gnetlist -g spice-sdb -o $mynet opamp_loopgain.sch
# replace %MYOPA% from schematic by $opamp
sed -i -r -e "s/\%MYOPA\%/${opamp}/g" $mynet
# e.g. add/set some circuit params or options be4 simulation run
echo -en "\n*.options savecurrents\n.control\n\tset opamp="${opamp}"\n\techo "OPA \$opamp"\n.endc\n\n" > $mynet.inc
ngspice -i $mynet.inc $mynet
# generate load result files listing
echo "load ngspice_ac_${opamp}.data" >> load_result_files1.inc
echo "load ngspice_vars_${opamp}.data" >> load_result_files2.inc
tianplots="${tianplots}ac${count} "
count=$(($count+1))
done
echo -en "${cend}" >> load_result_files1.inc
echo -en "${cend}" >> load_result_files2.inc
echo -en "set tianplots=( ${tianplots})${cend}" >> load_result_files0.inc
# load (no netlist!) results only from stepping and display e.g. fft, fourier and input, output voltages
ngspice opamp_loopgain_show.ngspice
# reset terminal if ngspice terminates unexpectedly
reset
fi
Attachments
... another 48 opamps ex adi1.lib from ltspice working with ngspice ...
some examples shown here ...
Schematic which has been used for open loop gain simulations.
BR, Toni
some examples shown here ...
Schematic which has been used for open loop gain simulations.
BR, Toni
Attachments
-
ad_opamps_adi1_lib.txt334 bytes · Views: 102
-
opamp_loopgain_adi1_lib.zip323.3 KB · Views: 102
-
opamp_openloop_gain_ac1_device=ad549_result.png7.1 KB · Views: 206
-
opamp_openloop_gain_ac13_device=ad8508_result.png7.1 KB · Views: 185
-
opamp_openloop_gain_ac43_device=op4177_result.png6.8 KB · Views: 105
-
opamp_loopgain_schematic.png144.8 KB · Views: 129
Last edited:
How difficult do you think it would be to get ngspice to run a LTspice netlist? Then I could go back and forth, I greatly prefer the LTspice schematic editor.
ltspice has a netlist export function. Either u can use one format native or a small perl script could convert it...
Will have a look on it..
BR, Toni
Will have a look on it..
BR, Toni
Just tested the ltspice netlist of sa2015 - with some editing rules it should be possible to nearly natively use the interim generated ".net" file when you do at least an "op" run.
Using a small helper script it should be possible to use ltspice as schematic editor only ...
(e.g.: the VDMOS devices in LTSpice have 4 connections whereas in ngspice they have 3 connections - the substrat connection needs to be removed)
BR, Toni
Using a small helper script it should be possible to use ltspice as schematic editor only ...
(e.g.: the VDMOS devices in LTSpice have 4 connections whereas in ngspice they have 3 connections - the substrat connection needs to be removed)
BR, Toni
Thanks for checking it out. I wouldn't be surprised if someone has already written a script for this.
ngspice has no variable string handling like substring or similar (or I can't simply find it)
We can extend the limited ngspice string handling using a scripting language via the "shell" command to do some simple string operations like get value from a key/value pair or upper/lowercase a string.
An example
The shell helper "shellcmd.sh " could be in any scripting language e.g. a shell script:
In my example I use the shell helper to extract the value from the loaded plot data header:
Example output in ngspice
Unfortunately ngspice auto-converts variable names AND content if we source them in the generated small script. A patch helps to avoid this, if the variable name is prefixed using 'nolc_' .
A second patch allows me to run gnuplot in batch mode without showing any x11-window to silently generate png graphs in a loop.
Attached 3 small ngspice patches which I currently need against ngspice-30+ pre-master. Maybe Holger can have a look into it to implement the patches.
We can extend the limited ngspice string handling using a scripting language via the "shell" command to do some simple string operations like get value from a key/value pair or upper/lowercase a string.
An example
Code:
.control
* NOTE: this needs a ngspice patch to get nice png output where gnuplot makes a auto exit
set gnuplot_terminal=png/quit
foreach pl $tianplots
setplot $pl
* get curplottitle and extract device name using a shell command which splits key/value pair by '='
* <cmd> <resultfile> <new_varname> <input_data>
shell ./shellcmd.sh getval getval.result nolc_dev "$curplottitle"
* run the generated ngspice script to feed the set variable
getval.result
shell ./shellcmd.sh uc uc.result nolc_ucdev "$nolc_dev"
uc.result
echo "OPA=$nolc_ucdev"
gnuplot opamp_openloop_gain_{$pl}_{$nolc_dev}_result vdb(av) phase ylimit -200 200
end
...
Code:
#!/bin/bash
if [ "$1" == "" ]; then
echo "Warning: need 4 parameters: <cmd> <resultfile> <new_varname> <input_data>"
exit
fi
cmd="$1"
resultfile="$2"
varname="$3"
data="$4"
echo "cmd=<$cmd> resultfile=<$resultfile> new_varname=<$varname> input_data=<$data>"
case $cmd in
getval)
result=$(echo ${data}|cut -d'=' -f2-99999999)
;;
getkey)
result=$(echo ${data}|cut -d'=' -f1)
;;
lc)
result=$(echo ${data}|tr 'A-Z' 'a-z')
;;
uc)
result=$(echo ${data}|tr 'a-z' 'A-Z')
;;
*)
echo "No such command <$cmd>!"
exit
;;
esac
echo -en "\n.control\nset ${varname}="${result}"\n.endc\n" > $resultfile
Code:
shell ./shellcmd.sh getval getval.result nolc_dev "$curplottitle"
Code:
Title: device=ada4627
Date: Tue Jan 29 17:03:55 2019
Plotname: ac data
Flags: complex
No. Variables: 3
No. Points: 2088
Variables:
0 frequency frequency grid=3
1 av notype
2 phase notype
Code:
cmd=<uc> resultfile=<uc.result> new_varname=<nolc_ucdev> input_data=<op747>
Circuit:
OPA=OP747
writing plot to file opamp_openloop_gain_ac47_op747_result.plt
cmd=<getval> resultfile=<getval.result> new_varname=<nolc_dev> input_data=<device=op777>
Circuit:
cmd=<uc> resultfile=<uc.result> new_varname=<nolc_ucdev> input_data=<op777>
Circuit:
OPA=OP777
writing plot to file opamp_openloop_gain_ac48_op777_result.plt
A second patch allows me to run gnuplot in batch mode without showing any x11-window to silently generate png graphs in a loop.
Attached 3 small ngspice patches which I currently need against ngspice-30+ pre-master. Maybe Holger can have a look into it to implement the patches.
- ngspice_add_gnuplot_png_batch_option.diff
- ngspice_allow_mixed_case_vars_using_prefix.diff
- astx_ngspice_write_ignore_currents.diff
Attachments
Last edited:
ngspice already has a LTSPICE compatibility mode. See chapt. 16.13.6.
Currently only the simple diode is supported.
I would add fixes to other differences directly in the source code at inpcom.c. Then you won't need any script. What are these netlist differences? Could you give me a list? So it is
VDMOS has 4 terminals (3 and 4 the same node)
What else ?
Currently only the simple diode is supported.
I would add fixes to other differences directly in the source code at inpcom.c. Then you won't need any script. What are these netlist differences? Could you give me a list? So it is
VDMOS has 4 terminals (3 and 4 the same node)
What else ?
Dear Holger,
attached a perl converter script, a complete amplifier project and some output logs to get a feeling, how much action is necessary to get a ltspice netlist running.
Some explanations:
You get some errors of unknown numbers because many libs contain a "mfg=string" parameter in the model definition. Ignore this with "y". The simulation drops additional warnings about unknown parameters but succeeds.
keantoken: maybe you want to try one of your projects too. ltspice "op" run generates the netlist - as long as the op result window is open, the temporary netlist should be on disk available,
BR, Toni
attached a perl converter script, a complete amplifier project and some output logs to get a feeling, how much action is necessary to get a ltspice netlist running.
Some explanations:
- ako_problems.txt: this ako let the ngspice die.
I have had to disable the ako models in kean9...txt
- convert.log: result of my perl script - self explaining
You get some errors of unknown numbers because many libs contain a "mfg=string" parameter in the model definition. Ignore this with "y". The simulation drops additional warnings about unknown parameters but succeeds.
keantoken: maybe you want to try one of your projects too. ltspice "op" run generates the netlist - as long as the op result window is open, the temporary netlist should be on disk available,
BR, Toni
Attachments
ngspice is supporting the 'ako' notation. Did you enable PSPICE/LTSPICE compatibility mode (see manual chapt. 16.13.7) ?
Holger
Holger
Yes, the zip file in post 50 has a .spiceinit with ltpsa set. Unzip and just try out "ngspice ako_problems.txt" ...
BTW I have added the patches on ngspice sourceforge homepage. Have a look at "Tickets/Patches".
BR, Toni
BTW I have added the patches on ngspice sourceforge homepage. Have a look at "Tickets/Patches".
BR, Toni
There is also the Quite Universal Circuit Simulator "QUCS-Studio" that is not spice but seems useful.
< QucsStudio Homepage >
I have played around somewhat and I kinda liked it. I have no very deep experience with it. It looks like it can inter-operate with ng-spice, Spice-opus and uses octave as post processor after simulation. It can import spice models and Verilog-A and can export to KICAD.
The style is more like ADS and it is more RF-oriented. QUCS without -studio seems to be an outdated version.
It can do harmonic balance simulation, required for nonlinear noise, that's what interested me. The interoperability with spice could be more interesting for the people here. Installation is easy. There is none. Just unzip the file somewhere and call up the .exe.
regards, Gerhard
< QucsStudio Homepage >
I have played around somewhat and I kinda liked it. I have no very deep experience with it. It looks like it can inter-operate with ng-spice, Spice-opus and uses octave as post processor after simulation. It can import spice models and Verilog-A and can export to KICAD.
The style is more like ADS and it is more RF-oriented. QUCS without -studio seems to be an outdated version.
It can do harmonic balance simulation, required for nonlinear noise, that's what interested me. The interoperability with spice could be more interesting for the people here. Installation is easy. There is none. Just unzip the file somewhere and call up the .exe.
regards, Gerhard
Last edited:
Dear Gerhard,
thx for the Information but it seems to be off topic. Can't find any information that qucsstudio is using ngspice in any way. Also it is not opensource and only available for Windows - see this statement from qucsstudio homepage:
BR, Toni
thx for the Information but it seems to be off topic. Can't find any information that qucsstudio is using ngspice in any way. Also it is not opensource and only available for Windows - see this statement from qucsstudio homepage:
QucsStudio is a Qucs fork that stems from the original project founder. It's freely available for Windows and not open-source. But it offers by far the most features and is updated regularly.
BTW: Qucs without "studio" is an active project, open source, supports ngspice and xyce - have a look at source code mirror: GitHub - Qucs/qucs: Qucs Project official mirror
BR, Toni
Last edited:
concerning ako
The PSPICE manual says:
plus other optional parameters. <model type> is required, but missing in kean9.bjt.txt, where I see only
with model type npn missing.
LTSPICE seems to treat this differently, as found in Undocumented LTspice - LTwiki-Wiki for LTspice
o.k., this requires an LTSPICE update to ngspice.
The PSPICE manual says:
Code:
.MODEL <model name> [AKO: <reference model name>]
+ <model type>
Code:
.model MMBT6429 AKO:MPSA18_kn
LTSPICE seems to treat this differently, as found in Undocumented LTspice - LTwiki-Wiki for LTspice
o.k., this requires an LTSPICE update to ngspice.
Have you checked that the AKO statement works in LTspice? I may have made a mistake here, I seem to remember encountering the problem. Might be different in different versions of LTspice.
EDIT:
Okay, this is interesting. The MMBT6429 AKO statement works when placed on a schematic but does not appear in the drop down transistor list when selecting a model. So whether it is my mistake or an LTspice feature is open to interpretation, but for full compatibility the NPN card needs to be added to to the AKO statement when it is in a library.
EDIT:
Okay, this is interesting. The MMBT6429 AKO statement works when placed on a schematic but does not appear in the drop down transistor list when selecting a model. So whether it is my mistake or an LTspice feature is open to interpretation, but for full compatibility the NPN card needs to be added to to the AKO statement when it is in a library.
Last edited:
Hmm. This is the only syntax which shows up in the transistor selector:
.model MMBT6429 NPN AKO:MPSA18_kn
Notice the NPN card comes before the AKO card, not after.
If the NPN card goes after the AKO card, it is interpreted as modifying the original model, IE if you use PNP it will override NPN and change the polarity of the transistor. But the LTspice model selector ignores models that don't include the NPN card before the AKO statement, which I suspect is an oversight, so I will report it to the LTspice developer.
.model MMBT6429 NPN AKO:MPSA18_kn
Notice the NPN card comes before the AKO card, not after.
If the NPN card goes after the AKO card, it is interpreted as modifying the original model, IE if you use PNP it will override NPN and change the polarity of the transistor. But the LTspice model selector ignores models that don't include the NPN card before the AKO statement, which I suspect is an oversight, so I will report it to the LTspice developer.
Well according to Mike it's supposed to be that way. I'm guessing adding a special case to the transistor selector parser would be considered frivolous.
Just to understand:
So
.model MMBT6429 NPN AKO:MPSA18_kn
is the correct notation? And not the one you have used in kean9.bjt.txt or one can find in Undocumented LTspice - LTwiki-Wiki for LTspice, that is
.model MMBT6429 AKO:MPSA18_kn
Or are both of the above allowed? If this becomes clear, I indeed might add a LTSPICE switch to read both and translate them to the PSPICE notation used in ngspice.
Well, frivolous would be adding something without having the spec clarified.
So
.model MMBT6429 NPN AKO:MPSA18_kn
is the correct notation? And not the one you have used in kean9.bjt.txt or one can find in Undocumented LTspice - LTwiki-Wiki for LTspice, that is
.model MMBT6429 AKO:MPSA18_kn
Or are both of the above allowed? If this becomes clear, I indeed might add a LTSPICE switch to read both and translate them to the PSPICE notation used in ngspice.
Well, frivolous would be adding something without having the spec clarified.
- Home
- Design & Build
- Software Tools
- Installing and using ngspice - an opensource simulator