Tuesday, April 12, 2011

RC Circuit

So, let's go create an RC circuit

RC Circuit
vin 1 0 1.0
r1 1 2 1MEG
c1 2 0 1uF
.ic V(1)=0 V(2)=0
.tran .001s 5s
.end

running in ngspice and plotting (plot v(1),v(2))we get



The new lines of note are the .ic and the .tran. .ic sets the initial conditions of all nodes. .tran sets the time step, and total time for the transient analysis. If you have both .dc and .tran in a single file, the last one is what will show up in an interpreter. If you do a batch run of course, both will be put into the result file.

Monday, April 11, 2011

Voltage Divider

So! Let's get started with a simple voltage divider. We have two resistors R1, and R2. We will hook them in series and attach across them some sort of battery. We will then attach a probe between them, and if luck holds out, this should give us a voltage drop of

R1/(R1+R2)

Lets see if this works.

So create a folder, and create a new text file (using vim in my case)

$ vim voltage_divider.spice

and enter the following spice language code into it

Voltage Divider
vin 1 0 1.0
r1 1 2 5K
r2 2 0 5K
.dc vin 0.0 1.0 .1
.plot dc v(1)
.end


Now, let's run spice

$ ngspice voltage_divider
******
** ngspice-19 : Circuit level simulation program
** The U. C. Berkeley CAD Group
** Copyright 1985-1994, Regents of the University of California.
** Please submit bug-reports to: ngspice-bugs@lists.sourceforge.net
** Creation Date: Tue Feb 16 12:47:30 PST 2010
******

Circuit: voltage divider

ngspice 118 -> run
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 0.00000e+00

No. of Data Rows : 11

ngspice 119 ->


So we've loaded the file, and we ran the analysis in it (the lines beginning with the '.'). We note that we don't see any graphs. However, if we type

ngspice 119 -> plot V(1),V(2)

We get the following plot


Huzzah! The red line is the voltage across both resistors (Node 1), and the blue is the voltage across the second only (Node 2). We see that the blue line has half the slope of the red as expected.

If you're interested in measuring the voltage only across the first resistor rather than both, you can use

plot v(1)-v(2),v(1)

Learning Spice

Learning Spice is a webblog whose purpose is for me to learn the Spice Circuit Simulation Language. It is also intended to help people discover what pitfalls one might encounter when attempting to perform simple tasks.