---
title: Diode characterization lab
heading: Extracting a diode's parameters from measurements, in Python
eyebrow: C5 · Lesson 6 · Diode characterization lab
xp: 50
---

::: hook
Datasheets give a diode's typical curve; a design that depends on the real part, such as a temperature sensor, a varactor tuner or a solar charger, starts by measuring it. Measured points don't come labeled with $I_S$ and n: you fit them. In this lab you'll write the fits a characterization engineer uses: the exponential law on a semilog plot, the series resistance that bends it at high current, the temperature slope, the capacitance law, and a solar cell's maximum power point.

::: play
- The line is a diode's voltage against the logarithm of its current. Without series resistance it's straight: $nV_T\ln10$ per decade.
- Raise the series resistance. The top of the line bends upward, where $IR$ adds to the junction's voltage.
- Change n and $I_S$. Which one changes the slope, and which one shifts the line?
:::
:::

```sim plot
view: graph
x: i = 1n..1 log A
y: v = 0.2..1.4 V
slider: n = 1..2 step 0.05 = 1
slider: s = 1e-16..1e-10 = 1e-14 A log
slider: R = 0..2 step 0.05 = 0.5 Ω
plot: n*0.02585*ln(i/s) + i*R | label: diode voltage | samples: 400
plot: n*0.02585*ln(i/s) | color: ch2 | label: junction alone | samples: 200
readout: slope per decade, mV = n*0.02585*ln(10)*1000 | digits: 3
readout: series drop at 100 mA, mV = 0.1*R*1000 | digits: 3
```

::: predict
## A diode with 0.5 Ω of series resistance carries 100 mA. How much higher is its voltage than the exponential law alone predicts?

- [ ] About 5 mV
- [x] About 50 mV
- [ ] About 0.5 V
- [ ] None: series resistance only matters in reverse

::: reveal
50 mV: the resistor drops $IR$ = 0.1 A × 0.5 Ω. At 1 mA the same resistor drops only 0.5 mV, invisible next to the junction's 60 mV per decade, so low-current points fix $I_S$ and n, and high-current points fix R.
:::
:::

::: nameit
## Fitting the exponential

Well above $I_S$, $\ln I = \ln I_S + \frac{V}{nV_T}$ is a straight line in V. A least-squares line through $(V_k, \ln I_k)$ gives the slope $\frac{1}{nV_T}$ and the intercept $\ln I_S$. Fit only points where the series resistance is negligible, typically below a milliamp for a small diode.

## Series resistance

With the junction known, each high-current point gives

$$R_k = \frac{V_k - nV_T\ln(I_k/I_S)}{I_k},$$

and a least-squares fit of the excess voltage against current, through the origin, combines them: $R = \frac{\sum I_k\Delta V_k}{\sum I_k^2}$.

## Temperature slope

At a fixed current, lesson 4's result is

$$\frac{dV}{dT} = \frac{V - E_g/q - 3V_T}{T},$$

with $E_g$ = 1.12 eV for silicon and $V_T$ evaluated at T.

## Capacitance

$C_j = \frac{C_{j0}}{(1 + V_R/V_0)^m}$ becomes linear in logarithms: $\ln C_j = \ln C_{j0} - m\ln(1 + V_R/V_0)$. With $V_0$ known (or swept to find the best fit), a line through the points gives m, ½ for an abrupt junction and ⅓ for a linearly graded one.

## Maximum power point

A solar cell's power, $P = V\left(I_{ph} - I_S(e^{V/V_T} - 1)\right)$, peaks where $\frac{dP}{dV}$ = 0. The derivative falls steadily with V, so bisection on its sign finds the peak.
:::

::: example
## Five points measured on a small diode at 300 K, from 0.40 V to 0.60 V in 50 mV steps, have currents rising by a factor of 6.3 per step. What are n and $I_S$, if the 0.50 V point carries 31.5 µA?

::: solution
1. **Slope from the ratio.** A factor of 6.3 per 50 mV means
   $$\begin{aligned} \frac{0.05}{nV_T} &= \ln 6.3 \\ &= 1.84 \end{aligned}$$
2. **Ideality factor.**
   $$\begin{aligned} nV_T &= 27.17\ \text{mV} \\ n &= 1.05 \end{aligned}$$
