# Adding Diode Model to gschem

I'm looking to use the D1N914 diode in a netlist for use with ngspice. Thankfully I've found the model for free here: http://ppd.fnal.gov/experiments/cdms/old_files/electronics/FLIP/3U/QampDiscrete/proto/schematics_layouts/DIODE.LIB

Problem is, I don't know how I can add such a model to work with gschem or even ngspice. I'm wondering if anyone is familiar as how to use models in ngspice or SPICE in general.

The circuit I'm describing is a just a voltage source connected to a D1N914 (anode to positive, cathode to negative). Nothing special, I'm just doing a small DC analysis.

## 2 Answers

On the ngspice side of things, you need to include the model in your circuit, using one of various commands.
The simplest is to put the .model into your netlist, and use the name to refer to it, e.g. your model looks like this:

.model D1N914 D(Is=168.1E-21 N=1 Rs=.1 Ikf=0 Xti=3 Eg=1.11 Cjo=4p M=.3333 + Vj=.75 Fc=.5 Isr=100p Nr=2 Bv=100 Ibv=100u Tt=11.54n)

Note ngspice seems to have a problem with a couple of parameters in this model (Isr and Nr), so the simulation may be unrealistic as I removed them just to get things working.
It appears to be a psice model, and (according to LTSpice):
Isr = Recombination current parameter Nr = Isr emission coefficient.
I don't think they will have much effect on the simulation, likely high order Is effects added into the commercial spices.

So here is an example netlist (with Isr and Nr removed, see above):

V1 1 0 5
R1 1 2 1k
D1 2 3 D1N914
Vdummy 3 0 0

.model D1N914 D(Is=168.1E-21 N=1 Rs=.1 Ikf=0 Xti=3 Eg=1.11 Cjo=4p M=.3333 + Vj=.75 Fc=.5 Bv=100 Ibv=100u Tt=11.54n)

*.option noacct .dc V1 0 10 1

*.print i(Vdummy)

.end

If we type plot i(Vdummy), we get this:

The second option would be to do something like add it to a modelcard and do .include\xxxx\xxx\modelcard.diode into your netlist. I have not tested this option though, only the first which works fine. I imagine there is some way of linking the modelcard to the symbol Matt describes in his answer (in LTspice you add the file as one of the symbol parameters)

• You have been extremely helpful, however it become apparent that ngspice is not the way to go. I do have access to Orcad PSPICE, so I'll make it easy on myself. Thanks. Aug 30 '11 at 2:53

I can't help with the ngspice side of things, unfortunately, but adding a new symbol to gEDA gschem is a doddle.

A .sym file will have to be created for your specific component. This is no different to a schematic file, just named "component.sym" instead of .sch.

Just draw the component using the lines, boxes and arcs at your disposal in gschem. Add pins (ap) and number them 1 and 2 (etc, depending on the number of pins you have). Maybe name them by their function as well.

Then you add 2 special attributes - the "refdes" - One or more letters followed by a question-mark - in your case I guess that'll be D? for diode number X. Also you need a "device" attribute which contains the name of the device - D1N914 in your case. These attributes are attached to the whole page, not any one individual object within the drawing.

Then you need to do a "Symbol Translate" - I think it's in the "Edit" menu. Translate it to the default of 0,0.

You can now save your new symbol. You'll have to place it somewhere gEDA can find it again. I have a local "gEDA/symbols" folder which I use. You can add whatever locations you like by editing ~/.gEDA/gafrc and adding lines like:

(component-library "/home/sidney/gEDA/symbols" "My Symbols")


I would imagine you'd have to do something similar with ngspice to tell it where to find extra library files. Not having used it I can't really say.