# ECE Software

Back to Hspice...

### A Common Emitter Amplifier Example

Consider the amplifier shown below:

To simulate this amplifier, we need to write a spice file to represent it. A spice file is a file which contains one element or instruction per line. Examine the spice file for this circuit below:

```Example Amplifier

* The first line of the spice file is the title, and
* is the only line which does not follow any
* formatting rules.  Every line beyond that must
* the comment character "*".  The * tells hspice to
* ignore these lines, and treat them as user

* The next 2 lines tell hspice which nodes the
* resistors are connected to.  Note that the lines
* begin with "R" to let spice know the rest of the
* line describes a resistor.  The format for a
* resistor line is:
* Rname +node -node value

RC vdd vout 5k
RE 1 0 10k

* Similarily, we put in the transistor and the
* voltage sources as follows: (refer to the rest of
* the help file or a hspice manual for line
* formatting instructions for these and other
* devices)

Q1  vout vin 1   Q2N2222
C1  1    0       10u
VIN vin  0       AC=1 DC=1.7v SIN(2.5v .5v 1kHz)
VDD vdd  0       DC=5v

* Now that we have finished adding all the
* components in our design, we must tell spice how
* to go about simulating the design.  First, lets do
* a AC-analysis which will sweep the input from one
* frequency to another frequency in given steps.
* This will allow us to determine the speed of the
* circuit.  We'll sweep it from 10 Hz to 10 mega-Hz
* (written 10meg or 10x).  The format for this line
* is:
* .ac dec numpoints-per-decade start-freq stop-freq

.ac dec 10 10 10meg

* Lets also do a transient analysis, letting the
* input change in time as the sinusoid defined above
* on the "VIN" line.  We do this with a ".tran"
* statement, who's format is:
* .tran step-size end-time

.tran 10u 1ms

* We must tell hspice that we want it to create two
* outputfiles which will contain all of the
* simulation results and that we want to process it
* with hspice's post-processor "cscope".  We do this by
* including the following line:

.options post

* Finally, we want numerical text output as well as
* the gsi files, so we add:

.print ac v(vin), v(vout)
.print tran v(vin),v(vout)

* to tell spice to print the results for the 2 nodes
* vin and vout.  We can also get a ascii-plot of
* this data by including:

.plot ac v(vin), v(vout)
.plot tran v(vin), v(vout)

* The very last thing in the spice file is the model
* statements for the transistors we are going to
* use.  Included below is a model for the popular
* Q2N2222 npn transistor:

.MODEL Q2N2222 NPN(IS=28.2F XTI=3 EG=1.11 VAF=101.8 BF=224.1 NE=1.327 ISE=28.2F
+  IKF=.5699 XTB=1.5 BR=3.374 NC=2 ISC=0 IKR=0 RC=0 CJC=12.14P VJC=.75
+  MJC=.3333 FC=.5 CJE=23.71P VJE=.75 MJE=.3333 TR=113.7N TF=340.7P ITF=0 VTF=0
+  XTF=0)

* Finally, we are done with this file.  The last
* thing spice expects in the file is a .end
* statement, letting spice know it can stop reading
* input and begin a simulation:

.end
```

### Further Sources of information for Hspice and CScope:

1. View the Hspice manual page by entering man hspice at the unix command prompt.
2. How to run hspice and how to view the simulation results.
3. See other ECE department tutorials on Hspice/CScope.