Simulation inside EDA software - ngspice  - Page 1
Forum section: electronics / general

author: rx8pilot
author_rank: Super Contributor
timestamp: October 13, 2018, 11:47:43 pm
content: I have been using LTSpice for most simulation needs during design. It is extremely clunky by modern software interface standards which essentially means that the learning curve is very steep if you want anything more complicated than a voltage divider. The good news is that if you take the time to learn all the secrets - the underlying solution engine is very powerful.I use Eagle and they now have ngspice 'integrated'. The sales pitch is that it is faster to simulate in the package you are designing in to avoid the double work of creating the schematic twice. So, I have been trying. And, failing. And, failing some more.It is hard to tell the difference between my inexperience in the software and its limitations - but it seems over the top un-intuitive even when compared to LTSpice. I have logged a number of hours trying to set up a capacitor charging simulation with a voltage controlled switch to discharge (a few R's and C's). No luck. This is a circuit that I can setup in LTSpice in about 2 minutes. The first time in LTSpice, maybe 5 minutes if I had to find something on the internet.In Eagle/ngspice - no success after hours of fiddling and digging until my day was wiped out. My instinct is to give up and consider the integrated simulation a useless toy for the marketing dept. Perhaps, I am just missing something. Some proper training, PDF's, videos, etc? Eagle training and documentation are abysmal overall - their YouTube videos cover about 5% of my questions after watching hours of rambling 'webinars'.Has any used ngspice with success? Anyone with Eagle or the other packages that are using ngspice engine?

author: nctnico
author_rank: Super Contributor
timestamp: October 14, 2018, 12:21:40 am
content: Forget about using a schematic for simulation as a real world circuit. You always end up adding parasitic and ideal components to make the circuit give a realistic simulation result within a reasonable amount of time. Also a complete circuit will be way to slow to simulate.

author: rx8pilot
author_rank: Super Contributor
timestamp: October 14, 2018, 12:45:27 am
content: Quote from: nctnico on October 14, 2018, 12:21:40 amI have no expectation of modeling a real-world circuit, just hashing out concepts is what I mainly do. It gets me in the ballpark and can catch some of the dumb mistakes that may not be obvious.Not the whole circuit either, just sections that I am not too sure about. Simulation is a great tool if our expectations are reasonable.

author: DerekG
author_rank: Frequent Contributor
timestamp: October 14, 2018, 01:05:03 am
content: Quote from: rx8pilot on October 13, 2018, 11:47:43 pmI would recommend you take a look at the simulator in DesignSoft Tina Cad. It is very intuitive compared to most (all) other powerful simulators. It is so good that the engineers at Maxim, Infineon, Texas Instruments & others use it. It is also taught in a number of universities as it produces accurate results without a high leaning curve.

author: rx8pilot
author_rank: Super Contributor
timestamp: October 14, 2018, 01:25:46 am
content: Quote from: DerekG on October 14, 2018, 01:05:03 amTI introduced me to TINA, but I have not done anything with it yet. I watched a few videos related to the TI version and it seemed like an all-new thing.Do you use it a lot?

