# How do I model an LED with SPICE?

What diode modifiers are used in practice to model LEDs with SPICE (Berkeley v.3f5)? These are available to me:

#       Name    Parameter                    Units      Default Example  Area
1       IS      Saturation current             A         1e-14   1e-14    *
2       RS      Ohmic resistance               Ω         0       10       *
3       N       Emission coefficient           -         1       1.0
4       TT      Transit-time                   s         0       0.1ns
5       CJO     Zero-bias junction capacitance F         0       2pF      *
6       VJ      Junction potential             V         1       0.6
7       M       Grading coefficient            -         0.5     0.5
8       EG      Activation energy              eV        1.11    1.11 Si
0.69 Sbd
0.67 Ge
9       XTI     Saturation-current temperature exponent  3.0     3.0 jn
2.0 Sbd
10      KF      Flicker noise coefficient      -         0
11    AF      Flicker noise exponent         -         1
12    FC      Coeff. for for.-bias dep. cap. formula   0.5
13    BV      Reverse breakdown voltage      V         ∞       40.0
14    IBV     Current at breakdown voltage   A         1.0e-3
15    TNOM    Parameter measurement temp.    °C        27      50


3.4.2 Diode Model (D)
The dc characteristics of the diode are determined by the parameters IS and N. An ohmic resistance, RS, is included. Charge storage effects are modeled by a transit time, TT, and a nonlinear depletion layer capacitance which is determined by the parameters CJO, VJ, and M. The temperature dependence of the saturation current is defined by the parameters EG, the energy and XTI, the saturation current temperature exponent. The nominal temperature at which these parameters were measured is TNOM, which defaults to the circuit-wide value specified on the .OPTIONS control line. Reverse breakdown is modeled by an exponential increase in the reverse diode current and is determined by the parameters BV and IBV (both of which are positive numbers).

For example, using this basic, cheap red: http://www.digikey.com/Web%20Export/Common/header/digikey_logo.jpg http://www.virtualvisiontech.com/system/customcores/VVTStorefront/storefrontimages/PDF_logo.gif

