SPICE Backend

SPICE stands for Simulating Program with Integrated Circuit Emphasis. Essentially a program for simulation of electrical circuits. We will look at a very small spice backend, written in C. The project was part of CAD Lab assignment for electrical engineering students.
Since there will be many equations, i have compiled the document into a PDF using LYX, the document processor. But i will briefly explain about the project.

Circuit simulation, is an easy task, till there are only few nodes. However, as the nodes and elements increase, the complexity increases exponentially. To ease our task and solve the repetitive process of solving equations, we write a simple program.

Our job, as the end user is very simple:
1. Write a net list, containing all the information about the circuit. Please note that, you need to draw the circuit on paper, label the nodes and write the net list accordingly.
2. Invoke the program.

Simple isnt it?

Now let us look from the programmer’s perspective:
1. Read the netlist. Convert all the data into numericals and node names. Scan for all errors
2. Create the circuit as a set of structure elements.
3. Create a matrix to solve the simultaneous linear equations
4. Write the output to file

The first step is a little difficult among all of them. Parsing a file in C with numericals, especially with muultipliers like nano, pico, micro etc is not trivial.

Once done, we use linked lists to store the information about the elements, the nodes to which it is attached, the values, the dependencies if any etc. Once this is done, we traverse the linked list again to fit all the values into a neat matrix. Solving this matrix will give back all the node voltages.

Download the following file to read about the spice backend.

SPICE_Backend

A few things i wanted to add:

1. The elements as plugins to the program, so that it is possible to add new elements

2. Better matrix inversion algorithms

3. A GUI frontend

In case you want the code, please drop a comment with your mail ID, so that i can mail it to you.

Advertisements

4 thoughts on “SPICE Backend

  1. Thank you for some other informative site. The place else may I am getting that kind of information written in such an ideal way? I have a venture that I’m simply now operating on, and I’ve been on the look out for such info.

    • Why not everything in python? Python code will boil down the whole program to around 200 or 300 lines. However, this was a CAD lab assignment which had to be done only in C. Sometime in future, we can surely try out writing in python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s