An Introduction to IC Design Under Linux
Before beginning a simulation, first create a SPICE file and add transistor models and SPICE commands to it. Next, simulate the inverter to verify that it was laid out correctly.
First, translate the inverter.ext file into something that SPICE can understand. The ext2spice program by Stefanos Sidiropolous that comes with the Magic distribution performs this translation. Simply enter:
ext2spice -f spice3 inverter.ext
We specify “spice3” format output, because earlier SPICE versions can't handle text strings for labels.
We now have a file that SPICE can understand, but it's incomplete in an important way. For SPICE to simulate a device correctly, it needs a model, a mathematical description of the device's behavior. In particular, we now need models for the two transistors (n-type and p-type) that we've used in our design.
SPICE has a variety of built-in transistor models specified in terms of sets of parameters. These parameters vary according to the fabrication process used, so it's up to the user to specify the correct parameters for the process being used. Fortunately, you don't have to figure these out yourselves—you can get them from MOSIS at ftp://ftp.mosis.edu/pub/mosis/vendors/orbit-scna20. This FTP site contains a whole slew of data from past runs; we chose a typical one from the “Level 2 Parameters” section. One minor detail—note that you need to change the “CMOSN” and “CMOSP” to match ext2spice's output, “NFET” and “PFET”.
After pasting in the transistor models, the inverter.spice file should look like Listing 1.
We've drawn the inverter and extracted a netlist. Now we need to simulate the chip to make sure it'll perform as expected when the chip is fabricated. A simulator such as SPICE can do many different types of circuit analysis. We will demonstrate two that are very useful for the digital circuit designer.
It might seem curious to use an analog circuit simulator for a digital circuit. We think of digital circuits as being in one of two states, 0 or 1, while analog circuits can take any of a continuous range of values. What's important to realize is that a digital circuit is actually a special kind of analog circuit. At the circuit level, a signal is either a voltage or current, and these are really analog quantities. The conventional 0 and 1 representations of a bit are simply abstractions of two particular voltage values; the actual values depend on the process in which the chip is fabricated. With CMOS in particular, you can generally ignore the currents and deal only with the voltages, due to the FET's mode of operation. For example, in the particular process for which we extracted our inverter, a 1 corresponds to 5 Volts (5V). In other processes, it might correspond to 3.3V or 2.5V. Happily enough, a 0 generally means 0V. As we all know, digital circuits don't switch instantaneously between their two values. It takes time to change voltages, and this delay is one of the things that makes your CPU run at 100MHz instead of 133MHz.
The upshot is that SPICE simulates analog behavior, but as digital circuit designers, we will interpret the circuit's output as digital bits rather than the analog voltages they actually are.
Simulators specialized for digital circuits do not provide the level of detail, that is, accuracy, that SPICE does, but they are orders of magnitude faster. IRSIM, which is available through the Magic WWW home page (see Resources at the end of the article) is an example of such a simulator.
Suppose we apply the test vector 101 to the inverter over a period of 75 nanoseconds (1 ns = 10-9 seconds). How will the output change over this time interval? To answer this question, SPICE can do a transient analysis. In a transient analysis, you define the input signal(s) and tell SPICE to simulate the circuit for a certain amount of time from the circuit's point-of-view, not real time. A transient analysis provides timing information, for example, how long the output takes to switch from 1 to 0. This analysis is also useful for verifying the circuit's functionality; you simply apply the test vector and check the output for correctness.
Let's apply the vector 101 to our inverter. Add the following lines to the end of the inverter.spice file:
Vpwr Vdd Gnd 5 Vgnd Gnd 0 0 Vinput in Gnd 0 PULSE( 0V 5V 0ns 2.5ns 2.5ns 25ns 50ns ) .TRAN 0.1ns 75ns .end
Let's go over this specification line-by-line. Line 1 defines a 5V voltage source between Vdd and Gnd; this is the power supply. Line 2 is necessary because of a SPICE artifact of always referring to ground as 0. We simply tie Gnd and 0 together (electrically speaking) by using a 0V voltage source, i.e., a short-circuit. Line 3 defines a voltage source between “in” and ground; this is the inverter's input. Looking at the parameters in parentheses, we have a voltage source whose initial voltage is 0V and “pulsed” voltage is 5V, and it starts after a 0ns delay. It has a rise time (i.e., the time required to switch from 0 to 1) of 2.5ns, and a fall time (i.e., the time required to switch from 1 to 0) also of 2.5ns. The width of each pulse is 25ns, and it repeats after 50ns have elapsed. Line 4 means that we want to do a transient analysis with a resolution of 0.1ns that lasts for 75ns. Line 5 ends the circuit file. Save the file, then run the simulation by typing:
spice3 -r inverter.out < inverter.spiceNow, let's view the results by typing:
sigview inverter.outWe're interested only in the top two signals, “out” and “in”, as shown in Figure 6.
From the digital point-of-view we see that the inverter correctly produces a 010 pattern; from the analog point-of-view we see that the output's rise time is about 0.91ns and its fall time is about 0.89ns.
Practical books for the most technical people on the planet. Newly available books include:
- Agile Product Development by Ted Schmidt
- Improve Business Processes with an Enterprise Job Scheduler by Mike Diehl
- Finding Your Way: Mapping Your Network to Improve Manageability by Bill Childers
- DIY Commerce Site by Reven Lerner
Plus many more.