Including Default SPICE Models in KiCad

I thought we were somewhat hijacking the other thread where this was discussed, so I wanted to make sure there was a separate topic for this at least to document the discussion. Here’s the link for context: KiCad 5.1.5 / ngspice Noob question

To summarize, there was discussion and suggestions on how to remove hurdles on getting started with using simulation (ngspice) within KiCad. These mainly revolve around supplying device models to make it easier to simulate basic circuits when the user is just getting started. I’m going to compare these suggestions with how LTspice handles the same concepts, because even though SPICE is generally a hard field to get into (this reality can’t be 100% avoided) I believe LTspice is one of the best examples of maximizing user friendliness:

1.) Giving semiconductor symbols a default value.
This is already done with R, L, and C components. Even if you don’t go into the “Edit Spice Model…” thingy within a symbol’s properties and choose “Passive->Resistor” (for example), the netlist generator will still auto-detect the reference designators and make sure these parts get put into the SPICE netlist. Anyway, the idea here is to extend this process to semiconductors. However, semiconductors require a .model statement (called a “model card” by pretentious SPICE users like me). The way LTspice handles this is that if a reference designator of Q is detected anywhere in the schematic it automatically adds the following two lines to the netlist:

.model NPN NPN
.model PNP PNP

What this does, and it’s a little confusing (so bear with me), is define an NPN BJT transistor model called “NPN” with all default parameters (see 8.2 of the manual). [and blah blah blah, same for PNP] It does this because when you drag an NPN symbol out of the part library and plop it onto the schematic the name of that symbol is “NPN”. This ensures that when you go to run the simulation without giving the symbol a more detailed model card definition, it’ll still run it using default parameters. It’s important to note that the default parameters usually result in a highly idealized model. For example, default diodes will have infinite breakdown voltage and no series resistance. The defaults are usually OK for basic educational circuits, with the exception that they are absolute trash for MOSFETs (in my opinion).

So how to handle this in KiCad? Well, it would need changes to the code. One idea is to implement the same thing LTspice does where it auto-detects designators, auto-netlists the symbols to the default model, and auto-adds the default “model card” for that symbol type. Another less complicated idea that was thrown around is to add another SPICE field in the symbol properties, maybe called “Spice_Modelcard” or something like that where you can put a .model NPN NPN string without having to reference an external .LIB text file. The code that would need to be changed is to have the netlist generator parse this out to the netlist and avoid duplicates (for when 2 or more instances of the same symbol exist). If this alternate idea gets implemented, then we would additionally need to add parts with these fields pre-defined to the already existing ngspice KiCad symbol library. The user can then just throw these specific symbols down onto the schematic, connect, and simulate.

2.) Supplying a list of pre-defined semiconductor models
This one’s simpler to understand. KiCad can already reference external .LIB text files to import .model statements (“model cards” as described in #1). The idea is to include a list of common parts for each semiconductor type: diodes, BJTs, JFETs, MOSFETs. LTspice has these lists stored locally in its \lib\cmp\ directory where, for example, the diodes list is stored as the filename: standard.dio. When you edit a symbol within LTspice, it automatically pulls up the corresponding list for each semiconductor type.

The main problem to sort out is how to package such lists within KiCad so that they can be readily used by KiCad users without any fuss. Is there perhaps a directory always installed with KiCad where this file can always reside and be packaged with the installation? Right now, KiCad can only reference external text model files if they are found in the project’s directory. Some system would need to be added such that it can look for and/or be able to select between the standard file or a user-supplied one within the project directory. So some kind of code changes would be needed here.

Alternatively, we can technically implement this without any code changes right now…but we need special instructions for telling the user where and how to download these pre-defined lists and copy them to their project folder if they want to use them. This somewhat defeats the purpose of out-of-the-box user-friendliness, but maybe we can start constructing external lists now so we can weasel them into a future KiCad build in the future?

My Lame Thoughts
Ideally, both of the above suggestions can be implemented and each would make simulations easier for users. They’re not disjoint. I know there are plenty of caveats associated with each, but man…I’m kind of tired typing all that out so maybe someone else can comment or ask a question for now instead? I also just realized I said “We” a lot…did I just inadvertently sign myself up for a bunch of work? Doh???

Exactly why has this topic become kind of… dry aged? Just to mention, I am THE perfect noob regarding KiCad and Spice. Yes, even too noob’ish, like drawing a circuit together, thinking it’ll be so cool, then starting the simulator - and closing the program afterwards. What the .heck x(7…12) stuff?

Yes, KiCad is not Notepad. Yes, why should manufacturers offer their most secretly kept secrets, of all things, to us? Their transistors aren’t Open Knowledge.

Still, those vendors know this fact: The simpler the use of their thingys is, the more we doctors, engineers, hobbyists will use AND BUY them.

But, unless KiCad becomes easier to use for us doctors, engineers, hobbyists, it’ll stay a nic(h)e product for the brave-at-heart. Imagine a startup company designing the usual automotive-AI-super-super stuff, but then one of their new employees urgently needed a simulation? Asking herself the fundamental question: “Will this work?” She’d remember KiCad, but then, after trying running the Spice thing, she’d be like “why the f***?”

Of course, other start-ups would appear like “Hey, let us handle this for you, for like x-zillion $$!”

At least to me, KiCad could be a changer, and a winner-maker. And at leat to me, there are three game-changing points along this road:

1st - Make more simple components avaiable, like @ste said
2nd - Add assistants to KiCad, or call it templates, and DO NOT design them from a software’s POW but from the user’s one. Not like “I want to simulate this transistor connected to that capacitor with a sinusoidialish sweepish thingy” but from the application’s point of view: “I want to water my plants on the balcony, according to sun and rain, because I’ll be away for a week.”

Exactly there appearance of AI.

Okay, I’m dreaming, but by the way, I am pretty sure that a generative AI would be able to create lots and lots of models handy for us, the noobs :slight_smile:

You should probably have split this into a new topic.

Anyway to comment: It may seem that if you had even more robust library it would make your life easier. However this is not the case, your still responsible for the things. AI or a third party is not terribly useful if the responsibility of correctness lies on you.

Why? Well, taking responsibility entails that you can make changes when you notice something is wrong. Having a database that does 99% of what you want just makes the 1% possibly 99 times harder. So while a better database helps, it does not really make things easeir to beginners.

So lets take two examples that are easy to understandout of something that has happened around me lately:

  1. Person wants to fill in the necessary paperwork to incorporate their business. This is a excellent candidate to using AI or third party service, because the responsibility of checking for correctness is in the hands of the bureaucrat that takes the documents in.

  2. Another person wants to CE mark their lighting product. This one is terrible place to use AI, because nobody reviews the paperwork until after something has happened. So the liability of checking is on you, if the ai makes a mistake it costs you money. A third party service might be okay if they indemnify you for mistakes on their part, but likely thats really expensive.

PCB manufacturing is more like number 2.

Please check the symbols and their devices made available in the Simulation_SPICE library.

1 Like