Skip to main content

Introduction to circuit simulation

Through this article on circuit simulation my goal is to have a useful tutorial for students and enthusiasts to jump start into circuit simulation using taking advantage of the free software available on the WWW. The softwares run on Linux though.

However, I felt that writing a tutorial from scratch will be unnecessary as good tutorial are already there, though not all at the same place. Hence, I have identified some very useful resources and have brought them out here.

So, lets start and go in steps.
  • Analyzing Circuits with SPICE on Linux,  http://www.linuxjournal.com/article/2169?page=0,0 by Kevin Cosgrove
    • This article written in 1997, covers the essentials to simulate your first circuit and will give you a puritan perspective of SPICE and its usage. However I recommend that we wait before actually trying out the things. This is because the SPICE package Kevin demonstrates is spice3. However, we shall use ngspice which is nothing but an improvement over spice3 and is now the simulator recommended by gEDA (what gEDA is not really relevant at this point, but I shall explain it later).
  • Setting up ngspice.
    • Look for the ngspice package in your system's package manager (eg. Synaptic in Ubuntu) and install it. If problems arise, the download link to the package (< 10 MB) can be found at ttp://ngspice.sourceforge.net/download.html and use the familiar tar -> configure -> install sequence to install.
  • Simulating a circuit using handwritten netlist
    • Now, its time to simulate our first circuit using ngspice. The best place to find good examples is the ngspice user manual itself which can be downloaded from http://ngspice.sourceforge.net/docs.html. Though, a large document I have found it very useful. Search for "Example Circuits" in the contents and try out one of the examples - "AC coupled transistor amplifier" to get familiar with simulating, plotting etc.
  • Using gEDA tools to generate netlist from a schematic
    • At this stage, we are all set to simulate any circuit using ngspice provided we have written the netlist. Since, this can be quite laborious, we now turn to tools that will generate netlist from a schematic of the circuit - a process popular as "schematic capture". As with any free software enterprise, we have to rely more than one software to go from schematic to netlist. These tools are part of the gEDA project. Anyway, the tool chain is as follows we draw the schematic in gschem whose .sch  files are used by gnetlist (using an appropriate backend like spice-sdb) to generate a netlist which is nothing but a text file. This is explained in http://geda.seul.org/wiki/geda:ngspice_and_gschem
My sincere thanks to the authors of the above references.
That completes the tutorial. Below, are some extra information that might help fill some gaps.

  • Circuit simulation using gEDA and SPICE -- HOWTO, http://www.brorson.com/gEDA/SPICE/t1.html by Stuart Brorson
    • This tutorial clarifies the process of netlist generation very well and also gives valuable insights into the tool chain itself besides an overview of the gEDA effort.
  • Device models
    • When simulating practical circuits its important that we provide SPICE the right models. One of the best places to get them are from the websites of various manufactures.
    • http://www.onsemi.com/PowerSolutions/supportDoc.do?type=models is a great place to go for models as they provide models that work directly in ngspice, as opposed to some manufactures who only provide models for commercial simulators like PSPICE.
      • As an example, search for 2N3904 (a popular general purpose NPN BJT) on the page. The search results in 4 items. The "SP3 Model for 2N3904" will work in ngspice directly. Hence, download the file 2N3904.SP3.
      • To include this model, add a "spice-model-1.sym" symbol in the schematic (refer to http://geda.seul.org/wiki/geda:ngspice_and_gschem) and set "model-name", "file" attributes to "2N3904", the path of the downloaded file respectively. Now set the "model-name" attribute of npn transistor's used in the schematic to "2N3904" so as attach the model to the transistors. 
    • http://homepages.which.net/~paul.hills/Circuits/Spice/ModelIndex.html#c is from where I got the cue to ON Semi's page.
To be done: I feel that a small video on using gschem will help to getting at speed with it. Type in the handwritten notes about evolution of spice, its home page etc.

Comments

Popular posts from this blog

Competitive Programming

Programming a Sport ? I didn't know that until today !! I was amazed to look around and find that so many initiatives abound on the internet that aim at popularizing programming. I got started at codechef.com , then watched an amazing inspirational video http://www.codechef.com/school The getting started page launched me into a web of great resources - http://www.codechef.com/getting-started Check every link ! I met two great heros of the sport in that great journey - 'tourist' and 'petr' The latter is elder to me while the former is just 19 now. petr works for Google but is still a great force in the sport. The ACM ICPC is like the olympics of programming where teams participate. Codechef's envision's the Indian team winning some day and the Go-for-Gold section is particularly geared towards that. Codechef also has a school section. Mathewkuttan, Maxwell - what do you think ?