---
title: Diode lab
heading: Saturation currents, I–V fits, series resistance, C–V profiles and switching, in Python
eyebrow: S1 · Lesson 24 · Diode lab
xp: 60
---

::: hook
A diode's datasheet and its physics meet in a handful of measurements: the forward I–V curve gives the saturation current and ideality factor, its bend at high current gives the series resistance, the C–V curve gives the doping profile, and the reverse-recovery transient gives the stored charge. This lab writes the extraction tools and the forward models in Python, and checks each against synthetic data built from known parameters, the way a device-characterization engineer validates their scripts before trusting them on real wafers.
:::

::: play
- The curve is a diode's forward current on a log scale: ideal exponential at low current, bending over at high current where the series resistance takes a growing share of the voltage.
- Raise the series resistance and the bend moves down to lower currents.
- Raise the ideality factor and the straight part's slope flattens: recombination in the depletion region (n near 2) dominates at low voltage.
:::

```sim plot
view: graph
x: I = 1e-12..1 A log
y: V = 0..1.4 V
slider: n = 1..2 step 0.05 = 1.2
slider: R = 0..5 step 0.1 = 2 Ω
plot: n*0.02585*ln(I/1e-14 + 1) + I*R | label: forward voltage
```

::: predict
## A diode's n region is thinned from much longer than a hole diffusion length (34 µm) to 2 µm, with an ohmic contact at its end. How does its saturation current change?

- [ ] It falls, since there's less silicon to recombine in
- [ ] It stays the same
- [x] It rises about seventeenfold
- [ ] It rises a thousandfold

::: reveal
With a contact at $W_n$, the hole term becomes $\frac{D_p}{L_pN_d}\coth(W_n/L_p) \approx \frac{D_p}{W_nN_d}$: the gradient is steeper because the holes are pulled out at the contact, $L_p/W_n = 17$ times. Short-base diodes leak more but switch faster, since they store less charge.
:::
:::

::: nameit
## The tools

- **Saturation current:** $J_0 = qn_i^2\left(\frac{D_n}{L_nN_a} + \frac{D_p}{L_pN_d}\coth\frac{W_n}{L_p}\right)$, the coth for a contact at $W_n$ (→ 1 for a long base).
- **I–V fit:** at moderate current, $\ln I = \ln I_0 + V/(nV_T)$ is a straight line: fit it by least squares.
- **Series resistance:** at high current, $V - nV_T\ln(I/I_0) = IR_s$: a line through the origin.
- **C–V profile:** for a one-sided junction, $N = \dfrac{2}{q\varepsilon A^2\,d(1/C^2)/dV}$ at each bias.
- **Reverse recovery:** charge control gives a storage time $\tau\ln(1 + I_F/I_R)$.

Use $V_T$ = 0.02585 V, q = 1.602 × 10⁻¹⁹ C, ε = 1.036 × 10⁻¹² F/cm.
:::

::: check
kind: python

## Write `j0(Na, Nd, Dn, Ln, Dp, Lp, Wn=None, ni=1e10)`: the saturation current density (A/cm²) of a junction, with the n side long if `Wn` is None, or ending at an ohmic contact at Wn otherwise ($\coth(W_n/L_p)$ factor on the hole term).

```python starter
import math

def j0(Na, Nd, Dn, Ln, Dp, Lp, Wn=None, ni=1e10):
    return 0.0
```

```python solution
import math

Q = 1.602e-19

def j0(Na, Nd, Dn, Ln, Dp, Lp, Wn=None, ni=1e10):
    hole = Dp / (Lp * Nd)
    if Wn is not None:
        hole /= math.tanh(Wn / Lp)
    return Q * ni * ni * (Dn / (Ln * Na) + hole)
```

```python tests
a = j0(1e19, 1e16, 3.0, 1e-4, 11.3, 3.362e-3)
assert abs(a - 5.43e-12) / 5.43e-12 < 2e-3, "The p+n diode of lesson 9: about 5.4e-12 A/cm²."
b = j0(1e19, 1e16, 3.0, 1e-4, 11.3, 3.362e-3, Wn=2e-4)
assert 16 < b / a < 17.5, "A 2 µm short base: about seventeen times more."
assert abs(j0(1e19, 1e16, 3.0, 1e-4, 11.3, 3.362e-3, Wn=1.0) - a) / a < 1e-6, "A very long base matches the long-base formula."
```

::: right
Right. The heavily doped side contributes almost nothing; the light side and its length set the leakage.
:::
:::

::: check
kind: python

## Write `fit_diode(V, I)`: fit $\ln I = \ln I_0 + V/(nV_T)$ by least squares to (V, I) data and return ($I_0$, n).

```python starter
def fit_diode(V, I):
    return (1e-14, 1.0)
```

```python solution
import math

VT = 0.02585

def fit_diode(V, I):
    ys = [math.log(i) for i in I]
    m = len(V)
    mx, my = sum(V) / m, sum(ys) / m
    b = sum((x - mx) * (y - my) for x, y in zip(V, ys)) / sum((x - mx) ** 2 for x in V)
    return (math.exp(my - b * mx), 1 / (b * VT))
```