author: DerekG
author_rank: Frequent Contributor
timestamp: October 14, 2018, 01:58:29 am
content: Quote from: rx8pilot on October 14, 2018, 01:25:46 amThe TI version is a "somewhat" cut down version of the full TINA Cad version. The TI version is free & contains most of the Texas Instruments components in the modeling library ready for you to use.There are a few things like the high end "smoke analysis" etc that are not included in the TI version. Most users don't require these unless they are actually modeling to put the components into a TO-220 package etc.QuoteThe "deal" with TI was done in late 2015 from memory, but TINA CAD themselves have been around since the mid 1990's.QuoteNot a lot, but it is great to confirm things like the minimum current in an actual circuit to fully turn on a specific type of transistor, or the -3db point in a filter when other components are also hanging off the input etc.The TI version is free & there is a training video to get you started.If only TINA CAD could read in my DipTrace schematics directly

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 14, 2018, 09:17:09 pm
content: Quote from: rx8pilot on October 13, 2018, 11:47:43 pmYeah, turns out a lot of CAD programs are clunky. Especially the EDA tools.LTSpice is not that hard to get used too though. Just go trough all the menus and toolbars. You may find features that you thought didn't exist.The main pet peave I have is that it has essentially the same selection approach as KiCad: you can't select items and then issue some operation on the selection. You first have to select an operation, and then you can drag, move, copy... which is clunky by itself but you get used to it. The bad thing is that you can only "select" items this way individually or in rectangular regions. If they don't fit in a rectangle exactly, you have to do it in several passes. Admittedly that sucks. But it's definitely workable for medium-sized schematics.Its simulation engine is Spice-based, but not too badly optimized. It's certainly faster (or even much faster) than ngspice in a lot of cases.Quote from: rx8pilot on October 13, 2018, 11:47:43 pmI don't believe that claim whatsoever, because in practice you're pretty much never going to use the exact same schematic for design than for simulation. I've just never got around to that with any real-life project. Besides, most often you'll simulate only parts of the design, not the the design as a whole (which is often not even possible). There are admittedly some simulation tools that you can make full-system simulations with, but they are much more complicated and involved than just Spice simulators. So you're still not likely to do that from within your EDA package.Quote from: rx8pilot on October 13, 2018, 11:47:43 pmI've used it a lot as a stand-alone tool. You have to write Spice circuits directly. It's not that difficult and gives you full control.I've also tested the new KiCad's integrated simulator - it's ngspice under the hood with a not-too-shabby GUI. It just works as far as I've tested it. KiCad's schematic editor has its quirks but in the same vein of LTSpice (maybe a tad better). It's usable.The thing with LTSpice is that, even though it's a capable simulator, I tend to shy away from it progressively. Even though you can integrate third-party Spice models in it, and I've done that quite a bit, of course it's much faster to use built-in models, so you find yourself using Linear Tech. parts a bit more often than you'd like. Obviously it's just given away for free for that exact reason.

author: rx8pilot
author_rank: Super Contributor
timestamp: October 14, 2018, 11:09:29 pm
content: Quote from: SiliconWizard on October 14, 2018, 09:17:09 pmFor sure - the schematic is different and the parts used in the schematic are different from the real parts. In Eagle, you can map a spice model to any part which is convenient but not enough to use your schematic directly in a simulation.In my test, I did copy a section of my schematic and made the appropriate changes to setup a simulation. Sadly, you cannot simulate a section so I still have to copy the simulation to an all-new file anyway. At that point, I would prefer to just use LTSpice.For a second, it looked like the graphing was kind of neat in Eagle, but it is not interactive like LTSpice. It does not allow freedom to probe around and see the results immediately.Aaaaaand yes.....LTSpice has encouraged me to use Linear parts because they all have models ready to go with example circuits. Lately, I have been using a lot more TI parts and they have licensed Tina - which appears to be a better interface overall. Easier. The full version is not free, but it is not expensive at all.

author: nctnico
author_rank: Super Contributor
timestamp: October 18, 2018, 07:48:52 pm
content: I just played a little bit with TI's free Tina version and it seems reasonable to use but there will be a learning curve. The interface seems to hide some of the settings so getting control over the finer details will require reading the manual. Drawing the schematic has the typical short-cuts (ctrl-r for rotate for example).

author: Araho
author_rank: Regular Contributor
timestamp: October 21, 2018, 05:37:18 pm
content: Altium actually also has an integrated spice-version now. If you do your due diligence when creating components and generally add the supplied models, I guess it would save you learning "yet another clunky UI". Apparently, it works with any spice-model, and seemed pretty self-explanatory when I tried it last week.

author: rx8pilot
author_rank: Super Contributor
timestamp: October 21, 2018, 06:12:45 pm
content: Quote from: Araho on October 21, 2018, 05:37:18 pmOne of the things that would make it useful inside EDA software is to be able to define sub-circuits for simulation. I never need to sim an entire design - just little sections. it would seem ideal to have a way to isolate a section - define sources, loads, directives, etc. After you have iterated based on the sims, just 'hide' the simulation elements and keep designing away.I am not sure how having this pseudo-integration is really all that helpful since I have to make a special and separate design just for simulation anyway. After it is done, I have to manually translate to the real system design.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 21, 2018, 06:38:59 pm
content: For sure.As Araho said, the real plus point would be not to have to learn another UI with different approaches and shortcuts.But other than that... yes that helps keeping all of your design work in one EDA project. Not sure I'm 100% in favor of that though. Don't like to put all my eggs in the same basket.And, even just thinking of the perspective to have to launch the AD monster just to make a couple simulations... ouch.

