Monday, May 30, 2011

Simple Diode Circuit

So, let's make a circuit with a diode! Now, diodes can have a bunch of characteristics when you buy them, so if you wanted to properly design a diode circuit, you'd need to know all the characteristics of the diode you bought. Also, to properly simulate, you need the same information.

So, I was interested in following the circuit simulation done in Sedra and Smith, so I googled for D1N4148, and found the following circuit model at http://www.seas.upenn.edu/~jan/spice/spice.models.html. Here is the model

.model D1N4148 D (IS=0.1PA, RS=16 CJO=2PF TT=12N BV=100 IBV=0.1PA)

I won't go over everything yet (want to keep this as concrete as possible for now), but the main take away is the the name of this model is D1N4148, as determined by the parameter right after the .model statement. You can paste this line at the beginning of your file, or you can, more nicely, put it into a separate file ("D1N4148.mod") .include statement, as shown below.


.include ~/spice_models/D1N4148.mod

vin 1 0 2.0
r1 1 2 5k
d1 2 0 D1N4148
.dc vin 0.0 1.0 .1
.plot dc v(1)
.end


Here, I have created saved the file in the directory spice_models located in my home directory.

So, launching spice we do the standard run


******
** 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: *include ~/spice_models/D1N4148.mod

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

Warning: d1: breakdown current increased to 3.86635e-10 to resolve
Warning: incompatibility with specified saturation current
Reference value : 0.00000e+00

No. of Data Rows : 11


Cool We got a warning (which I will discuss some time in future), but aside from that, everything worked. Let's plot it.

ngspice 214 ->
plot v(1), v(2)




Now we might be initially surprised by this, if we thought that v(1) was the drop across the resistor. It's not, remember it's the voltage at node 1, so it's exactly whatever the voltage of the battery is. So we see as the voltage increases, the voltage drop across the diode eventually saturates to about 1 diode drop. However, let's go actually look at the voltage drop across the resistor


ngspice 215 ->
plot v(1)-v(2), v(2)



Ah! That looks right. However, that v(1)-v(2) title looks a bit ugly. We might want to do the following

ngspice 216 -> let resistorVoltage = v(1)-v(2)
ngspice 217 -> plot resistorVoltage, v(2)



Spiffy! So, we learned a lot just now. We learned how to include additional files using .include. We learned how to create variables using let, and we learned a little about model files. Yay!


No comments:

Post a Comment