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

Converting Samsung S-Note .snb file to video : Solved ?

After my recent post ( http://electrokavalam.blogspot.in/2013/05/converting-samsung-s-note-snb-file-to.html ) about the difficulty in converting a Samsung S-Note .snb file to video I got some encouraging comments which made me realize that the problem is indeed relevant to some people at least. I am happy to announce the prototype solution that I have put together. This solution can convert the snb to a flash movie that can be easily viewed using a web browser with flash player installed. So, here are the steps: Step 1: Get the "drawingdata_1" file The (x,y,time) coordinates of the pen are available in text format within the .snb archive. Rename .snb to .zip and extract the archive. Navigate to <extracted-folder>\snote\media directory. You will find "drawingdata_1" file there. This is a simple text file (in XML format) that we are interested in. Step 2: Create flash movie using snb2swf From a command prompt run snb2swf.exe (which may be downloade...

matplotlib.pyplot - A great way to plot

http://matplotlib.org/users/pyplot_tutorial.html It can be confusing in the beginning - there is this pylab module which are used in the examples on the scipy site, then there is pyplot, pylab and matplotlib. As I understand, matplotlib is the main package and it has two modules - matplotlib.pylab, matplotlib.pyplot. The first one is designed for interactive use and the second one for batch/script use. In the light of my experience with matplotlib.pyplot, I have found it to be very similar to MATLAB in usage. Remember, the above are just plotting libraries. For manipulating vectors, matrices etc. it is the job of Numpy/Scipy

Learning assembly is easy

More than a year ago, in the fourth semester of my engineering studies I was formally introduced to the assembly level programming of the Intel 8086. However, to test my programs I got a special software package installed on my PC. The extra piece of software was justified as there was the need for an emulator - something that mimics the 8086 on anybody's computer. But the question remained ... when am I going to write an assembly program that I can directly run on my own processor and not on an emulator. Now, after a while and having rediscovered my interest for assembly I have finally figured out that it is extremely easy using gcc on my Linux terminal - Write the assembly code and save to a test file with the extension .s. Next on the terminal $ gcc test.s $ ./a.out Done !! Here is a wonderful tutorial http://linuxgazette.net/issue94/ramankutty.html