ra3xdh / qucs_s

Qucs-S is a circuit simulation program with Qt-based GUI
https://ra3xdh.github.io/
GNU General Public License v2.0
857 stars 111 forks source link

Subcircuits node names are not made unique with ng-spice #1007

Open Rmano opened 4 hours ago

Rmano commented 4 hours ago

Hi --- this is a quite complex thing to explain, so please bear with me...

The following project, opened with qucs 24.3.2 on a Manjaro system, with ngspice-43, behave in a very strange way.

strangesub_prj.zip

Notice that the project has the "LT" compatibility flag on.

I downloaded the INA826 library from the TI site; this is a very popular instrumentation amplifier. It works ok "as is" in LTspice (under Windows or Wine in Linux). If I use it directly in my circuit by picking it like this:

image

it does not work at all: my results are the following:

image

As you can see, the amplifier is basically dead.

Now, I edited the text .lib file and changed all the occurrences of "GND" to "VSS" with a simple global search and replace, and to avoid clashes, I changed the name of the device to INA826E. And now...

Screenshot from 2024-10-19 18-15-19

It works flawlessly!!! So basically, the subcircuit node named "GND" is conflated with the external "GND" node name...

So this seems to be an encapsulation problem, and I do not know if the problem is in qucs-s or in ngspice. Node names in the subcircuit should be private, don't they? At least, they behave in the LTspice app.

tomhajjar commented 4 hours ago

One of the schematics is missing the device.

Rmano commented 3 hours ago

You're right. Forgot to make save/all before creating the zip... I have re-loaded it above. Thanks and sorry for the problem...

tomhajjar commented 2 hours ago

Updated Files: INA826_v1.1e.lib created

I created a new project for you. It will also show you how to make sub-circuits and symbols.

There are v1 and v1.1 of the Spice model INA826 and you modified v1. I tested all 3 versions. I didn't dig into which model works under ngspice. The cleaned up project will make it easier for @ra3xdh to make a judgement.

The v1.1 model tests the same as v1. I assume your modified v1e model works but more testing needs to be done to confirm how well.

The v1.1 model is supposed to be less "cluttered". It removed a number of unused sub-circuits. The pin order is totally different.

2024-10-19_142736 2024-10-19_142817 2024-10-19_142757 2024-10-19_161019

OpAmp_INA826_prj.zip

Rmano commented 2 hours ago

Very nice, thanks! Is there a tutorial somewhere on how did you do it? I tried but got stuck... even if I authored a simple tutorial for QUCS subcircuits (see attached), I got lost when trying to integrate the external libraries ...

ampli_qucs_tut.pdf

BTW, if this could be of interest for the documentation project, I'll be happy to contribute (adapting to qucs-s, that is, with also spice simulation).

tomhajjar commented 1 hour ago

Your tutorial is a start.

It's easier for beginners to make sub-circuits from manufacturer Spice models if one looks at the many examples I posted in the Discussion area or examples included in the Qucs-S distribution. Finding Spice models compatible with ngspice is the most difficult thing. There is no guarantee a model that woks in LTspice or PSpice will work in ngspice. The ngspice guys can help determine if a model can be altered to work in ngspice or a modification to ngspice is justified.

I also posted Symbol examples that you can copy-paste into your subcircuit. I generally copy an existing symbol from the symbol examples into "symbols_blank.sch" and clean it up prior to placing it into the sub-circuit. You generally want the Centroid of the symbol to be 0,0.