.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/electrical_engineering/electronics/plot_02_shockley_diode.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_electrical_engineering_electronics_plot_02_shockley_diode.py: Shockley's diode equation and the load line (1949) ================================================== William Shockley's theory of the p-n junction, published in 1949 with the junction transistor, explained why a diode conducts one way: minority carriers injected across the junction diffuse away at a rate that grows as :math:`e^{qv/kT}`, so the current is :math:`i = I_S\left(e^{v/nV_T} - 1\right)` with the thermal voltage :math:`V_T = kT/q` (:func:`~engineeringkit.electrical_engineering.shockley_diode_current`, :func:`~engineeringkit.electrical_engineering.thermal_voltage`). In a circuit the diode shares its current with a resistor, whose straight load line meets the exponential at the operating point (:func:`~engineeringkit.electrical_engineering.diode_operating_point`). This example draws the characteristic, solves a load line and checks the famous 60 mV per decade and the fall of the forward voltage with temperature, roughly 2 mV/K. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.electrical_engineering import diode_operating_point, shockley_diode_current, thermal_voltage .. GENERATED FROM PYTHON SOURCE LINES 28-30 The characteristic ------------------ .. GENERATED FROM PYTHON SOURCE LINES 30-39 .. code-block:: Python Is, n = 1e-14, 1.0 vt = thermal_voltage(300.0) v = np.linspace(-0.2, 0.75, 400) i = shockley_diode_current(v, Is, n) per_decade = n * vt * np.log(10) print(f"V_T = {1e3 * vt:.2f} mV at 300 K; forward voltage rises {1e3 * per_decade:.1f} mV per decade of current") assert np.isclose(shockley_diode_current(0.65 + per_decade, Is) / shockley_diode_current(0.65, Is), 10, rtol=1e-6) .. rst-class:: sphx-glr-script-out .. code-block:: none V_T = 25.85 mV at 300 K; forward voltage rises 59.5 mV per decade of current .. GENERATED FROM PYTHON SOURCE LINES 40-44 The load-line solution ---------------------- A 5 V supply drives the diode through 1 kΩ. .. GENERATED FROM PYTHON SOURCE LINES 44-52 .. code-block:: Python Vs, R = 5.0, 1e3 vd, idiode = diode_operating_point(Vs, R, Is, n) print(f"operating point: v = {vd:.4f} V, i = {1e3 * idiode:.4f} mA") assert np.isclose(idiode, (Vs - vd) / R) and np.isclose(idiode, shockley_diode_current(vd, Is, n), rtol=1e-9) # The constant-drop model a student would use is within a few percent. print(f"0.7 V model: i = {1e3 * (Vs - 0.7) / R:.3f} mA") .. rst-class:: sphx-glr-script-out .. code-block:: none operating point: v = 0.6925 V, i = 4.3075 mA 0.7 V model: i = 4.300 mA .. GENERATED FROM PYTHON SOURCE LINES 53-59 Temperature ----------- At a fixed current the forward voltage falls with temperature, because :math:`I_S` grows much faster than :math:`V_T` (roughly :math:`I_S \propto T^3 e^{-E_g/kT}` with :math:`E_g = 1.12` eV for silicon). .. GENERATED FROM PYTHON SOURCE LINES 59-82 .. code-block:: Python def saturation_current(T, Is300=Is, Eg=1.12): return Is300 * (T / 300) ** 3 * np.exp(Eg / (n * thermal_voltage(300.0)) - Eg / (n * thermal_voltage(T))) temperatures = np.array([280.0, 300.0, 320.0]) forward = [diode_operating_point(Vs, R, saturation_current(T), n, T)[0] for T in temperatures] slope = np.polyfit(temperatures, forward, 1)[0] print(f"forward voltage temperature coefficient {1e3 * slope:.2f} mV/K") assert -2.5e-3 < slope < -1.5e-3 fig, axes = plt.subplots(1, 2, figsize=(10, 3.8)) axes[0].plot(v, 1e3 * i, label="diode") axes[0].plot(v, 1e3 * (Vs - v) / R, label="load line") axes[0].plot(vd, 1e3 * idiode, "ko", label="operating point") axes[0].set(xlabel="diode voltage [V]", ylabel="current [mA]", ylim=(-0.5, 6), title="Load line") axes[0].legend(fontsize="small") axes[1].semilogy(v[v > 0.2], i[v > 0.2]) axes[1].set(xlabel="diode voltage [V]", ylabel="current [A]", title="Exponential law") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/electrical_engineering/electronics/images/sphx_glr_plot_02_shockley_diode_001.png :alt: Load line, Exponential law :srcset: /api/gallery/electrical_engineering/electronics/images/sphx_glr_plot_02_shockley_diode_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none forward voltage temperature coefficient -1.67 mV/K .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.137 seconds) .. _sphx_glr_download_api_gallery_electrical_engineering_electronics_plot_02_shockley_diode.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/electrical_engineering/electronics/plot_02_shockley_diode.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_shockley_diode.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_shockley_diode.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_shockley_diode.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_