Analyzing Circuits with SPICE on Linux

All about SPICE: how to get it and what to do with it.

SPICE is the Simulation Program with Integrated Circuit Emphasis, first released from the University of California at Berkeley in the early 1970s. Before the existence of SPICE engineers designed circuits by hand, possibly with the aid of a slide-rule or calculator. A prototype was constructed from the original design, and its performance evaluated against the designer's goals.

Designing many of today's circuits would be impossible without the aid of SPICE. Frequently analog circuits contain hundreds or thousands of devices. Design and analysis involve finding solutions to simultaneous equations. These equations can be of simple algebraic form or involve nonlinear differential equations. Prototypes are still constructed to gauge performance, but given costs running in the hundreds of thousands of dollars, performance must be largely anticipated through computer simulation before prototype fabrication begins.

SPICE is not limited to integrated circuit design. Rather, SPICE is useful for analyzing any circuit which can be described in terms of voltage sources, current sources, resistors, capacitors, inductors, transistors and a few other components.

Where to Get SPICE for Linux

SPICE version 3f4 was released in 1993, and the source code is freely available to those friendly to the U.S.A. You can get a copy of the source code from ftp://sunsite.unc.edu/pub/Linux/apps/circuits/spice3f4.tar.gz.

I run Red Hat Linux and use the Red Hat Package Manager (rpm). If you're running rpm, you can take advantage of Andrew Veliath's spice-3f4-2.src.rpm package. You can find a copy on ftp.redhat.com and mirrors. If you don't use rpm, you might want to consider building it and using rpm2cpio to unpack the spice-3f4-2.src.rpm package, since it contains two very useful patches to the pristine source for building on Linux systems.

How to Build/Install SPICE on a Linux System

If you're using rpm, building SPICE is as easy as:

rpm -ba -vv SRPMS/spice-3f4-2.src.rpm
rpm -i -U -vv RPMS/i386/spice-3f4-2.i386.rpm

The first line builds the installable package from the source package. The second line installs the package and updates the rpm database.

If you're not using rpm, building and installing SPICE is a little more involved but not too bad. The basic process is as follows:

rpm2cpio SRPMS/spice-3f4-2.src.rpm | cpio -i
tar xzpf spice3f4.tar.gz
patch < spice3f4.newlnx.patch
patch < spice3f4.dirs.patch
cd spice3f4
util/build linux

Compiling took 12 minutes on my 200MHz Pentium system.

util/build linux install
strip /usr/bin/{spice3,help,nutmeg,sconvert,multidec,\
        proc2mod}
install -m 644 man/man1/spice.1 /usr/man/man1
install -m 644 man/man1/nutmeg.1 /usr/man/man1
install -m 644 man/man1/sconvert.1 /usr/man/man1
install -m 644 man/man3/mfb.3 /usr/man/man3
install -m 644 man/man5/mfbcap.5 /usr/man/man5
After installation comes the real fun—creating and simulating circuits. While a minimal Linux system can run SPICE adequately, analysis time can be significantly improved when it is run on a system with a fast processor(s), 133MHz or above. Additional RAM is equally important, especially for larger circuits. I have 32MB in my home Linux/Pentium system and 128MB in my SunOS/Sparc20 at work.

Constructing a Simple Circuit

Figure 1. Differential Pair Circuit Schematic

Figure 1 shows a the schematic of a differential pair circuit constructed from bipolar junction transistors and resistors. This circuit can be used for either digital or analog purposes and, in either case, can be simulated using SPICE. The circuit operates in the following manner. Very little current flows through the base of transistor Q2, so the base can be considered to be held near ground potential, zero volts. When the input voltage, VIN, is low, near ground, Q1 will be off and Q2 will be on. No current will flow through Q1, so VO1 will be high, equal to VCC. All of the current in IEE will flow through Q2. The voltage drop across RL2 will be:

So the voltage VO2 will be 5V below VCC. So, VO2 will be 0V.

In linear analog operation VIN will be held near ground except for small signal excursions away from ground. Under this condition the differential pair will serve as an amplifier where the voltage gains are:

AV1 = VO1 / VIN = -(gm1/2) * RL1
AV2 = VO2 / VIN = (gm2/2) * RL2

where gm1 and gm2 are the transconductances of the two transistors. These values can easily be calculated by hand, but since the point of this story is to show SPICE at work, we'll let SPICE tell us the transconductance values.

