EE 240 UC Berkeley, EECS Department
Prof. B. E. Boser Page 1 of 4
SPICE and MATLAB
This document explains how to configure and use SPICE and MATLAB on the EECS
instructional servers. You can use a different environment but we cannot support it. Instructions
for creating and using instructional accounts are at http://inst.eecs.berkeley.edu.
We will be using Spectre, a version of SPICE from Cadence, for circuit simulation and Matlab
for plotting results. Cadence runs under Linux; make sure to connect to an appropriate server
(not a Windows computer).
Setting up the Environment
Copy the file bashrc from the course website (resources) to your home directory on the
instructional machines and rename it .bashrc (note the “dot” at the beginning of the filename).
If you already have a .bashrc file you may want to merge the two files using an editor (e.g.
gedit).
Then run the following command at the prompt:
source ~/.bashrc
Verify your Spectre setup. If your setup is correct, typing
spectre –h
at the command prompt displays the version of the simulator and some documentation.
Running Matlab on a Linux computer requires running X11. Either login locally on one of the
instructional machines or follow the instructions at the instructional website for setting up X11
with remote login.
Start Matlab by typing
matlab &
at the command prompt. Help and documentation are available from the graphical user interface
or by typing help at the console.
Spectre Documentation
The following command gets you to the directory with the documentation:
cd `cds_root spectre`/doc
Start with the information in folders spectreuser (simulator usage) and spectreref
(analysis statements) spectremod (instances, e.g. vsource, resistor, …).
Last modified 2/5/16 13:02
EE 240 UC Berkeley, EECS Department
Prof. B. E. Boser Page 2 of 4
Documentation for the Spectre-Matlab Toolbox is available in MatlabWorkshop.pdf. Type
cd `cds_root spectre`/tools/spectre/examples/SpectreRF_workshop
to get to the directory where the file is located.
Simulating a Circuit with Spectre
In this example we simulate a resistively loaded common-source amplifier. Use your preferred
editor (e.g. gedit) to create cs.scs, the file with the simulator input:
// NMOS Common-Source Stage
simulator lang=spectre
* device model; download from course website
include "./cmos180.scs" section tt
* save transistor bias (gm, cgs, ...); very helpful for diagnosis
save m1
* circuit model
parameters vdd=1.8
parameters vi=510m
parameters ibias=170u
vin (vi 0) vsource dc=vi mag=1
vob (vdd2 0) vsource dc=vdd/2
ib (vdd2 vo) isource dc=ibias
m1 (vo vi 0 0) nfet l=180n w=26u
rl (vdd2 vo) resistor r=1.41k
cl (vo 0) capacitor c=2.26p
* analysis
options1 options gmin=0.1p reltol=0.1m vabstol=1u iabstol=100ps
options2 options temp=27 tnom=27
options3 options save=allpub rawfmt=psfbin rawfile="./cs.raw"
dc1 dc param=vi start=0 stop=1.2 lin=101
ac1 ac start=100k stop=10G log=101
noise1 (vo 0) noise start=100k stop=1T log=101
Download the technology file (cmos180.scs in this example) from the course website and
place it in the same directory as cs.scs. Then run the simulation from the command prompt:
spectre cs.scs
Check the output for errors, warnings and notices. Address all issues, then start Matlab:
matlab &
At the matlab command prompt, type
Last modified 2/5/16 13:02
EE 240 UC Berkeley, EECS Department
Prof. B. E. Boser Page 3 of 4
vo = cds_srr('cs.raw', 'dc1-dc', 'vo')
to load the simulated dc output voltage vector. The command
cds_plotsig(vo)
produces the following figure:
To plot the ac-response type
voac = cds_srr('cs.raw', 'ac1-ac', 'vo')
cds_plotsig(voac, '', 'freq', 'db20')
set(gca, 'xscale', 'log')
The following commands plot the noise density and total noise at the output of the circuit:
out = cds_srr('cs.raw', 'noise1-noise', 'out');
von = out.V_sqrt_Hz_;
f = out.freq;
vot = sqrt(cumtrapz(f, von.^2));
subplot(2,1,1);
loglog(f, von*1e9);
ylabel('von [nV/rt-Hz]');
subplot(2,1,2);
loglog(f, vot*1e6);
ylabel('vot [uV]');
xlabel('Frequency [Hz]');
Last modified 2/5/16 13:02
EE 240 UC Berkeley, EECS Department
Prof. B. E. Boser Page 4 of 4
Last modified 2/5/16 13:02