2
\$\begingroup\$

I am doing a MATLAB project at my university.

I have tried to implement DC and transient analysis of diode and transistor circuits by linearizing them and using iterative methods, but the results don't converge.

How do SPICE simulators do the magic?

Links to resources would be very helpful.

I have followed this website.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ SPICE was developed decades ago as a university project and is pretty well documented. What searches have you tried yourself? Do you have any specific questions? \$\endgroup\$ Jul 3, 2021 at 13:21
  • \$\begingroup\$ I have tried replacing diode with its linear companion model. It works good for DC analysis. But it doesn't do so for transient analysis. I am searching for numerical methods, equivalent models of diode and transistor that work fine for both DC and transient analysis. \$\endgroup\$
    – M. Fahmin
    Jul 3, 2021 at 14:03
  • 2
    \$\begingroup\$ You say "I am searching"...what have you found so far? We generally don't put much effort into answering questions where someone basically asks us to do an internet search for them. \$\endgroup\$ Jul 3, 2021 at 14:06
  • \$\begingroup\$ I followed this website. The linear companion model of diode and the numerical method that I followed are here. ecircuitcenter.com/SpiceTopics/Non-Linear%20Analysis/… \$\endgroup\$
    – M. Fahmin
    Jul 3, 2021 at 14:11
  • \$\begingroup\$ Here’s the source code for a great simple web simulator. falstad.com/circuit/offline FWIW based on physics. Voltage sources nor Caps cannot be ganged without ESR, but convergent solution for CC sources has been made converge , albeit with infinite voltage. Passives have optional small initial conditions. \$\endgroup\$ Jul 3, 2021 at 16:20

3 Answers 3

11
\$\begingroup\$

I strongly recommend that you get and read "The Designer's Guide to SPICE & SPECTRE" by Kenneth S. Kundert. The book covers every topic in which you are interested, and in detail. It will do more for you than any other single resource. (It certainly helped me.)

In Chapter 2, on DC Analysis, he immediately dives into the problem in 2.2 DC Analysis Theory and then, 2.2.1 Solving Non-Linear Equations, and then 2.2.2 Convergence Criteria, and then followed by 2.2.3 Convergence, where he starts out by writing, "Failure of circuit simulators to converge is a serious problem. One large electronics company estimated that their circuit designers spent an average of two hours a day trying to cajole their simulators into converging."

The author also discusses a key difference between SPECTRE and SPICE. SPECTRE uses KCL to determine convergence. The problem with this is that tiny parasitics (such as \$1\:\mu\Omega\$) can leave computations requiring better than an absolute voltage precision of \$10^{-18}\$ in order to converge and, often, this means that KCL is never satisfied in SPECTRE and it just won't converge. In contrast, SPICE decided not to use KCL as a convergence requirement. But as a result of that decision, SPICE can and does falsely converge where it should not.

You'll also learn why it is that MOSFETs capacitance models in SPICE are not and cannot ever be made to actually model a MOSFET, properly. Charge conservation is vital with MOSFETs. But Meyer capacitances are incomplete and inconsistent. So there cannot ever be a charge function, when differentiated, that gives Meyer capacitances. The mapping doesn't exist. So it isn't mapped and people live with the problems in SPICE. (SPECTRE can be made to do it more readily, but then again it may not converge, either.)

As I say here, you really need this first book.

Also, go and get the primary document, "SPICE2: A Computer Program to Simulate Semiconductor Circuits" by Laurence W. Nagel, directly from Berkeley. This one is entirely free. Just click on the PDF link at that site. It's probably an essential base -- everyone knows about it, refers to it, and it is a primary resource by one of the primary people involved in developing SPICE. (The first book mentioned above provides the overall perspective you need, and is an essential read that doesn't lose sight of the necessary details, before diving deep into SPICE2.)

Finally, go and get "The SPICE Book" by Andrei Vladimirescu. This book is also excellent and will help you a great deal, as well. But I'd place it as the 3rd book to get, if you can only consider two. You really do want to have the first two, for sure. But I think this one is almost just as important.

This third book provides excellent examples of applying KCL nodal equations in preparing circuits for analysis. (Right away, in fact, in the very first chapter on What is SPICE?.) The clarity in these examples were what enabled me to develop the insights that I use today in my own KCL methods, which differ from those found in textbooks.


These three books in particular were the ones that Mike Engelhardt, who is responsible for LTspice from Linear, recommended to me many years ago when I was struggling to learn how SPICE works, inside. And I can assure you that I was not in any way disappointed by his recommendations. I can pass them on with my grateful recommendation.