3. **Saturation current.** Use the 0.50 V point:
   $$\begin{aligned} I_S &= \frac{31.5\ \mu\text{A}}{e^{0.5/0.02717}} \\ &= 3.2 \times 10^{-13}\ \text{A} \end{aligned}$$
4. **Why five points help.** With five points instead of two, the least-squares line averages out measurement noise; with points that disagree, its residuals show which ones are suspect.

**Answer:** n = 1.05 and $I_S = 3.2 \times 10^{-13}$ A.
:::
:::

::: example
## The same diode reads 0.774 V at 100 mA, where the fitted law predicts 0.724 V. What's its series resistance, and what will it read at 300 mA?

::: solution
1. **Series resistance.** The excess is 50 mV at 100 mA, so
   $$\begin{aligned} R &= \frac{0.05\ \text{V}}{0.1\ \text{A}} \\ &= 0.5\ \Omega \end{aligned}$$
2. **Junction voltage at 300 mA.**
   $$\begin{aligned} V_j &= 0.724 + 0.0272\ln 3 \\ &= 0.754\ \text{V} \end{aligned}$$
3. **Add the resistor's drop.** The resistance adds 0.15 V:
   $$0.754 + 0.15 = 0.904\ \text{V}$$
4. **Why R matters.** A model without R would predict 0.754 V and be 150 mV low, which matters for a rectifier's loss and a sensor's calibration.

**Answer:** the series resistance is 0.5 Ω, and the diode will read 0.904 V at 300 mA.
:::
:::

::: example
## A small solar cell has $I_{ph}$ = 30 mA and $I_S = 10^{-10}$ A. Find its maximum power point by bisection on $\frac{dP}{dV}$.

::: solution
1. **Differentiate the power.**
   $$\begin{aligned} \frac{dP}{dV} &= I_{ph} - I_S(e^{V/V_T} - 1) \\ &\quad - \frac{V}{V_T}I_Se^{V/V_T} \end{aligned}$$
2. **Bracket the root.** At 0.3 V it's positive and at 0.5 V negative.
3. **Bisect.** Halving the interval 50 times pins the root at 0.4304 V, where the cell gives 28.30 mA:
   $$P = 12.18\ \text{mW}$$
   a fill factor of 0.805.
4. **Compare with stepping.** Lesson 4 found the same point by stepping V; bisection gets there in a fraction of the evaluations, which matters in a charger's firmware.

**Answer:** the maximum power point is at 0.4304 V and 28.30 mA, giving 12.18 mW and a fill factor of 0.805.
:::
:::

::: check
kind: python

## Step 1. Write `fit_diode(V, I, VT=0.02585)` returning `(IS, n)` from a least-squares line through $(V_k, \ln I_k)$.

```python starter
import numpy as np

def fit_diode(V, I, VT=0.02585):
    return 1e-14, 1.0

V = np.linspace(0.4, 0.6, 5)
print(fit_diode(V, 2e-14 * np.exp(V / (1.05 * 0.02585))))
```

```python solution
import numpy as np

def fit_diode(V, I, VT=0.02585):
    slope, icpt = np.polyfit(np.asarray(V, float), np.log(np.asarray(I, float)), 1)
    return float(np.exp(icpt)), float(1 / (slope * VT))

V = np.linspace(0.4, 0.6, 5)
print(fit_diode(V, 2e-14 * np.exp(V / (1.05 * 0.02585))))
```

```python tests
import numpy as np
V = np.linspace(0.4, 0.6, 5)
IS, n = fit_diode(V, 2e-14 * np.exp(V / (1.05 * 0.02585)))
assert abs(IS / 2e-14 - 1) < 1e-6 and abs(n - 1.05) < 1e-9, f"Exact data must give back IS = 2e-14 A and n = 1.05; got {IS}, {n}"
rng = np.random.default_rng(1)
I = 5e-15 * np.exp(np.linspace(0.35, 0.65, 13) / (1.2 * 0.02585)) * (1 + 0.01 * rng.standard_normal(13))
IS2, n2 = fit_diode(np.linspace(0.35, 0.65, 13), I)
assert abs(n2 - 1.2) < 0.01 and 0.8 < IS2 / 5e-15 < 1.25, f"1% noise should still give n near 1.2; got {n2}, {IS2}"
```

