\section{PN junction}
\subsection{What are we even doing}
We stick together n and p doped regions, such that the doping effectively  becomes a step function.
This causes majority carriers (electrons in n region, holes in p region) to diffuse the minority carrier side,
resulting in a new equilibrium (\autoref{label:fig:pn_carrier_profile_equilibrium}).
\begin{figure}[H]
    \centering
    \begin{subfigure}[b]{.45\textwidth}
        \includegraphics[width=\textwidth]{imgs/pn_carrier_profile_equilibrium.png}
        \caption{Resulting carrier profile in thermal equilibrium}
        \label{label:fig:pn_carrier_profile_equilibrium}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{.45\textwidth}
        \includegraphics[width=\textwidth]{imgs/pn_fermi_level_band_bending.png}
        \caption{Resulting carrier profile in thermal equilibrium}
        \label{label:fig:pn_fermi_level_band_bending}
    \end{subfigure}
\end{figure}

As can be seen in \autoref{label:fig:pn_fermi_level_band_bending},
the energy levels for conduction and valence bands bend, whereas the fermi level remains constant.



\subsection{Depletion approximation}
We assume p and n regions quasi-neutral,
and the intermediate space charge region to be completely depleted of carriers.
We further assume all transitions are expressed as step-functions.
This allows the following simplified equations:
\begin{align}
    \rho(x) & = \begin{dcases}
                    0     & x<-x_p   \\
                    -qN_a & -x_p<x<0 \\
                    qN_d  & 0<x<x_n  \\
                    0     & x_n<x
                \end{dcases}                            \\
    E(x)    & =\begin{dcases}
                   0                                & x<-x_p    \\
                   -\frac{qN_a}{\varepsilon}(x+x_p) & - x_p<x<0 \\
                   \frac{qN_d}{\varepsilon}(x-x_n)  & 0<x<x_n   \\
                   0                                & x_n<x
               \end{dcases}
\end{align}
Where $E$ is found using \eqref{label:eq:def_electric_field_integral}.

\subsection{Electrostatic potential - (Width of the depletion zone)}
Because of overall charge neutrality
\begin{equation}
    qN_ax_p = qN_cx_n
\end{equation}
and continuity of the potential at the junction interface
\begin{equation}
    \phi_p+\frac{qN_a}{2\varepsilon}x_p^2 = \phi_n-\frac{qN_d}{2\varepsilon}x_n^2
\end{equation}
we can find $x_n$ and $x_p$:
\begin{align}
    x_n & = \sqrt{\frac{2\varepsilon\phi_BN_a}{qN_d(N_a+N_d)}} \\
    x_p & = \sqrt{\frac{2\varepsilon\phi_BN_d}{qN_a(N_a+N_d)}}
\end{align}
Where $\phi_B$ is the built-in potential (see \autoref{label:eq:boltzman:phi_B}), which is the potential over the junction.
Also, it is the less heavily doped region that defines the junction width.
It is also in the less heavily doped region that the depletion zone extends farther.

\subsection{Contact potential}
Although there is a potential accross the diode, it cannot be measured because there are the metal semi-conductor junctions for both p and n regions.
\begin{equation}
    \phi_B = \phi_{mn}+\phi_{mp}
\end{equation}