Listing 1

Listing 1 shows the SPICE input file corresponding to the circuit in Figure 1. The SPICE input file contains a description of the circuit and its connections, input stimuli, statements to control what kind of analysis SPICE will perform, statements to control output, comments and a title. The first line is always the title and the last non-blank line is always .end. Comment lines begin with an asterisk (*). Control lines of any kind begin with a period (.). The line continuation character is a plus sign (+) which goes at the beginning of a line being continued from the previous line. This is a little different from the common backslash (\) line continuation, used elsewhere in Linux, where that continuation character goes at the end of the line being continued on the next line.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

construction of a simple calculator

Anonymous's picture

I'm an electronics student. i am willing to construct a simple calculator of my own. the problem is i don't know the circuit of it. My request to you is that you print the circuit connection of a simple calculator.

SPICE is probably the wrong tool for this

Anonymous's picture

SPICE is probably the wrong tool, unless you mean "analog computer" when you ask for a simple calculator. You can use SPICE to simulate an analog computer nicely. If you aren't familiar with what an analog computer is, it probably won't help much.

SPICE is a pretty low-level simulation tool for analog circuits. Digital circuits are built from analog circuits but a typical NAND gate alone can take up to a dozen transistors to represent, and even a simple calculator likely has thousands of NAND gates.

What you may want to look into is digital logic simulation that uses VHDL or Verilog. Such simulators work at a level that is comfortable for digital hardware such as a calculator. They do ignore many of the analog effects actually seen in real life circuits however. This is why both SPICE and HDL simulators are typically used in complementary fashion.

The other choice is to simulate using software such as C or any other language of choice.

building pspice

ziaa's picture

Can Pspice(linux based) will be enough efficient to support user as in windows??

YOUR WEB PAGE IS ALL SCREWED

Anonymous's picture

YOUR WEB PAGE IS ALL SCREWED UP!!!!

Re: Analyzing Circuits with SPICE on Linux

Anonymous's picture

very good, it realy help me.

thank you for your work.

some help needed

Anonymous's picture

Hi ,
I am trying to install spice on linux .
But every time I try to do so installation stops with error saying "couldnot find the file -ltermcap .
though when i install the termcap on my system it says package is already installed...!
can some one help me figure out what actually is gooing wrong.

BR
Ashish

Re: Analyzing Circuits with SPICE on Linux

Anonymous's picture

Excellent tutorial !!! It's just what I needed to get spice running at home after a brief introduction to pspice on MSDOS at school.

Well done,

B. Liessens

Re: Analyzing Circuits with SPICE on Linux

Anonymous's picture

a very good article for new spice3 users who want to install spice3 sources on linux systems and start using it.

wow, i'm impressed it is

Anonymous's picture

wow,
i'm impressed it is what i was searching for, at my uni theyre using pspice student version ;-) i was fedup with limitations like 50 parts at all and the windowssystem and now i'm here, and the samples are running on ngspice, every thing is fine and the best ! i know what i'm doing
thank you

hi , i am very much in ne

Anonymous's picture

hi ,

i am very much in need of u. i have the same problem as u ,of installing the spice3 on linux. please give me the solution to this problem for which i will be grateful to u.

could you please provide the

Anonymous's picture

could you please provide the basic knowledge of adding the patches for bsim4 or bsimsoi model. or couls u do it and put on some site so that we could be able to do the work on spice with latest models...

help will be appreciated.

anyways this was great tutorial. very helpful.

spice for linux

Anonymous's picture

Hi

This was a useful article in general but after wrestling with Linux
gEDA on RedHat enterprise AS4 I can say that the KDE gui versions
are really well suited for SUSE professional or Fedora not enterprise
version. I think that spice comes with SUSE even. I had to install
the non RPM versions because wxwidget-config, guile-config and many
other config files did not come with the RPMs. I also had to install
GTK+, GTK-devel and many other things and when I was through well
the student version of PSPICE still blew the linux version away. Many
versions of linux are compiler dependent meaning you just can't take
a executible from one version and run it on a later version like
the backward comparability of SunOs. My friends who work professionally with Linux say its a nightmare and have a build engineer just to straighten out executables and libraries. I have
to use Enterprise Linux to run Oracle 10G version 2 because I heard
a lot of problems with SUSE 10.1 professional, therefore gEDA is
not an option.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState