---
title: Carrier lab
heading: Neutrality, resistivity, Hall and Haynes–Shockley data, and diffusion profiles, in Python
eyebrow: S1 · Lesson 6 · Carrier lab
xp: 60
---

::: hook
The first four lessons gave formulas for carriers at rest and in motion. A device engineer uses them the other way around as often as forward: a wafer's resistivity is specified, so what doping is it? A Hall bar gives a voltage, so what are the density and mobility? A pulse arrives late and spread out, so what are μ and D, and do they obey Einstein? This lab writes those calculations as small Python tools and checks them against the numbers in the lessons.
:::

::: play
- The curve is silicon's resistivity against donor density, from the mobility fit $\mu_n = 92 + 1268/(1 + (N/1.3 \times 10^{17})^{0.91})$, on log axes.
- It's nearly a straight line with slope −1, bending where the mobility starts to fall at high doping.
- Lab task 2 inverts this curve: given a resistivity, find the doping by bisection.
:::

```sim plot
view: graph
x: N = 1e13..1e20 cm⁻³ log
y: r = 0.0001..1000 Ω·cm log
plot: 1/(1.602e-19*N*(92 + 1268/(1 + (N/1.3e17)^0.91))) | label: n-type resistivity
```

::: predict
## A wafer is specified at 1 Ω·cm, n-type. Roughly what donor density is that?

- [ ] About $10^{13}$ cm⁻³
- [x] About $5 \times 10^{15}$ cm⁻³
- [ ] About $10^{17}$ cm⁻³
- [ ] About $10^{19}$ cm⁻³

::: reveal
$1/(q\mu\rho)$ with μ ≈ 1300 gives $4.8 \times 10^{15}$ cm⁻³, which the lab's bisection confirms. Wafer vendors quote resistivity because it's what a four-point probe measures; the doping follows from curves like this one.
:::
:::

::: nameit
## The tools

| Task | From | To |
|---|---|---|
| Neutrality | $N_d$, $N_a$, $n_i$ | n and p, exactly, including near-intrinsic wafers |
| Resistivity | doping | ρ, and back again by bisection |
| Hall | $V_H$, I, B, thickness, ρ | carrier density and Hall mobility |
| Haynes–Shockley | distance, field, arrival time, time spread | μ, D, and the Einstein ratio D/μ |
| Diffusion | surface concentration or dose, D, t, background | junction depth |

Use $q = 1.602 \times 10^{-19}$ C and $n_i = 10^{10}$ cm⁻³ throughout.
:::

::: check
kind: python

## Write `carriers(Nd, Na, ni=1e10)`: the exact equilibrium (n, p) from charge neutrality $n + N_a = p + N_d$ and $np = n_i^2$. Solve the quadratic in a form that doesn't lose precision when one carrier is tiny.

```python starter
import math

def carriers(Nd, Na, ni=1e10):
    return (Nd - Na, ni * ni / (Nd - Na))
```

```python solution
import math

def carriers(Nd, Na, ni=1e10):
    d = (Nd - Na) / 2
    if d >= 0:
        n = d + math.sqrt(d * d + ni * ni)
        return (n, ni * ni / n)
    p = -d + math.sqrt(d * d + ni * ni)
    return (ni * ni / p, p)
```

```python tests
n, p = carriers(1e16, 0)
assert abs(n - 1e16) / 1e16 < 1e-9 and abs(p - 1e4) / 1e4 < 1e-6, "1e16 donors: n = 1e16, p = 1e4."
n, p = carriers(3e16, 1e16)
assert abs(n - 2e16) / 2e16 < 1e-9, "Compensated: n = Nd − Na."
n, p = carriers(1e10, 0)
assert abs(n - 1.618e10) / 1.618e10 < 1e-3, "Doping equal to ni: n = 1.618 ni (the golden ratio)."
n, p = carriers(0, 1e15)
assert abs(p - 1e15) / 1e15 < 1e-9 and abs(n - 1e5) / 1e5 < 1e-6, "p-type works too."
```

::: right
Right. Choosing the large root first and dividing for the small one avoids subtracting nearly equal numbers.
:::
:::

::: check
kind: python

## Write `rho_n(N)`: the resistivity of n-type silicon from the mobility fit, and `doping_for(rho)`: the donor density giving that resistivity, by bisection in log N between $10^{12}$ and $10^{20}$.

```python starter
def rho_n(N):
    return 1.0

def doping_for(rho):
    return 1e15
```

```python solution
import math

Q = 1.602e-19

def mu_n(N):
    return 92 + 1268 / (1 + (N / 1.3e17) ** 0.91)

def rho_n(N):
    return 1 / (Q * N * mu_n(N))

def doping_for(rho):
    lo, hi = 1e12, 1e20
    for _ in range(200):
        mid = math.sqrt(lo * hi)
        if rho_n(mid) > rho:
            lo = mid
        else:
            hi = mid
    return mid
```

```python tests
assert abs(rho_n(1e16) - 0.500) < 0.001, "1e16 donors: 0.50 Ω·cm, as in lesson 2."
N = doping_for(1.0)
assert abs(N - 4.80e15) / 4.80e15 < 2e-3, "1 Ω·cm: about 4.8e15 donors."
assert abs(rho_n(N) - 1.0) < 1e-9, "Round trip."
assert abs(doping_for(0.01) - 4.42e18) / 4.42e18 < 5e-3, "0.01 Ω·cm: 4.4e18, where mobility has fallen."
```