\$\endgroup\$
5
  • \$\begingroup\$ Designer's Guide to SPICE and Spectre splash page: designers-guide.org/analysis/dg-spice/index.html. \$\endgroup\$ Jul 3, 2021 at 18:14
  • \$\begingroup\$ @SystemTheory Thanks. The first book coupled with the SPICE2 from Berkeley composed, for me, what I needed in order to implement my own naïve, but serviceable code. Mostly, I just wanted to see if I could independently validate the process with available sources. And yes, I could. I stopped at that point, satisfied. \$\endgroup\$
    – jonk
    Jul 3, 2021 at 18:21
  • \$\begingroup\$ I learned SPICE in the late 1980s during studies for BEE. My home computer was IBM compatible 8088. I had student version of SPICE on floppy drive(s). Even simple transistor circuits might take up to 30 minutes to find out whether convergence or not. By 1990 the EE Lab had Intel 386 machines with 25 node limit and converge within 3 minutes or so for relatively simple circuits. A few years ago Windows software (DYNAST Solver) was available for mixed system simulations using circuit methods. I used Transient analysis to simulate physical systems from the Mythbusters show with good results. \$\endgroup\$ Jul 3, 2021 at 18:46
  • \$\begingroup\$ @SystemTheory Thanks! It's nice to hear personal stories like this. Too little of that here, I fear. I wasn't aware of DYNAST, until now. So thanks for that tidbit. I'll look into it more, when I get a moment. It's pasted into my 'todo' list now. Also, your EE Lab computers probably were 386DX with the 387 coprocessor on them. So that may have helped, along with the clock rate changes. \$\endgroup\$
    – jonk
    Jul 3, 2021 at 19:56
  • 1
    \$\begingroup\$ Yes the Intel 386 most likely did have the integrated floating point coprocessor. DYNAST (dynshell.exe) is not available for download from the primary source. This is the 1 page flyer home.zcu.cz/~nohac/Dynast/…. This may be a copy of the software for download here: dynast-for-windows.software.informer.com. This link home.zcu.cz/~nohac/Dynast/… has a 157 page pdf under link: Course on Dynamics of Multidisciplinary Systems. \$\endgroup\$ Jul 4, 2021 at 1:28
2
\$\begingroup\$

I think you're best bet is looking at the SPICE source code, either the original SPICE3f5 or ngspice. The code contains hidden tricks which are not typically highlighted or mentioned in SPICE textbooks. ngspice will also contain some of the newer tricks implemented in the industry since SPICE3f5.

One such example is when I was struggling to match hand calculated Newton iterations of a simple diode circuit to what SPICE was actually doing. It turned out there was a little trick they employed involving something the authors called \$V_{CRIT}\$. It is related to finding the minimum radius of curvature for the diode I/V plot, and is further explained in the bottom half of this article. You can easily find Vcrit in diotemp.c and devsup.c of the ngspice source code. Although this specific Vcrit technique is mentioned in the original 425-page SPICE2 reference document (on PDF page 150), it was much easier to find when skimming through source code.

\$\endgroup\$
0
\$\begingroup\$

According to this link some people apparently try to link Matlab to Spice:

https://www.mathworks.com/matlabcentral/answers/71606-what-is-the-preferred-way-to-interface-matlab-with-spice

I have a lot of experience with MATLAB, and very little experience with SPICE (did some stuff back in university). I'd like to setup a simulation in matlab involving some electronic circuits, and preferably be able to change parameters and plot results from MATLAB. I have googled this but did not find anything conclusive?

We have customers who work a lot with Spice simulation and Matlab. In general the Spice simulation is done by one of the numerous commercial simulators or an open source simulator like NgSpice. The the simulation results can then be read by a specialized toolbox and processed in Matlab. You can find some simple solutions for reading simulation outputs on stackexchange: http://www.mathworks.com/matlabcentral/fileexchange/8237-import-spice-raw-file/content/ReadRawSpice.m We have wrapped our C/C++ solution in a Matlab toolbox for our customers who use Matlab for post-processing, model extraction and characterization. This toolbox is little more complicated to use but it can handle many different file formats, it can handle huge files and it is quite fast. You can find further informations at http://www.analogflavor.com/en/parse-spice-simulation-output-with-matlab/

However it is probably much easier to learn how to simulate circuits directly in Spice such as LTSpice.

This 7 page tutorial demonstrates the Transient simulation and DC sweep using LT Spice through an example of a half-­‐wave rectifier:

https://www.seas.upenn.edu/~jan/LTspice/ESE216LTSpiceDC&TransientSimulations.pdf

Convergence problems are often caused by improper circuit description, improperly specified initial conditions, and poor choice of time-step among other concerns.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.