Adding Raw Spice Element

Not sure if I try to do something here that is not meant to be supported by KiCAD or if it’s just not fully implemented yet.

I added a few symbols of my own for spice simulation. These work fine, but the sub-circuits are stored in external files. I would really like the sub-circuit code stored inside the respective symbol definitions. There is a selection for ‘Raw Spice Element’. When this is selected it is possible to enter the code in the code tab and save it. This makes it appear like what I want to do should be possible.

The problem is that I can’t figure out how to connect the symbol pins. When attaching an external file, the file is automatically parsed and the model nodes appear in the pin assignments tab in drop down lists. One can then simply select the appropriate node ids and everything is connected. However, when the raw code is added directly to the symbol these lists are empty, so connections cannot be made.

I’m not an expert with ngspice (I prefer LTspice) but, I have done enough with ngspice to post this screenshot - perhaps useful.

Doesn’t matter if external file is called LIB, SubCkt, Tofu… as long as it contains the needed content… I’ve even included reference to Wave files for audio simulation…

@BlackCoffee Thanks for your post, and yes that works.

Obviously I wasn’t clear enough about what I am after. Your answer shows what I think should be possible. But I am working on subcircuits for OpAmps and other more complex items. There isn’t a category I can select other than ‘Raw Spice Element’. When I do that all the things that work so nicely with diodes and transistors and such stop working and it’s fighting me every step of the way. The only way I managed to get my OpAmps working was with external files for the subcircuit.

My thinking is that I should be able to insert the subcircuit code just the same way as you are showing with the .model example. Perhaps I am expecting too much?

Perhaps I should mention this also again, to be really clear. My OpAmps work perfectly fine. I have no problems implementing them or integrating them into KiCAD. The issue is simply that they need to be stored in external files and I would rather store them inside the library. That way everything is bundled in a single file, not in any number of ‘scattered’ files. This last part is what eludes me.

Ok, I did some more experimenting with this and realize now where I was expecting too much.

Even with diodes, as an example, I have to use an external file. It copies the code into the dialog (not sure if that is stored some place or if it’s done on the fly). From that and the fact that this is present with the default models I was assuming I could keep my models in this place as well. Obviously expecting too much. Maybe some day …

One last word about this topic. I noticed that it is important after selecting the file, to select the model in the box below, before closing the dialog. If that is not done KiCAD will inevitably crash. This is in KiCAD 7.0.10 on Ubuntu.

Can you report this on gitlab please? Help->report a bug

All sub circuits is pretty much all tools are stored in files.
Suggest getting proficient at this in LTSPICE
It has excellent documentation and there are lots of HOW TO videos to watch.

While I use a pro tool for nonlinear analysis, I use LTSPICE for everything else. permits me to send sims to clients… Altium got a bit in trouble when they started adding simulators and solvers to it, added an unnecessary doco and help overhead to the tool, when there were plenty of excellent open source SPICE simulators out there…

I put the Lib’s, SubCkt’s, .model…etc, and any resource files such as .wave, into my Kicad Project’s folder.

Further, I run LTSpice from Kicad, screnshot…

1 Like

Well, well yes, LTSPICE. I used it for years, but lost it because I was fleeing Microsoft and live on Ubuntu now … So I am working to get new tool chains up and running and getting proficient at using them. Most things are working qite well by now. SPICE was one of the few remaining items to get a handle on.

I am building my own library of components for simulation at the moment (added a nice selection of Zener diodes yesterday). That will allow me to jump into a quick simulation at a moment’s notice. With LTSPICE that wasn’t necessary because it comes with a decent selection of components that allow you to do that. Only needed something special every now and then. Not so in KiCAD.

Keeping the extra files is not difficult but it is not a clean solution and makes it hard to move the entire library to a new machine or share it with colleagues. I find it would be much cleaner if I simply could copy a KiCAd library and with that would not only copy the symbols, but also the models that go with them.

At the moment I keep the simulation libraries in a special directory and the models in a tree of sub directories. At least when the moment comes, I can simply zip up that tree and have everything that makes up my simulation library. I added a path KICAD_SPICE_MODEL_DIR to the directory that holds the models. That will make it possible to move it/migrate it to a different machine etc. If the path was hard coded that would be a horror trip.

So, just signed up for a GitLab account and tried to retrace my steps so I could describe the problem correctly, but it does not crash. Yesterday it crashed on me at least 10 times. Given that I’ll implement some more stuff it’s bound to happen at some point. I’ll try to observe carefully and report it then …

1 Like