::: right
Right. Bisecting in the logarithm handles a range of eight decades in a fixed number of steps.
:::
:::

::: check
kind: python

## Write `hall(VH, I, B, t_cm, rho)`: a Hall bar t cm thick carries current I (A) in field B (T) and shows Hall voltage VH (V); its resistivity is ρ (Ω·cm). Return (carrier density in cm⁻³, Hall mobility in cm²/(V·s)).

```python starter
def hall(VH, I, B, t_cm, rho):
    return (0.0, 0.0)
```

```python solution
Q = 1.602e-19

def hall(VH, I, B, t_cm, rho):
    n = I * B / (Q * (t_cm * 1e-2) * VH) * 1e-6
    return (n, 1 / (Q * n * rho))
```

```python tests
n, mu = hall(5e-3, 1e-3, 0.5, 0.05, 4.0)
assert abs(n - 1.248e15) / 1.248e15 < 1e-3, "n = IB/(qtV_H): 1.25e15 per cm³ (with t in meters, then m⁻³ to cm⁻³)."
assert abs(mu - 1250) < 1, "Mobility from ρ: 1250 cm²/(V·s)."
n2, _ = hall(2.5e-3, 1e-3, 0.5, 0.05, 4.0)
assert abs(n2 / n - 2) < 1e-9, "Half the Hall voltage means twice the carriers."
```

::: right
Right. The Hall voltage counts carriers; the resistivity then gives their mobility.
:::
:::

::: check
kind: python

## Write `haynes_shockley(d, E, t, sigma_t)`: a minority pulse drifts d cm in field E (V/cm), arriving after t s with a time spread (standard deviation) σ_t. Return (μ, D, D/μ), with $\mu = d/(Et)$, the spatial spread $\sigma_x = (d/t)\sigma_t$ and $D = \sigma_x^2/(2t)$.

```python starter
def haynes_shockley(d, E, t, sigma_t):
    return (0.0, 0.0, 0.0)
```

```python solution
def haynes_shockley(d, E, t, sigma_t):
    mu = d / (E * t)
    sx = d / t * sigma_t
    D = sx * sx / (2 * t)
    return (mu, D, D / mu)
```

```python tests
mu, D, r = haynes_shockley(0.5, 20, 57e-6, 4.099e-6)
assert abs(mu - 438.6) < 0.1, "μ = d/(Et) = 439 cm²/(V·s): holes in n-type silicon."
assert abs(r - 0.02585) < 2e-4, "D/μ comes out at kT/q: Einstein's relation, measured."
assert abs(D - 11.34) < 0.05, "D about 11.3 cm²/s."
```

::: right
Right. One experiment measures both μ and D, and their ratio checks the Einstein relation directly.
:::
:::

::: check
kind: python

## Write `xj_erfc(Cs, NB, D, t)`: the junction depth (cm) of a constant-surface diffusion $C_s\,\text{erfc}(x/2\sqrt{Dt})$ into a background $N_B$, by bisection. Then `xj_gauss(Q, NB, D, t)`: the depth for a drive-in of dose Q, $x_j = 2\sqrt{Dt}\sqrt{\ln(Q/(N_B\sqrt{\pi Dt}))}$.

```python starter
import math

def xj_erfc(Cs, NB, D, t):
    return 0.0

def xj_gauss(Q, NB, D, t):
    return 0.0
```

```python solution
import math

def xj_erfc(Cs, NB, D, t):
    L = 2 * math.sqrt(D * t)
    lo, hi = 0.0, 20 * L
    for _ in range(200):
        mid = (lo + hi) / 2
        if Cs * math.erfc(mid / L) > NB:
            lo = mid
        else:
            hi = mid
    return mid

def xj_gauss(Q, NB, D, t):
    return 2 * math.sqrt(D * t) * math.sqrt(math.log(Q / (NB * math.sqrt(math.pi * D * t))))
```

```python tests
x = xj_erfc(1e20, 1e16, 1e-13, 3600)
assert abs(x * 1e4 - 1.044) < 0.002, "erfc profile: junction at 1.04 µm, 2.75 diffusion lengths 2√(Dt) deep."
assert abs(xj_gauss(1e15, 1e16, 1e-13, 3600) * 1e4 - 1.073) < 0.002, "Gaussian of 1e15 per cm²: 1.07 µm."
assert xj_erfc(1e20, 1e17, 1e-13, 3600) < x, "A heavier background stops the junction sooner."
```

::: right
Right. Junction depth grows as $\sqrt{Dt}$, with a logarithmic factor from how far the profile must fall.
:::
:::

::: explain
## Why does a Haynes–Shockley measurement check the Einstein relation, and what would a ratio well above kT/q suggest?

::: model
The experiment watches one pulse of minority carriers. Its arrival time gives the drift velocity in a known field, hence the mobility, and the growth of its width gives the diffusion coefficient, so both quantities come from the same carriers under the same conditions. Einstein's relation says that in equilibrium D/μ equals kT/q, because the same random collisions limit both drift and diffusion. A measured ratio well above kT/q would point to extra spreading not caused by diffusion: carrier trapping and release, a nonuniform field, or a pulse that was too wide at the start.
:::
:::
