1
\$\begingroup\$

I have written a circuit simulator that uses Kirchoff's voltage and current laws to solve linear circuits containing capacitors, resistors, inductors and op-amps (where the op-amps are assumed to be linear), but I'd like to add support for diodes and transistors and I'm a bit lost as to how to do it.

My program is essentially an implementation of modified nodal analysis - using the user's specified circuit, I build a series of simultaneous equations into an admittance matrix and solve it for the circuit's input using a sparse solver. It works well for performing small signal ac analysis to calculate transfer functions and noise.

Diodes and transistors are of course non-linear, and must in the latter case have negative feedback applied by the circuit to linearise them. They do not have a (simple) frequency dependent resistance dependency like the passive components I have already implemented, but rather a transconductance set by the bias in the circuit, so my admittance matrix approach doesn't really work for circuits containing diodes and transistors. I think SPICE handles non-linear components by first finding the "dc operating point" of the circuit, then it replaces the non-linear components with equivalent impedances (perhaps with e.g. parasitic capacitance as well) but I don't know how to do that. In my current program, I do not need to calculate the dc operating point because this is implicitly zero due to the presence of only linear components. If anyone can describe the process of calculating the dc operating point of circuits with diodes and transistors, or if they could point me towards any documents or texts that describe how to perform such an analysis (or perhaps some source code in a high level language), I'd be grateful!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Do you have the Seda and Smith textbook? I would just paste the four pages from section 4.3.7 from there an an answer but I don't know if we are allowed to do something like that. \$\endgroup\$
    – DKNguyen
    Jun 25, 2019 at 21:01
  • \$\begingroup\$ @DKNguyen, do you refer to this? If so, then no I don't have it. \$\endgroup\$
    – Sean
    Jun 25, 2019 at 21:04
  • \$\begingroup\$ Yes, that ...... \$\endgroup\$
    – DKNguyen
    Jun 25, 2019 at 21:05
  • \$\begingroup\$ Why don't you just look at the SPICE source code and documentation? Why are you reinventing that wheel? \$\endgroup\$ Jun 25, 2019 at 21:42
  • 1
    \$\begingroup\$ One way of solving it is iteratively, such as Nonlinear systems of Equations. It is Newton's method but for 2 or more variables. It is indeed an iterative solution, but you are simulating across time, this means that you can use the previous time step as your starting point and this will make your number of required iterations substantially lower (the more iterations, the smaller the error). So the first time step could take a lot of time, but after the first one it will flow like water. \$\endgroup\$ Jun 26, 2019 at 4:14

3 Answers 3

1
\$\begingroup\$

Not too much for me to say since it's so straightforward other than make sure to read through the derivation, especially the parts related to the first two terms of the exponential series. enter image description here

enter image description here

enter image description here

...

Source: Microelectronic Circuits 7th Edition, Sedra/Smith

It's a good book, though it can be difficult to tell if you're in class getting so much work shoveled onto you that you never have the chance to actually sit down and read it. The paperback is half the price of hardcover. You should buy it.

\$\endgroup\$
10
  • \$\begingroup\$ Let me know if an answer like this is not allowed. \$\endgroup\$
    – DKNguyen
    Jun 25, 2019 at 21:06
  • \$\begingroup\$ Thanks for the recommendation, that looks very useful. I still don't really see how to compute the bias (Q) point that the book section mentions though. I guess it must involve some non-linear equation solving using e.g. Newton-Ralphson, but I don't know how to treat e.g. the op-amps, capacitors and inductors in the circuit (I assume the latter two I open and short, respectively, but that's a guess). Do you know if that book also talks about those points? \$\endgroup\$
    – Sean
    Jun 25, 2019 at 21:24
  • \$\begingroup\$ I think that's in section 4.2 of the book but I can't really post the entire chapter. It basically boils down to Equation 4.11 I think. The book is mostly about transistors though being called microelectronics and you don't really find Ls or Cs inside integrated circuits. \$\endgroup\$
    – DKNguyen
    Jun 25, 2019 at 21:31
  • \$\begingroup\$ I edited my answer to also include transistors, which I would also like to model, since I forgot to mention that part (that's why I was talking about negative feedback). I assume with transistors (but I think also diodes) I first need to compute the Q point as discussed in your posted book section. Some circuits with certain component values won't settle and so there must be some first step to linearise the circuit or identify a circuit that doesn't settle. \$\endgroup\$
    – Sean
    Jun 25, 2019 at 21:34
  • 3
    \$\begingroup\$ @Sean, this tells you (nearly) all about SPICE internals, as it was in 1975. What's there is pretty much still how numerical simulators do operating point and small signal AC analysis. \$\endgroup\$
    – The Photon
    Jun 25, 2019 at 21:52
0
\$\begingroup\$

You are reinventing the wheel. Open source versions of SPICE* already exist. Instead of rolling your own, why not study, and possibly improve, the existing simulator?

* If that link rots, just search on "open source SPICE".

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'm having fun making my own, and making my own helps me understand how circuits work. I'm not trying to take on SPICE, this is a personal project; but even if I was, I think this would still be a valid question and we should not just ignore the details because someone already worked them out. \$\endgroup\$
    – Sean
    Jun 25, 2019 at 21:21
0
\$\begingroup\$

The precursor to SPICE at Berkeley was an operating-point software program.

That was key in, as you already understand, building a small_signal simulator.

\$\endgroup\$

Your Answer

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

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