::: right
Right. On a logarithmic current axis the exponential is a line, and least squares does the rest.
:::
:::

::: check
kind: python

## Step 2. Write `series_resistance(V, I, IS, n, VT=0.02585)` returning R from the excess voltages $V_k - nV_T\ln(I_k/I_S)$ by least squares through the origin.

```python starter
import numpy as np

def series_resistance(V, I, IS, n, VT=0.02585):
    return 0.0

I = np.array([0.01, 0.03, 0.1, 0.3])
print(series_resistance(1.05 * 0.02585 * np.log(I / 3e-13) + 0.5 * I, I, 3e-13, 1.05))
```

```python solution
import numpy as np

def series_resistance(V, I, IS, n, VT=0.02585):
    V = np.asarray(V, float); I = np.asarray(I, float)
    dv = V - n * VT * np.log(I / IS)
    return float(np.sum(I * dv) / np.sum(I * I))

I = np.array([0.01, 0.03, 0.1, 0.3])
print(series_resistance(1.05 * 0.02585 * np.log(I / 3e-13) + 0.5 * I, I, 3e-13, 1.05))
```

```python tests
import numpy as np
I = np.array([0.01, 0.03, 0.1, 0.3])
V = 1.05 * 0.02585 * np.log(I / 3e-13) + 0.5 * I
R = series_resistance(V, I, 3e-13, 1.05)
assert abs(R - 0.5) < 1e-9, f"Expected 0.5 Ω; got {R}"
assert abs(series_resistance(V + 0.002 * np.array([1, -1, 1, -1]), I, 3e-13, 1.05) - 0.5) < 0.02, "A few millivolts of noise should move R only slightly."
```

::: right
Right. Weighting by current lets the high-current points, where R matters, dominate.
:::
:::

::: check
kind: python

## Step 3. Write `dvdt(V, T, Eg=1.12)` returning a silicon diode's voltage slope in volts per kelvin at a fixed current, with $V_T = \frac{kT}{q}$ = 8.617e-5 × T.

```python starter
def dvdt(V, T, Eg=1.12):
    return -0.002

print(dvdt(0.655, 300))
```

```python solution
def dvdt(V, T, Eg=1.12):
    VT = 8.617e-5 * T
    return (V - Eg - 3 * VT) / T

print(dvdt(0.655, 300))
```

```python tests
assert abs(dvdt(0.655, 300) + 1.8085e-3) < 1e-7, f"Lesson 4's thermometer: −1.81 mV/K; got {dvdt(0.655, 300)}"
assert dvdt(0.5, 300) < dvdt(0.7, 300), "A diode at lower current (lower V) drifts faster."
```

::: right
Right. The slope depends on the operating point, which is why a sensor is calibrated at the current it will run at.
:::
:::

::: check
kind: python

## Step 4. Write `cv_fit(VR, C, V0)` returning `(Cj0, m)` from a least-squares line through $(\ln(1 + V_R/V_0), \ln C)$.

```python starter
import numpy as np

def cv_fit(VR, C, V0):
    return float(C[0]), 0.5

VR = np.array([0.0, 1, 2, 5, 10])
print(cv_fit(VR, 10 / np.sqrt(1 + VR / 0.7), 0.7))
```

```python solution
import numpy as np

def cv_fit(VR, C, V0):
    x = np.log(1 + np.asarray(VR, float) / V0)
    slope, icpt = np.polyfit(x, np.log(np.asarray(C, float)), 1)
    return float(np.exp(icpt)), float(-slope)

VR = np.array([0.0, 1, 2, 5, 10])
print(cv_fit(VR, 10 / np.sqrt(1 + VR / 0.7), 0.7))
```

```python tests
import numpy as np
VR = np.array([0.0, 1, 2, 5, 10])
c0, m = cv_fit(VR, 10 / np.sqrt(1 + VR / 0.7), 0.7)
assert abs(c0 - 10) < 1e-9 and abs(m - 0.5) < 1e-12, f"Abrupt: 10 pF and m = 0.5; got {c0}, {m}"
c1, m1 = cv_fit(VR + 0.5, 4.7 / (1 + (VR + 0.5) / 0.6) ** (1 / 3), 0.6)
assert abs(c1 - 4.7) < 1e-9 and abs(m1 - 1 / 3) < 1e-12, f"Graded: m = 1/3; got {m1}"
```