I don't care much about high-frequency characteristics -- just would like to be able to match it's IV-curve within its operating specs (-10uA/-5V leakage to +100mA/+2.2'ishV forward):

As you stated, there are 3 parameters that dictate the DC response of a diode. Those are the saturation current (IS), the emission coefficient (N), and the ohmic resistance (RS). I was able to fit the curve with a fairly high accuracy, so I'll document my model procedure.

The SPICE model for the diode closely matches the Schokley diode equation:

If = IS(e^(Vf/(N*Vt)) - 1)


where Vt = kT/q = 26mV at room temperature.

1. Get actual values from the graphs provided in the datasheet to use for comparison. The more points the better, and the more accurate the better. Below is a table that I estimated from the figure you provided:

Vf  If (mA)
1.3 0.001
1.4 0.010
1.5 0.080
1.6 0.700
1.7 5.000
1.8 20.000
1.9 40.000
2.0 65.000
2.1 80.000

2. Plug the values into Excel, and change the y-axis to a log scale. You should get a graph that looks identical to the original graph from the datasheet. Add another column for your graph, with If calculated from the forward voltage and the constants IS and N. We can use this configuration to iteratively find IS and N.

3. Solve for IS and N. We are trying to match the linear part of the graph (1.3 <= Vf <= 1.7). Adjusting IS will move the curve in the y-axis. Get the calculated graph to the same order of magnitude. The next step is to find the emission coefficient (N). N affects both the amplitude and the slope, so some adjustment of IS may be necessary to keep the curve in the same ballpark. Once the slopes match (the lines are parallel), trim IS so that the calculated data matches the datasheet values. I got IS = 1e-18, and N=1.8 for the diode you listed.

4. Identify RS. This is a bit tricky. RS is responsible for the curving of the current from 1.7V and above. Consider modeling the ohmic resistance as a resistor in series with the diode. As the current through the diode increases, the voltage drop across the ohmic resistance causes the forward diode voltage Vf to increase slower. At small currents, this effect is negligible.

The first thing to do is to get a ballpark estimate of RS to use in the more accurate solutions. You can calculate the effective value of RS from the datasheet values by back-calculating for Vf using the measured If. The voltage difference between the input value and the calculated Vf can be used with the forward current to generate a resistance. At the higher currents, this will be a good starting value.

To plot the diode current using RS, you need to first calculate the diode Vf given a voltage for the resistor-diode series combination. Wikipedia lists an iterative function - it converges easily if the resistor voltage drop is significant. This function was easy enough to set up in Excel. For Vf values below 1.8, I hard-coded the input value because the iterative function did not converge. Then take this Vf value to calculate the If of the ideal diode. I plotted this with the original datasheet graph.

Using trial and error, you should be able to get a RS value that gets pretty good overlap with the datasheet values. All that's left is to throw the model together in SPICE to verify your work.

Below is my diode model that I verified using HSPICE. The simulation data is almost a perfect overlay for the datasheet graph.

.model Dled_test D (IS=1a RS=3.3 N=1.8)


I used this article, which helped a lot with the diode spice parameters.

• This is an awesome answer. +∞ – tyblu Jan 31 '11 at 2:37

First, I would point out that you can read additional diode parameters BV, Ibv and Cjo directly from the LED datasheet as "Reverse Current" Ir at Vr and as "Capacitance" C.

Adding to W5VO's great answer, I somewhat streamlined the process for myself the following way:

1. I used the chart type of XY scatter plot as lines only on OpenOffice (YMMV with Excel, etc.) and set the minima and maxima of the axes manually, e.g. (X,Y)=(1.4-4.0, 0.01-50.0), to pervent it from autoranging to outside the scope of my sampled data.

2. After the first three columns of sampled points Vf_sampled, If_sampled as well as the If_estimate using the Schokley diode equation, I added a fourth one for a calculated Vf_estimate. Remember, that Rs is a series resistance (see image at the bottom) and the If_estimate actually gives us the current to use here, so one can simply calculate the column cells as:
Vf_estimate = Vf_sampled + (If_estimate * Rs).

3. I could now add a third curve, in which I used the new fourth column (Vf_estimate) as the X coordinate and the third column (If_estimate) as the Y coordinate, and which I could now easily match against the first curve (the data sampled from the graph on the datasheet). Note that I didn't want to simply replace the second curve since the straight line was quite helpful in my estimates.

4. I'm sure I'm somewhat repeating W5VO here, but it bares reminding of the role of the constants Is, Rs and N in terms of the curve shape (in our log-lin scale):

• Is only affects the position of the curves (up/left or down/right).
• N affects the curve slopes as well as the positions (since it's a linear coefficient and the curves always go through the origin, which is always outside the scale).
• Rs defines the curvature (the progressive rightward sweep) of the new third curve (since it's a linear term in the other direction).
5. Things I found that may be of use:

• You may find that the second curve (the straight line) needs to be very slightly steeper and to the up/left than it would seem from the sampled data, because the curvature due to Rs starts at the origin.
• You can get fairly accurate sampling by zooming in to the datasheet (assuming PDF), taking a screencap and opening it in your favourite drawing program. You can then use e.g. the selection or straight-line tool to measure the distance in pixels between the interval lines and the distance of the point to the lower-value interval line. For linear axes, that fraction translates to easy data values.
• XY scatter plot allows you to use arbitrary points of data. You can get away with less samples than with equidistant sampling. You can choose to only sample the data at the points where it is easiest and where strictly needed. For example, on a semilog scale you can sample at the interval lines of the logarithmic scale. If you need to, you can still have more points (rows) for the estimated curves. (At least OpenOffice charts seem to ignore the points for which there is no corresponding Y-coordinate.)
Note that the X values (Vf_sampled) still need to be in ascending (or descending) order. Otherwise the lines become a mess.
• Note the scale of the units you are estimating/charting/trying to find (e.g. milliamperes) and remember that SPICE generally uses the bare units (amperes).
• Note that W5VO's Vt is in millivolts. If you're using volts, use the value 0.026.
• Check which metric prefixes (m, p, u, etc.) your SPICE simulator accepts. Using the exponent notation (e.g. 12E-34) may be simpler.
• Editing the cell range for the chart seemed to always reset the (new) third curve so that I had to re-add the data range to X-coordinates and re-change the third column as its Y range. Take that into consideration when adding more points or modeling multiple LEDs on the same chart - make such changes all at once. (Changing the data within the cells obviously didn't trigger the reset.)
• Curved interpolation on the chart may lead you astray by overshooting or undershooting and not showing you why i.e. where the actual points of data are.
• Straight line segments may also mislead, since the corresponding points end up in different locations and the linear interpolation doesn't track the logarithmic nature of the curve. (All the points of data of the sampled curve and the new third curve should be outside (up/left) of the straight line segments of the other.)

AFAIK, our model for the LED is essentially an Rs resistor and Is/N estimate diode in series: (-R->-D-)

simulate this circuit – Schematic created using CircuitLab

I have put together a Python program that will model the forward bias characteristics of a diode based on datasheet I-V characteristics.

http://leicesterraspberrypi.wordpress.com/projects/modelling-a-diode-for-use-in-spice-simulations/

Feel free to give it a try and comment.

• While your code looks very useful link-only answers are discouraged because they can become useless in the future if the link dies. Perhaps you could include more details on the algorithm / code in your answer to ensure it continues to be useful if that ever happens. – PeterJ Feb 17 '14 at 12:32
• This is quite useful, in fact. Using WebPlotDigitizer made this quite easy. – andy.holmes Nov 18 '16 at 6:47

Here are the ones I would use

#       Name    Parameter                    Units      Default Example  Area
2       RS      Ohmic resistance               Ω         0       10       *
6       VJ      Junction potential             V         1       0.6
13    BV      Reverse breakdown voltage      V         ∞       40.0
14    IBV     Current at breakdown voltage   A         1.0e-3


For your VJ=1.8 typ, BV=5. That gets you most of the way there.

• Actually, VJ is used to calculate the junction capacitance based on the applied voltage. Modifying this and the reverse breakdown voltage won't really set the gross DC characteristics. The final result should be almost identical to the default diode model. – W5VO Jan 30 '11 at 14:52

If anyone is wondering why his/her single-page datasheet doesn't have an If/Vf curve, it's probably because he/she doesn't have the complete datasheet. I know that e.g. Optosupply only publishes the first-page summaries on their website, but they'll send you the full specs (with all the If/Vf, relative intensity and spectrum curves, etc.) on request.

You can also probably get usable figures for all the values by using a datasheet from another LED of same colour with the same chemistry (by the same manufacturer). Just check that the basic characteristics (like currents, voltages and wavelengths) match.

Great answers, but it is easy to solve the Shockley diode equation algebraicly. Just note that the "minus 1" in the formula is very irrelevant for forward currents that are an order of magnitude greater than Is, which is very small, say, 1E-12 A. Find just two points in the graph with easy to read I and V values, and plug these into the formula. Dividing both formula's eliminates Is, so N is easy to compute. Then fill in N in a formula to find Is.

Here are my LibreOffice Calc macro's in Basic:

Const Q as double = 1.6E-19
Const K as double = 1.38E-22
Const T as double = 300

rem The Shockley diode equation, to build the graph Id(Vd) for hardcoded values of Is and N
Function shockley(Vd as double) as double
Const Is1 as double = 5.94463E-18
rem Note that 'Is' is a reserved word and cannot be the name of a variable
Const N as double = 0.191367
shockley = Is1 * (exp(Vd * Q / (N * K * T )) - 1)
End Function

rem Step 1 in solving the diode equation for N using values from a graph
Function ComputeN(V1 as double, V2 as double, I1 as double, I2 as double) as double
ComputeN = (Q / (K * T)) * (V1 - V2) / (log(I1) - log(I2))
End Function

rem Step 2 in solving the diode equation for Is
Function ComputeIS(V as double, I as double, N as double) as double
ComputeIS = I / (exp(Q * V / (N * K * T)))
End Function

rem for debugging
sub Test
dim N as double
N = ComputeN(1.85, 1.3, 0.1, 1.5E-6)
dim Is1 as double
Is1 = ComputeIs(1.85, 0.1, N)
end sub


If you look at the formula's, you might recognize simply the description of a straight line with slope of q/NkT but also of delta Log(Id) / delta Vd.

I get a somewhat similar value for Is: 5.94E-18 = 5.94 atto-ampere (W5VO found 1 aA), but much different N = 0.19 (W5VO found 1.8, typo?), still the data also computes back to the same graph:

The column Vd are the voltages, Id is the diode current according to the real formula, Id0 is the current with the simplified formula where the "minus 1" is changed to "minus zero". As Id0 is a true exponential curve, you can take the logaritm in column Id0_log. (You cannot take the log of a curve that becomes zero and negative like Id) The plot is from Id0_Log versus Vd. In this plot I made the lowest part dotted, because there it is NOT the actual diode current anymore, but does show the value of Is at the intersection with the Y-axis.

Following the exponential curve to the left brings you asymptotally to zero. But the "minus 1" subtracts an amount of Is, so that the real diode curve goes through the origin and, with negative voltages, shows a reverse leakage current of amount Is.

If the original manufacturers curve would have been on a really large log plot, we could have simply used a ruler to extend the straight line downwards to easily find Is at Vd=0 and then compute N, instead of compute first N then Is with the above macro's. The ruler method has been described in "The Spice Book" by Andrei Vladimirescu (1994).