{
 "metadata": {
  "name": "",
  "signature": "sha256:5f773c85e1dfab84f7a94d7a8dae80fafd68f7320fe878d3eb9f67c265c3b4c6"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Ch2 : The p-n junction diode"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1: Page 185"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "print \"Part (a)\" \n",
      "# Applying Thevnin's theorem at XX', in Fig. 2.5(a)\n",
      "Vth=15*20e3/(10e3+20e3)  # Thevnin equivalent voltage in volts\n",
      "Zth=10e3*20e3/(10e3+20e3)  # Thevnin equivalent resistance in ohms\n",
      "# From the figure 2.5(c)\n",
      "I=Vth/(Zth+20e3)  # Labelled current in amperes\n",
      "Vo=I*20e3  # Labelled voltage in volts\n",
      "I=I*1e3  # Labelled current in miliamperes\n",
      "print \"Labelled current I = %0.2f mA\"%I \n",
      "print \"Labelled voltage Vo = %0.2f V\" %Vo\n",
      "\n",
      "print \"Part (b)\" \n",
      "# Applying Thevnin's theorem at XX' and YY', in Fig. 2.5(b)\n",
      "Vth1=15*10e3/(10e3+10e3)  # Thevnin equivalent voltage at XX' in volts\n",
      "Zth1=10e3*10e3/(10e3+10e3)  # Thevnin equivalent resistance at YY' in ohms\n",
      "Vth2=5  # Thevnin equivalent voltage at YY' in volts\n",
      "Zth2=5e3  # Thevnin equivalent resistance at YY' in ohms\n",
      "# From the figure 2.5(d)\n",
      "I=0  # Labelled current in amperes\n",
      "Vo=5-7.5  # Labelled voltage in volts\n",
      "print \"Labelled current I = %0.2f mA\"%I \n",
      "print \"Labelled voltage Vo = %0.2f V\" %Vo "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (a)\n",
        "Labelled current I = 0.38 mA\n",
        "Labelled voltage Vo = 7.50 V\n",
        "Part (b)\n",
        "Labelled current I = 0.00 mA\n",
        "Labelled voltage Vo = -2.50 V\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.2: Page 186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "ID1=1  # Let the initial diode current be 1 A\n",
      "ID2=15*ID1  # Final diode current\n",
      "VT=25e-3  # Voltage equivalent to temperatue at room temperature in volts\n",
      "eta=1  # for Ge\n",
      "deltaVD=eta*VT*log(ID2/ID1)  # Change in diode voltage in volts\n",
      "deltaVD=deltaVD*1e3  # Change in diode voltage in milivolts\n",
      "print \"Change in diode voltage (for Ge) = %0.2f mV\"%deltaVD\n",
      "eta=2  # for Si\n",
      "deltaVD=eta*VT*log(ID2/ID1)  # Change in diode voltage in volts\n",
      "deltaVD=deltaVD*1e3  # Change in diode voltage in milivolts\n",
      "print \"Change in diode voltage (for Si) = %0.3f mV\" %deltaVD"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in diode voltage (for Ge) = 67.70 mV\n",
        "Change in diode voltage (for Si) = 135.403 mV\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.3: Page 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import exp\n",
      "print \"Part (a)\" \n",
      "eta=1  # for Ge\n",
      "T=300  # Room temperature in kelvins\n",
      "VT=T/11600  # Voltage equivalent to temperatue at room temperature in volts\n",
      "IS=1  # Let reverse saturation current be 1 A\n",
      "I=-0.9*IS  # Reverse current\n",
      "V=eta*VT*log(1+(I/IS))  # Voltagei in volts\n",
      "V=V*1e3  # Voltage in milivolts\n",
      "print \"Voltage = %0.2f mV \" %V\n",
      "\n",
      "print \"Part (b)\" \n",
      "V=0.05  # Voltage in volts\n",
      "If_Ir=(exp(V/(eta*VT))-1)/(exp(-V/(eta*VT))-1)  # Ratio of current in forward bias to that in reverse bias\n",
      "print \"Ratio of current in forward bias to that in reverse bias = %0.3f\"%If_Ir \n",
      "\n",
      "print \"Part (c)\" \n",
      "IS=10e-6  # Reverse saturation current in amperes\n",
      "V=0.1  # Voltage in volts\n",
      "ID=IS*(exp(V/(eta*VT))-1)  # Forward current for 0.1 V in amperes\n",
      "ID=ID*1e6  # Forward current for 0.1 V in micro-amperes\n",
      "print \"Forward current for 0.1 V = %0.2f \u03bcA \" %ID\n",
      "V=0.2  # Voltage in volts\n",
      "ID=IS*(exp(V/(eta*VT))-1)  # Forward current for 0.1 V in amperes\n",
      "ID=ID*1e3  # Forward current for 0.1 V in miliamperes\n",
      "print \"Forward current for 0.1 V = %0.2f mA\"%ID \n",
      "V=0.3  # Voltage in volts\n",
      "ID=IS*(exp(V/(eta*VT))-1)  # Forward current for 0.1 V in amperes\n",
      "print \"Forward current for 0.1 V = %0.2f A\" %ID"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (a)\n",
        "Voltage = -59.55 mV \n",
        "Part (b)\n",
        "Ratio of current in forward bias to that in reverse bias = -6.913\n",
        "Part (c)\n",
        "Forward current for 0.1 V = 467.83 \u03bcA \n",
        "Forward current for 0.1 V = 22.82 mA\n",
        "Forward current for 0.1 V = 1.09 A\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4 Page 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "IS=10e-6  # Reverse saturation current in amperes\n",
      "eta=1  # for Ge\n",
      "VT=25e-3  # Voltage equivalent to temperatue at room temperature in volts\n",
      "\n",
      "print \"Part (a)\" \n",
      "VD=-24  # Reverse bias in volts\n",
      "ID=IS*(exp(VD/(eta*VT))-1)  # Current in amperes\n",
      "ID=ID*1e6  # Current in micro-amperes\n",
      "print \"Current = %0.2f \u03bcA \"%ID \n",
      "\n",
      "print \"Part (b)\" \n",
      "VD=-0.02  # Reverse bias in volts\n",
      "ID=IS*(exp(VD/(eta*VT))-1)  # Current in amperes\n",
      "ID=ID*1e6  # Current in micro-amperes\n",
      "print \"Current = %0.2f \u03bcA \"%ID \n",
      "\n",
      "print \"Part (c)\" \n",
      "VD=0.3  # Forward bias in volts\n",
      "ID=IS*(exp(VD/(eta*VT))-1)  # Current in amperes\n",
      "print \"Current = %0.2f A \"%ID"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (a)\n",
        "Current = -10.00 \u03bcA \n",
        "Part (b)\n",
        "Current = -5.51 \u03bcA \n",
        "Part (c)\n",
        "Current = 1.63 A \n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.5: Page 188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "T=300  # Operating temperature in kelvins\n",
      "VT=T/11600  # Voltage equivalent to temperatue at room temperature in volts\n",
      "ID1=1  # Let the initial diode current be 1 A\n",
      "ID2=10*ID1  # Final diode current\n",
      "eta=1  # for Ge\n",
      "deltaVD=eta*VT*log(ID2/ID1)  # Change in diode voltage in volts\n",
      "deltaVD=deltaVD*1e3  # Change in diode voltage in milivolts\n",
      "print \"Change in diode voltage (for Ge) = %0.2f mV \" %deltaVD\n",
      "eta=2  # for Si\n",
      "deltaVD=eta*VT*log(ID2/ID1)  # Change in diode voltage in volts\n",
      "deltaVD=deltaVD*1e3  # Change in diode voltage in milivolts\n",
      "print \"Change in diode voltage (for Si) = %0.2f mV \" %deltaVD"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in diode voltage (for Ge) = 59.55 mV \n",
        "Change in diode voltage (for Si) = 119.10 mV \n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.6: Page 188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# In the circuit given in Fig. 2.7\n",
      "V=50e-3  # Output voltage\n",
      "VD1=0.7  # Voltage across diode 1 in volts\n",
      "I1=10e-3  # Current through diode 1 at 0.7 V in amperes\n",
      "VD2=0.8  # Voltage across diode 2 in volts\n",
      "I2=100e-3  # Current through diode 2 at 0.8 V in amperes\n",
      "eta_VT=(VD2-VD1)/log(I2/I1)  # Product of \u03b7 and VT\n",
      "I=10e-3/(exp(V/eta_VT)+1)  # Current through diode 1 in amperes\n",
      "R=V/I \n",
      "print \"R = %0.2f \u03a9 \"%R "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R = 20.81 \u03a9 \n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7: Page 189"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "VDD=5  # Applied voltage in volts\n",
      "VD=0.7  # Diode voltage in volts\n",
      "I1=1e-3  # Current in amperes at diode voltage = 0.7 V\n",
      "R=1000  # R in ohms\n",
      "deltaVD=0.1  # Change in diode voltage in volts for every decade change in current\n",
      "ratioI=10  # Decade change in current\n",
      "eta_VT=deltaVD/log(ratioI)  # Product of \u03b7 and VT\n",
      "ID=(VDD-VD)/R  # Diode current in amperes\n",
      "VD2=VD+eta_VT*log(ID/I1)  # Diode voltage in volts\n",
      "ID=ID*1e3  # Diode current in miliamperes\n",
      "print \"Diode current = %0.2f mA\" %ID\n",
      "print \"Diode voltage = %0.2f V \"%VD2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Diode current = 4.30 mA\n",
        "Diode voltage = 0.76 V \n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8: Page 190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Part (a)\" \n",
      "# Since both the diodes are in OFF state\n",
      "Vo=5  # Output voltage in volts\n",
      "print \"Output voltage = %0.2f V \"%Vo \n",
      "\n",
      "print \"Part (b)\" \n",
      "#Since diode D1 is in OFF state and diode D2 is in ON state\n",
      "# From Fig. 2.16(C)\n",
      "I=(5-0.6)/(4.7e3+300)  # Current flowing through the diode D2 in amperes\n",
      "Vo=5-I*4.7e3  # Output voltage in volts\n",
      "print \"Output voltage = %0.2f V \"%Vo\n",
      "\n",
      "print \"Part (c)\" \n",
      "# Since both diodes are in ON state\n",
      "# Applying KVL in Fig. 2.16(d)\n",
      "I=(5-0.6)/(2*4.7e3+300)  # Current flowing through diode D1 or diode D2 in amperes\n",
      "Vo=5-2*I*4.7e3  # Output voltage in volts\n",
      "print \"Output voltage = %0.2f V \"%Vo"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (a)\n",
        "Output voltage = 5.00 V \n",
        "Part (b)\n",
        "Output voltage = 0.86 V \n",
        "Part (c)\n",
        "Output voltage = 0.74 V \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.9 Page 190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Vy=0.7  # Cut-in voltage in volts\n",
      "# In the Fig. 2.17\n",
      "R1=5e3 \n",
      "R2=10e3 \n",
      "\n",
      "print \"Part (a)\" \n",
      "# Since diode D1 is OFF and diode D2 is ON\n",
      "ID1=0 # A\n",
      "ID2=(5-Vy-(-5))/(R1+R2)  # Current through diode D2 in amperes\n",
      "Vo=5-ID2*R1  # Output voltage\n",
      "ID2=ID2*1e3  # Current through diode D2 in miliamperes\n",
      "print \"Output voltage = %0.2f V \" %Vo\n",
      "print \"Current through diode D1 = %0.2f mA\"%ID1 \n",
      "print \"Current through diode D2 = %0.2f mA \"%ID2 \n",
      "\n",
      "print \"Part (b)\" \n",
      "# Since both the diodes are ON\n",
      "VA=4-Vy  # In the fig.\n",
      "Vo=VA+Vy  # Output voltage\n",
      "ID2=(5-Vo)/R1  # Current through diode D2 in amperes\n",
      "IR2=(VA-(-5))/R2  # Current through diode R2 in amperes\n",
      "ID1=IR2-ID2  # Current through diode D1 in amperes\n",
      "ID1=ID1*1e3  # Current through diode D1 in miliamperes\n",
      "ID2=ID2*1e3  # Current through diode D2 in miliamperes\n",
      "print \"Output voltage = %0.2f V \" %Vo\n",
      "print \"Current through diode D1 = %0.2f mA\"%ID1 \n",
      "print \"Current through diode D2 = %0.2f mA \"%ID2 "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (a)\n",
        "Output voltage = 1.90 V \n",
        "Current through diode D1 = 0.00 mA\n",
        "Current through diode D2 = 0.62 mA \n",
        "Part (b)\n",
        "Output voltage = 4.00 V \n",
        "Current through diode D1 = 0.63 mA\n",
        "Current through diode D2 = 0.20 mA \n"
       ]
      }
     ],
     "prompt_number": 21
    }
   ],
   "metadata": {}
  }
 ]
}