Concentrations of carriers in semiconductor

For a given semiconductor at a given temperature $T$ with doping levels of acceptors $N_A$ and donors $N_D$ and intrinsic carrier concentration $n_i$ without any external biases, how can I calculate the densities of holes and electrons.

I know that, at equillibrium, $np=n_i^2$, which is one equation. I also know that $n$ and $p$ can be calculated directly with the difference between the fermi level and the intrinsic energy level $E_f - E_i$ with the formulas $n=n_i \exp{(\frac{E_f-E_i}{kT})}$ and $p=n_i \exp{(\frac{E_i-E_f}{kT})}$.

For heavily doped scenarios in which $N_D \gg N_A$ or vice versa, I could calculate $E_f-E_i$ by assuming $n \approx N_D$. However, for situations in which the semiconductor isn't heavily doped or for situations where $N_A$ and $N_D$ are close, how could I calculate the the difference between the fermi energy after doping and the intrinsic fermi energy?

• I'm not sure but I think for heavy doping there's no single formula. The formula you mentioned assumes a Boltzmann distribution which is a good approximation at low doping but for heavy doping effects of Pauli exclusions should be considered