SPICE

From CPUDev Wiki
Jump to: navigation, search

This page or section is a stub. You can help the wiki by accurately contributing to it.

SPICE (Simulation Program with Integrated Circuit Emphasis) is an open source analog circuit simulator. It is used in integrated circuit design to simulate circuit behaviour.

Variants

Usage

Circuit Components

  • Elementary Devices
    • Resistors (RXXXXXXX N1 N2 VALUE)
    • Capacitors (CXXXXXXX N+ N- VALUE <IC=INCOND>)
    • Inductors (LYYYYYYY N+ N- VALUE <IC=INCOND>)
    • Switches (SXXXXXXX N+ N- NC+ NC- MODEL <ON><OFF> or WYYYYYYY N+ N- VNAM MODEL <ON><OFF>)
  • Voltage and Current Sources
    • Independent
    • Linear Dependent
    • Non-linear Dependent
  • Transistors and Diodes
    • Junction Diodes
    • BJTs
    • JFETs
    • MOSFETs
    • MESFETs

A list of components and their formats can be found here.

SPICE file

Simple DC circuit

The image shown on the right may be converted to SPICE format as follows. This text can be put in any text file, usual extensions are .spice, .spc and .circ. The correct formats for the circuit components can be found above.

V1 A GND DC 5
R1 B GND 150.0
R2 A GND 2.2k
R3 B A 3.3k
.end

Any commands (analysis, initial conditions, models, etc.) must be preceded with a '.', like the '.end'.

With Open Circuit Design tools

The Magic VLSI Layout Tool and XCircuit tool from OCD can export to (flattened) SPICE format. For example, the VLSI cell shown on the right may produce the following SPICE file when extracted.

* SPICE3 file created from nand.ext - technology: scmos

.option scale=1u

M1000 Out A vdd w_n5_n3# pfet w=3 l=2
+  ad=22 pd=20 as=38 ps=36
M1001 vdd B Out w_n5_n3# pfet w=3 l=2
+  ad=0 pd=0 as=0 ps=0
M1002 a_2_n12# A gnd w_n5_n15# nfet w=3 l=2
+  ad=18 pd=18 as=19 ps=18
M1003 Out B a_2_n12# w_n5_n15# nfet w=3 l=2
+  ad=19 pd=18 as=0 ps=0
C0 w_n5_n3# vdd 2.1fF
C1 vdd gnd 2.1fF
C2 w_n5_n15# gnd 5.1fF
C3 w_n5_n3# gnd 4.8fF

.end

To make this functional, one needs to add voltage sources for all inputs, in case of the NAND gate above for VDD/GND, A and B. It is also important to make sure all models are defined. For example, the pfet and nfet devices are models of type pmos and nmos. OCD tools will not create the model definitions for you!

Analysis

Operating Point

If we take the example from the SPICE file section, we can perform an OP analysis (since the voltage is constant). To do this we either append the '.op' command to the SPICE file or running the 'op' command in the SPICE simulator. After the analysis has succeeded we can view the results by doing 'print a b v1#branch' where a and b are the voltages at A and B, and v1#branch is the current drawn from V1.

a = 5.000000e+00
b = 2.173913e-01
v1#branch = -3.72200e-03

Transient

Transient analysis allows for analyzing behaviour in the the time domain.

Example in XCircuit
File:SPICE TRAN example result.png
Collector current of the example

DC-Sweep

The DC-Sweep analysis changes the DC voltage from the specified voltage source from Vmin to Vmax in Vinc increments, and allows you to plot the circuits response to different voltages.

Example in XCircuit
File:SPICE DC example result.png
Collector current of the example

For example, we take the circuit on the left and transform that into SPICE. Then we run the following DC sweep analysis, which analyzes the circuit, varying the collector-emitter voltage (V1) from 0 to 5 volts in 0.01 V increments.

dc v1 0 5 0.01

Then we may plot the result (current drawn from V1, the collector current of the npn transistor) and get something like the image on the right.

plot v1#branch

AC Small-Signal Frequency Response