author: Araho
author_rank: Regular Contributor
timestamp: October 23, 2018, 01:22:54 pm
content: Quote from: rx8pilot on October 21, 2018, 06:12:45 pmAFAIK, it simulates on a sheet-by-sheet basis with defined signals only. So it might be possible to create designs that are simulatable "as-is", maybe via some compiler directives...

author: shapirus
author_rank: Super Contributor
timestamp: November 30, 2023, 11:42:03 pm
content: It's an old topic, but relevant, so why not bring it up to see how things changed in 5 years....the bottom line is that they have not, as far as helping the user achieve the goal goes.I am trying hard to migrate off of (pirated, of course) Proteus to KiCad + ngspice. Ngspice is FOSS, which is cool, but it's worth nothing if there is no supporting ecosystem, and by that I mean models. Every single component beyond the basic resistor, capacitor, diode and transistor (and a few more) primitives require hours of frustrating search in the internet for models, where most of you can find are LTSpice or PSPICE models. Sometimes, if you're lucky, after trying several models you can find one that doesn't give cryptic errors (because the ngspice's compatibility layer doesn't support certain features) and works, sometimes it even works as expected (e.g. implements the 555's reset pin, unlike many). In most cases, however, you end up with a handful of models, none of which are supported by ngspice.I don't know how people are using it for anything beyond a resistor divider. Does everyone create their own IC models from basic elements?I haven't given up yet. But if/when I do, my next attempt will be exporting netlist to LTspice (if it's possible) and running simulation in it. At least it should support models created for LTSpice. Or maybe create schematics in it and then import back to KiCad (to create a PCB), which the current development branch supports. But it kind of sucks. I'd love to use ngspice, but without a big library of supported models it's useless for me.Please someone correct me if I'm missing something obvious.p.s. to make it clear: yes I do understand that simulation will not represent a real circuit. It's the same for me as for the OP: get a ballpark estimate for values, verify ideas, design something by trial and error, and make sure that VDD is not shorted to GND before proceeding to building a breadboard (or whatever) prototype. It doesn't, usually, require a careful analysis of parasitics etc.

author: Warhawk
author_rank: Frequent Contributor
timestamp: December 01, 2023, 11:56:22 am
content: That's the reality of simulations. Every simulation is as good as the input. If you're wildly browsing the internet trying to find spice models the simulation ends up likely junk. Garbage in, garbage out. Modern semiconductors are so complex that many models are just either for AC or transient analysis. It is important to open the spice model and read what the model does. By no means the simulation model represents what is truly inside on the silicon level. For this reason, you may find many ideal gm stages, silly caps, etc. You get most reliable results if you use the tool provided by the semi vendor. I use circuit simulators for debugging early concepts. Most of time I use idealized components.I work at TI. This means that I use Tina TI (hate it), pSpice of TI (I am ok with it), but also qspice and LTspice (only for hobby). PSpice is notoriously bad for switchers therefore Simplix is the right tool for it.tl;dr;Don't waste your time with simulations. Go to the lab instead. You learn more. After you get enough experience, you will understand better when simulation helps. I unfortunately see too many young engineers blindly relying on simulations...When you get there, you will understand the brilliancy of LTspice or qspice.

author: shapirus
author_rank: Super Contributor
timestamp: December 01, 2023, 04:05:13 pm
content: Quote from: Warhawk on December 01, 2023, 11:56:22 amThat's clear. I will add: "...assuming that models for the components you use exist and the simulator does not crash with syntax errors", which is where ngspice does not shine.Quote from: Warhawk on December 01, 2023, 11:56:22 amWhen they work at all, they work for me, most of the time. Again, I understand the limitations. Edge cases, switching conditions, power-on transitions, real silicon pecularities, complex processors are to be tested in hardware anyway. LTSpice runs well with what I have attempted so far. Proteus runs perfectly, I was able to simulate (interactively!) entire devices in it, but no complex things so far -- no MCUs etc.: where these are required, I use dummy voltage sources and resistor or transistor primitives in place of the actual device's i/o pins. Simulating those sounds like more hassle than wiring them up on a breadboard anyway, which is the opposite situation than that of discrete analog and simple logic parts.Quote from: Warhawk on December 01, 2023, 11:56:22 amNot my case really. I don't develop complex (or any) boards for commercial production. I need simulation mostly for ancient ICs like CD4xxx/HEF4xxx and some basic comparators and op amps for my DIY stuff that I mostly do for fun, however sometimes I actually use what I create. Even there, with the most jellybean parts, ngspice fails before it starts, that's even before we can talk of whether the simulation results are realistic.My use case for simulation, again, is to get an answer to "is the wiring correct? did I not mess up the inputs and outputs? will I get the expected signal at a given output when a switch is pressed or a particular voltage is fed to a given input?" before proceeding to breadboard proofing and PCB design. I use simulation to verify concepts and get a qualitative estimation, not to make precise measurements.Proteus works for this. LTSpice works too. Both offer huge libraries of models, regardless of the software's price (insanely expensive and pretending that individual hobbyists do not exist, vs free for personal use).Ngspice only works if you can find compatible models, which are scarce. Any given user, including myself, can improve it for themselves by learning the spice syntax and its various dialects, which will allow to rewrite certain models to become compatible with ngspice. Its syntax is not uncomprehensible, so it is feasible, but it makes me remember my Fortran days, and that, I'll say, was somewhat of a mixed experience.In other words, ngspice is as user-unfriendly as it gets and assumes quite a steep learning curve even before you start using it for anything beyond its builtin primitives. This is quite unlike other simulators that I have tried. That being said, I have a feeling that I'll get there eventually. Yes it is possible to launch LTSpice (it works well under wine) from KiCad via the netlist export dialog, but it's so inconvenient and LTSpice's UI is so ugly, inconvenient, and outdated (much more so than that of KiCad, and the latter is improving because of being in active development) that probably adapting the LTSpice models to ngspice is a better way after all.Speaking of Proteus, well, it gets the job done, but I hate to be using a pirated copy, it is glitchy under wine, and its PCB design functionality is rather lacking, buggy, and the UI is poorly made. Apparently they cannot afford hiring a UX specialist. But I'm not paying, so I can't complain, that's why I want to move to a FOSS solution instead.Quote from: Warhawk on December 01, 2023, 11:56:22 amSpeaking of TI, the fact that many, if not most of the parts, have freely downloadable pspice models on the TI website, is great. Kudos to TI for this.PSpice models also tend to work with ngspice more often than the LTSpice ones, based on what I have tried so far.There used to be a downloadable archive that contained all the models, but it shrank over time and now it's completely empty. Not sure what the motivation behind it was and whether it was intended, but maybe you could ask someone around who might be controlling that stuff to see if they could restore it. It'd be useful to be able to conveniently have everything locally in a single package.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 02, 2023, 07:42:53 pm
content: There are two threads on the KiCad user forum with ngSpice simulation examples:https://forum.kicad.info/t/simulation-examples-for-kicad-eeschema-ngspice/34443https://forum.kicad.info/t/more-simulation-examples-for-kicad-eeschema-ngspice/45546And those have zipped up projects to help you to get started.Also, in the last year several enhancement have been made for the integration of ngSpice in KiCad.These are available in the current "nightly V7.99", and will be part of the next stable release which will be KiCad V8 and is expected around the end of February 2024. You can have a look at the changes in the thread below.https://forum.kicad.info/t/post-v7-new-features-and-development-news/40144

author: djsb
author_rank: Super Contributor
timestamp: December 02, 2023, 08:32:22 pm
content: I dabble in QUCS-S, LTSPICE, and now I've started using QSPICE. These 3 can only do schematics and simulation, but they are useful for cross-referencing and making sure that all the simulations agree. LTSPICE schematics can be imported into KiCad, which is useful.A hierarchical design could be simulated block by block in LTSPICE (although not sure if LTSPICE does hierarchical blocks) and then imported into KiCad step by step (and also simulated in KiCad as well).QSPICE has great potential as it hierarchical blocks can be "stuffed" or "unstuffed" (I.E can be included or exclude from a simulation). It also has the advantage of being able to do mixed signal simulation of analogue AND digital circuits at the same time using Verilog and C++ code. The QSPICE forum is a very useful resource and Mike Engelhardt is very responsive to any questions you may have. I've not really tried simulation in KiCad yet, but it's useful to be able to just do a schematic once with a view to making a PCB later.PS I use Altium as well but just for PCB design. Simulation in Altium seems a bit of an afterthought.PS This might also be of interest as a source of exampleshttps://forum.qorvo.com/t/seeking-recommendations-for-starting-up-a-repository-for-sharable-user-custom-c-and-verilog-blocks/16157

author: shapirus
author_rank: Super Contributor
timestamp: December 02, 2023, 11:07:44 pm
content: Quote from: Doctorandus_P on December 02, 2023, 07:42:53 pmYeah they can be quite useful, however most of them are built using basic primitives. I can see, however, that the basic primitives now include a generic op amp, which is good. It's getting better, and at the same time I'm also learning how to use it and work around its shortcomings, so synergetically it's gonna give a satisfying result.Quote from: Doctorandus_P on December 02, 2023, 07:42:53 pmI'm actually using 7.99 now. It has its glitches, which I report in the issue tracker (the opportunity that does not exist with commercial software), some of the issues aren't 7.99-specific, but overall I like it, especially the dual cursors in the simulation plot. Many things are done in a much more convenient way than in Proteus, which I used before, and, frankly, after a few days, once I got the basic concepts of running "offline" spice simulation, I don't think that realtime/interactive simulation is all that important. Lighting up LEDs and bulbs and burning fuses are cool, though. Maybe some day KiCad will have them.Still, finding models that work for specific ICs is often a pain. It's also somewhat of a PITA to manually assign models to every part that you place on schematics, then reassign pins, which rarely match the model's ones (and many models have them numeric instead of aliases!), and that is a time consuming process. Support for multi-unit chips does not exist: you either have to simulate them as separate chips, which I currently do, ormodify the modelto represent a multi-unit IC.At the same time, there are models for many ICs that are offered by the semiconductor manufacturers, and those work more frequently than they don't. In fact they almost always work, as long as they are analog models (I've not had much success using digital ones: ngspice doesn't like mixed mode). Some models have weird constants, e.g., insanely high input capacitances, which don't agree with the datasheet, but that's usually easy to fix....I have yet to see the PCB design part of KiCad. Hopefully it'll be more satisfying than the simulator

author: shapirus
author_rank: Super Contributor
timestamp: December 02, 2023, 11:51:08 pm
content: Quote from: djsb on December 02, 2023, 08:32:22 pmIt's actually super convenient when you can design a schematic, simulate it and build a PCB in the same software without having to redraw the schematic twice. Obviously you can't simulate everything, but still.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 03, 2023, 12:48:40 am
content: Indeed. A schematic for Simulation is not the same as for making a PCB, but first doing your simulations, and then using the same project (or a copy) to modify it and design the PCB is a time saver.And doing it in the same program and the same GUI also simplifies it. You don't have to go searching for the other program or learn it's user interface.And I guess there are also options to use just one sheet of a bigger (hierarchical) project for the simulation.Simulation and PCB design are also not mutually exclusive. For the schematic it is just some extra meta data. Simulation needs attached simulation models, while the PCB needs footprint links. And parts can be excluded from either the simulation (for example connectors) or from the PCB (voltage and signal sources).

author: shapirus
author_rank: Super Contributor
timestamp: December 03, 2023, 03:38:40 pm
content: Quote from: Doctorandus_P on December 03, 2023, 12:48:40 amThey can actually be the same, at least that's been my experience so far. The "exclude from simulation" and "exclude from PCB layout" checkboxes in the component attributes allow to create a single schematic that suits both the simulator and the PCB editor. Again, I haven't done anything too complicated, so maybe I simply haven't hit some limitations in this area yet.I have "backported" changes to schematics based on both the simulation and PCB editing results countless times, since each of them, by allowing to look at the same thing from a different side, so to speak, can give ideas as for what extra parts may be needed, or, on the contrary, what parts are extraneous. After (almost) every such a change I re-run the simulator to make sure that it still works as expected, and then update the PCB layout with respect to the schematics change.Thus it is very useful to have a single schematics, serving as the single source of truth (if that's the right term), or the "master copy", that, when it's changed, automatically updates the respective data in both the PCB editor and the simulator.