```python tests
V = [0.3 + 0.02 * k for k in range(10)]
I = [1e-14 * (math.exp(v / (1.2 * 0.02585)) - 1) for v in V]
I0, n = fit_diode(V, I)
assert abs(n - 1.2) < 1e-3 and abs(I0 - 1e-14) / 1e-14 < 1e-3, "Recovers I0 = 1e-14 A and n = 1.2."
I2 = [2e-15 * math.exp(v / 0.02585) for v in V]
assert abs(fit_diode(V, I2)[1] - 1.0) < 1e-9, "An ideal diode: n = 1."
```

::: right
Right. Fitting the log keeps every decade of current equally weighted, as it is on the plot.
:::
:::

::: check
kind: python

## Write `series_r(V, I, I0, n)`: with $I_0$ and n known from the low-current fit, find $R_s$ by least squares through the origin on $V - nV_T\ln(I/I_0) = IR_s$, using high-current (V, I) points.

```python starter
def series_r(V, I, I0, n):
    return 0.0
```

```python solution
import math

VT = 0.02585

def series_r(V, I, I0, n):
    num = sum(i * (v - n * VT * math.log(i / I0)) for v, i in zip(V, I))
    return num / sum(i * i for i in I)
```

```python tests
Is = [1e-3, 3e-3, 1e-2, 3e-2]
Vs = [1.2 * 0.02585 * math.log(i / 1e-14) + i * 2.0 for i in Is]
assert abs(series_r(Vs, Is, 1e-14, 1.2) - 2.0) < 1e-9, "Recovers 2 Ω."
Vs2 = [v + 0.001 * (k % 2) for k, v in enumerate(Vs)]
assert abs(series_r(Vs2, Is, 1e-14, 1.2) - 2.0) < 0.05, "A millivolt of noise barely moves it."
```

::: right
Right. The extra voltage above the exponential, divided by the current, is the series resistance.
:::
:::

::: check
kind: python

## Write `cv_profile(V, C, A)`: from capacitances C (F) at reverse biases V (V) of a one-sided junction of area A (cm²), return the doping $N = 2/(q\varepsilon A^2\,\Delta(1/C^2)/\Delta V)$ for each neighboring pair of points.

```python starter
def cv_profile(V, C, A):
    return []
```

```python solution
Q, ES = 1.602e-19, 1.036e-12

def cv_profile(V, C, A):
    out = []
    for k in range(len(V) - 1):
        s = (1 / C[k + 1] ** 2 - 1 / C[k] ** 2) / (V[k + 1] - V[k])
        out.append(2 / (Q * ES * A * A * s))
    return out
```

```python tests
import math
A, N, Vbi = 1e-4, 5e15, 0.8
VR = [0, 1, 2, 3, 4]
C = [A * math.sqrt(1.602e-19 * 1.036e-12 * N / (2 * (Vbi + v))) for v in VR]
prof = cv_profile(VR, C, A)
assert len(prof) == 4 and all(abs(p - N) / N < 1e-9 for p in prof), "A uniform 5e15 profile comes back flat."
C2 = [A * math.sqrt(1.602e-19 * 1.036e-12 * 2 * N / (2 * (Vbi + v))) for v in VR]
assert abs(cv_profile(VR, C2, A)[0] / N - 2) < 1e-9, "Twice the doping reads twice as high."
```

::: right
Right. Real profiles vary with depth; pairing each estimate with the depletion width $\varepsilon A/C$ turns this into a plot of doping against depth.
:::
:::

::: check
kind: python

## Write `storage_time(IF, IR, tau)`: the charge-control storage time $\tau\ln(1 + I_F/I_R)$, and `stored_charge(IF, tau)`: $I_F\tau$.

```python starter
def storage_time(IF, IR, tau):
    return tau

def stored_charge(IF, tau):
    return 0.0
```

```python solution
import math

def storage_time(IF, IR, tau):
    return tau * math.log(1 + IF / IR)

def stored_charge(IF, tau):
    return IF * tau
```

```python tests
assert abs(storage_time(10e-3, 5e-3, 1e-6) - 1.0986e-6) < 1e-10, "10 mA forward, 5 mA reverse, 1 µs: 1.10 µs."
assert abs(stored_charge(10e-3, 1e-6) - 10e-9) < 1e-15, "10 nC stored."
assert storage_time(10e-3, 50e-3, 1e-6) < storage_time(10e-3, 5e-3, 1e-6), "Pulling harder clears it faster."
```

::: right
Right. The same stored charge sets both the recovery time and the diffusion capacitance.
:::
:::

::: explain
## Why is the ideality factor fitted from moderate currents and the series resistance from high currents, rather than both from the whole curve at once?

::: model
At low and moderate currents almost all of the applied voltage appears across the junction, so the current follows the exponential law and its log is a straight line whose slope gives the ideality factor and whose intercept gives the saturation current. At high current the series resistance takes a growing share of the voltage, so the curve bends away from that line, and the size of the bend at each current gives the resistance once the junction part is known. Fitting the whole curve with one straight line would mix the two effects and distort both; fitting each in the region where it dominates separates them cleanly.
:::
:::
