Connect with us

Developing a Circuit Simulator from Scratch

Discussion in 'CAD' started by [email protected], Feb 13, 2007.

  1. Guest

    Hi,

    Can anyone give me some directions on how to develop a circuit
    simulator from scratch. I need to develop a simple spice compatible
    simulator,that can read in spice netlists. I will be using C++ to code
    the simulator. I need to support only simple R,L,C, diode and mosfet
    devices and DC,AC and transient analyses. I would be using the Ebbers
    - Moll models. The problem is that I could not find any guidelines on
    how to actually go about writing a simulator from sctrach. I found
    several books that explain the different types of analysis but none of
    the books give a frame work to develop a circuit simulator.

    I am right now going through "Computer Simulation Of Electronic
    Circuits" by R Raghuram and "SPICE2: A Computer Program To Simulate
    Semiconductor Circuits" by Laurence W.Nagel. But, these are very old
    books and are based on FORTRAN.

    If anyone could suggest a website or a book it would be great help.

    Thanx,
    Balaji.
     
  2. How do you eat an elephant?
     
  3. In sci.electronics.cad wrote:
    : Can anyone give me some directions on how to develop a circuit
    : simulator from scratch.

    My question is: Why on earth do you want to do that? There are
    enough open-source simulators out there already which you can hack on
    that rolling your own seems rather daft. Is there a reason you need
    to roll your own?

    Do you think you can do better than what's already out
    there? If so, then you're probably wrong.

    Is your reason that you want to learn about circuit simulation so as
    to get a job in the glamorous EDA industry? In that case, choose one
    of the open-source simulators and work on it.

    Stuart
     
  4. Ian Bell

    Ian Bell Guest

    The source code the spice 3f5 is readily available. That should give you a
    few clues.

    Ian
     
  5. Le Mon, 12 Feb 2007 18:25:12 -0800, komminenibalaji a écrit :
    Why don't you try fix some bugs in some spice engines. I think it'a the
    better way to start your own project.
    Fortran ... "has been" language. See Spice C implementation like spice3f5.
    Habib.
     
  6. One of the existing open-source simulators might provide the
    framework you are looking for. QUCS is one of my favourite
    programs. I'm sure they would welcome your contribution.
    http://qucs.sourceforge.net/

    E.S.
     
  7. Guest

    Hi,

    I want to develop the simulator from scratch out of intrest rather
    than anything else. I don't want to develop a fancy high end
    simulation system like hspice or anyother spice based simulator out
    there. I was wondering if I could write a C++ simulator from scratch
    which could do simple transient,ac and dc analysis for basic circuits.
    I was inspired by the fact that the original SPICE2 was a class room
    project done by 6 students at berkeley.

    I have all the time in the world as it does not have a deadline. It
    can be something I can do over an year or more. But, I want the
    simulator to be developed from the scratch. I hope all of you would
    understand what I am trying to do even if it is stupid and
    meaningless. I would love to do it.

    Thanx,
    Balaji.
     
  8. Guest

    The source code the spice 3f5 is readily available. That should give you a
    I have seen the source code for spice3f5,spice2g6 and xspice. But, all
    those are really good simulators and thier source code is all too
    complex to understand due to the lack of proper documentation. I have
    also seen some of the other open source simulators such as
    freeda,superspice and ngspice. But, even though they are well
    documented they are also pretty complicated. I am just wondering if
    there is no simple way of implementing a circuit simulator if all it
    needs is a matrix based euation solver, newton rapson method and
    numerical integration.

    I have been looking at source codes for almost 5 months now. But,
    could not find anything that is really simple. I don't want to write a
    really fast or efficient but a simple simulator.

    Thanx,
    Balaji
     
  9. Chuck Harris

    Chuck Harris Guest


    Well, then you have already gathered some important clues: A circuit
    simulator is not a simple program!

    Even writing a few very specialized circuit solvers can be a daunting
    task to get right.

    -Chuck
     
  10. David Harmon

    David Harmon Guest

    On 13 Feb 2007 05:52:12 -0800 in sci.electronics.basics,
    wrote,
    Well, your initial post said that you did want it all. Meanwhile,
    read David Sager's explanation of the simplified approach:
    http://home.comcast.net/~stager21/Circuits.html
     
  11. john jardine

    john jardine Guest

    The book "Applied Circuit Design, matrix and computer methods" ISBN
    0-470-26908-1 is a tour de force if you wish to write your spice from
    absolute scratch.
    First half of the book will get you to the filled nodal admittance matrix
    stage. Then programme your options for transfer function, 2 port, state
    variable, sensitivity, tolerance etc.

    Problem is, that the author supplies sample programming in a beginners all
    purpose language called 'Basic', which is very similar to Fortran.
    Both languages though are ideal for this kind of complex mathematical
    processing, as they offer clarity of structure, simplicity and built in
    matrix operations.
     
  12. Guest

    Thanx for the website I was looking for something like this. Is there
    a website which is a little more advanced? Thanks once again.
     
  13. Guest

    Hi,
    Thanks for the book.
    The programming language does not matter as long as the author gives a
    framework on which I can build on. That is the problem I am facing.
    well but don't go into the details of how to build the intial matrix
    equations and then how to do error checking and so on. That's the
    difficult part for me. Anyways thanx a lot for the book.
     
  14. Simulate one resistor. Then two in series. Then two in parallel. Continue as
    needed.
     
  15. Joel Kolstad

    Joel Kolstad Guest

    There was a discussion of this just a month or two ago; Goole (groups) can
    find it for you.

    The other input you've gotten is some of the same information from that
    discussion, and I'll repeat here what I said there: I took a quarter-long
    course from this guy:
    http://eecs.oregonstate.edu/research/members/mayaram/index.html ... to build a
    SPICE-like simulator containing pretty much all the features you're looking
    for. If you ask him nicely, he might be willing to send you a copy of the
    course notes... or I might too. :)

    As others have alluded, you'll find that getting passive device simulation
    working is not particularly difficult. Once you start adding active devices,
    transient simulation and even DC convergence become rather complex -- there
    are many fancy academic papers over a handful of decades now trying to make
    such simulations robust, but it's not a completely solved problem even today.

    I disagree with the folks who say, "just join a group working on an
    open-source simulator" -- you'll find that in many cases, only a couple of
    people in the *entire group* really have an understanding of the "guts" of the
    simulator, and the vast bulk of people working on such projects are doing
    GUIs, netlist interfacing, etc. Many of these groups have started with, e.g.
    Berkeley SPICE 3f5 code and have been improving it over time (note that many
    *commercial* simulators used the same approach!). The likelihood that you
    could get a good grip on exactly what's going on just by starring at SPICE 3f5
    source code long enough is slim... you might as well try to figure out how a
    method-of-moments electromagnetic simulator works while you're at it...

    ---Joel Kolstad
     
  16. JeffM

    JeffM Guest

     
  17. Guest

    Hi Joel,
    Thanx for the information. Atleast now I know I am after something
    that is practical over an year.
    That's what I want to do. Understand the core of a circuit simulator.
    And while I am doing it I could as well code one and have fun doing
    it.

    Thanx a lot.

    Regards,
    Balaji.
     
  18. Joel Kolstad

    Joel Kolstad Guest

    Even Nagel had plenty of help with SPICE... Google "The Life of SPICE" and
    read about it in his own words.

    ---Joel
     
  19. I am going to repeat what already has been said. You are simple wasting your
    time trying to write a simulater from scratch. Its way to big a project for
    one person such that you could produce a usefull outcome. You can learn
    about spice without reinventing the wheel. You only have to note the docs at
    source forge. to wit..write one from sctratch...but uin the meantime... lets
    use code whats available. Listen er...sonny...these old timers do actually
    know what is worth doing...or not...sometimes.

    Kevin Aylward

    www.anasoft.co.uk
    SuperSpice
     
  20. Jim Douglas

    Jim Douglas Guest

    Good Luck and send me the URL when you are done so I can check it out.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-