::: right
Right. The exponent tells you how the junction was doped without cutting it open.
:::
:::

::: check
kind: python

## Step 5. Write `solar_mpp(Iph, IS, VT=0.02585)` returning `(Vmp, Imp, Pmp)` by bisection on the sign of $\frac{dP}{dV}$ between 0 and the open-circuit voltage.

```python starter
import math

def solar_mpp(Iph, IS, VT=0.02585):
    V = 0.4
    I = Iph - IS * (math.exp(V / VT) - 1)
    return V, I, V * I

print(solar_mpp(0.03, 1e-10))
```

```python solution
import math

def solar_mpp(Iph, IS, VT=0.02585):
    def dP(V):
        e = IS * math.exp(V / VT)
        return Iph - (e - IS) - V * e / VT
    lo, hi = 0.0, VT * math.log(Iph / IS + 1)
    for _ in range(100):
        mid = (lo + hi) / 2
        if dP(mid) > 0:
            lo = mid
        else:
            hi = mid
    V = (lo + hi) / 2
    I = Iph - IS * (math.exp(V / VT) - 1)
    return V, I, V * I

print(solar_mpp(0.03, 1e-10))
```

```python tests
V, I, P = solar_mpp(0.03, 1e-10)
assert abs(V - 0.430367) < 2e-6 and abs(P - 12.17946e-3) < 1e-7, f"Expected 0.4304 V and 12.18 mW; got {V}, {P}"
V2, I2, P2 = solar_mpp(0.5, 1e-9)
assert abs(V2 - 0.442873) < 2e-6 and abs(P2 - 0.209224) < 1e-6, f"A larger cell: 0.4429 V and 0.2092 W; got {V2}, {P2}"
```

::: right
Right. Bisection needs only the sign of the derivative, so it can't overshoot or diverge.
:::
:::

::: check
kind: parts
given: r = 4 | 6.3 | 10; d = 40 | 50 | 60

## A diode's current rises by a factor of {r} for every {d} mV at 300 K.

::: part
answer: d/1000/ln(r)/0.02585
tolerance: 0.5%

### What's its ideality factor?

::: misses
- [d/1000/log(r)/0.02585] The law uses the natural logarithm.
- [any] $n = \frac{\Delta V}{V_T\ln r}$.
:::
:::

::: part
answer: d/1000/ln(r)*ln(10)*1000
unit: mV
tolerance: 0.5%

### How many millivolts per decade of current?

::: misses
- [any] $nV_T\ln10$.
:::
:::
:::

::: check
given: dV = 20 | 50 | 120; I = 30 | 100 | 400
answer: dV/I
unit: Ω
tolerance: 0.5%

## At {I} mA a diode reads {dV} mV above its fitted exponential law. What's its series resistance?

::: right
Right. $R = \frac{\Delta V}{I}$ = {answer}.
:::

::: misses
- [any] The excess voltage over the current.
:::
:::

::: explain
## Why do you fit a diode's exponential law using only its low-current points?

::: model
At low current the series resistance drops almost nothing, so the measured voltage is the junction's voltage alone, and the points fall on a straight line on a semilog plot whose slope gives the ideality factor and whose intercept gives the saturation current. At high current the resistance adds a drop proportional to the current, which bends the line upward; including those points would tilt the fit and give a wrong n and $I_S$. Once the junction is fitted from clean points, the high-current points' excess over the fitted line gives the series resistance cleanly.
:::
:::

::: practice

::: check
given: r = 5 | 8; d = 45 | 70
answer: d/1000/ln(r)/0.02585
tolerance: 0.5%

## ×{r} per {d} mV at 300 K. Ideality factor?

::: misses
- [any] $\frac{\Delta V}{V_T\ln r}$.
:::
:::

::: check
given: dV = 15 | 90; I = 50 | 250
answer: dV/I
unit: Ω
tolerance: 0.5%

## {dV} mV excess at {I} mA. Series resistance?

::: misses
- [any] $\frac{\Delta V}{I}$.
:::
:::
:::
