{
 "metadata": {
  "name": "ch_2"
 }, 
 "nbformat": 2, 
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown", 
     "source": [
      "<h1>Chapter 2: Circuit configuration for linear IC's<h1>"
     ]
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 2.1, Page no:40<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "Vcc=5.0              #voltage Vcc in volt", 
      "Vbeon=0.6            #Voltage  Vbeon in volt", 
      "Beta=150.0           #gain", 
      "Io=100.0*10**-6      #output current in amperes", 
      "", 
      "#Calculations:", 
      "Iref=Io*(1+ 2/Beta)  #calculating reference current", 
      "Iref=Iref*10**6      #calculating reference current", 
      "", 
      "R=(Vcc-Vbeon)/Iref   #Calculating value of resistance", 
      "R=R*1000.0           #Calculating value of resistance", 
      "", 
      "#Results:", 
      "print(\"Iref= %.2f uA\"% Iref)", 
      "print(\"\\nResistance= %.2f kohm\"% R)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Iref= 101.33 uA", 
        "", 
        "Resistance= 43.42 kohm"
       ]
      }
     ], 
     "prompt_number": 1
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 2.2, Page No:40<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declarations:", 
      "Vbe=0.7             #voltage Vbe in volt", 
      "Vcc=12.0            #voltage Vcc in volt", 
      "Rc1=1000.0          #collector resistance in ohm", 
      "Rc2=330.0           #collector resistance in ohm", 
      "", 
      "#Calculations:", 
      "Iref=(Vcc-Vbe)/Rc1  #calculating reference current ", 
      "I0=Iref             #Output current is equal to Reference current ", 
      "V0=Vcc-Rc2*I0       #Calculating output volatge", 
      "", 
      "Iref=Iref/10**-3    #calculating reference current", 
      "", 
      "#Results:", 
      "print(\"Iref= %.1f mA\"%Iref)", 
      "print(\"\\nV0= %.3f V\"%V0)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Iref= 11.3 mA", 
        "", 
        "V0= 8.271 V"
       ]
      }
     ], 
     "prompt_number": 2
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 2.3, Page No:40<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration", 
      "Vbe=0.6             #Voltage Vbe in volt", 
      "Vz=4.7              #Zener voltage in volt", 
      "Re=1000.0           #Emitter resistance in ohm", 
      "", 
      "#Calculations:", 
      "Vre=Vz-Vbe          #Calculating voltage acrross emitter resistance", 
      "", 
      "I=(Vre)/Re          #Calculating output current", 
      "I=I/10**-3          #Calculating output current", 
      "", 
      "#Results", 
      "print(\"I=%.1f mA\"%I)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "I=4.1 mA"
       ]
      }
     ], 
     "prompt_number": 3
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 2.4, Page No.: 42<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "Vcc=20.0            #Vcc in volt", 
      "R1=19300.0          #resistance in ohm", 
      "Vbe=0.7             #Vbe voltage in Volt", 
      "Ic2=0.000005        #current in amperes", 
      "Vt=0.026            # Vt voltage in volt", 
      "", 
      "#Calculations:", 
      "Ic1=(Vcc-Vbe)/R1                    #Calculating current through transistor Q1", 
      "", 
      "R2=(Vt/Ic2)*math.log(Ic1/Ic2)       #Calculating value of R2 for desired current through transistor Q2", 
      "", 
      "Ic1=Ic1/10**-3                      #Calculating current through transistor Q1", 
      "R2=R2/10**3                         #Calculating value of R2 for desired current through transistor Q2", 
      "", 
      "#Results:", 
      "print(\"Ic1= %d mA\"%Ic1)", 
      "print(\"\\nR2= %.2f kohm\"%R2)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Ic1= 1 mA", 
        "", 
        "R2= 27.55 kohm"
       ]
      }
     ], 
     "prompt_number": 4
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No.2.5, Page No: 44<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "Beta=100.0                  #Gain for transistor", 
      "R=20000.0                   #Resistance in ohm", 
      "Vcc=5.0                     #Volatage Vcc in volt", 
      "Vbe=0.6                     #Voltage Vbe in volt", 
      "N=3.0                       #Number of multiple current source", 
      "", 
      "#Calculations:       ", 
      "Iref=(Vcc-Vbe)/R            #Calculating reference current", 
      "", 
      "Ic=Iref*(1+ 4/Beta)         #Calculating current through transistor Q", 
      "Ic1=Iref*(Beta)/(Beta+N+1)  #Calculating current through transistor Q1", 
      "Ic2=Iref*(Beta)/(Beta+N+1)  #Calculating current through transistor Q2", 
      "Ic3=Iref*(Beta)/(Beta+N+1)  #Calculating current through transistor Q3", 
      "", 
      "Iref=Iref/10**-3            #Calculating Reference current", 
      "Ic1=Ic1/10**-3              #Calculating current through transistor Q1", 
      "", 
      "#Results:", 
      "print(\"Iref= %.2f mA\"%Iref)", 
      "print(\"\\nIc1=Ic2=Ic3= %.3f mA\"%Ic1)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Iref= 0.22 mA", 
        "", 
        "Ic1=Ic2=Ic3= 0.212 mA"
       ]
      }
     ], 
     "prompt_number": 5
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No.2.6, Page NO: 52<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "Iref=0.25*10**-3              #Reference current in amperes", 
      "Io=0.2*10**-3                 #Outpyt current in amperes", 
      "kn=20*10**-6                  #Transconductance in ampere per volt square", 
      "Vth=1.0                       #Threshold voltage in volt", 
      "Vgs2=1.752                    #Voltage Vgs2 in volt", 
      "lamb=0.0                      #Channel length modulation parameter", 
      "Vdd=5.0                       #Voltge Vdd in volt", 
      "Vss=0.0                       #voltage Vss in volt", 
      "", 
      "#Calculations:", 
      "wbyltwo=Io/(kn*(Vgs2-Vth)**2)     #calculating width by length 2 ratio", 
      "Vdssat=Vgs2-Vth                   #Calculating voltage Vdssat", 
      "Vgs1=Vgs2                         #Volage Vgs1 is eqaul to Vgs2", 
      "wbylone=Iref/(kn*(Vgs2-Vth)**2)   #Calculating width by length 1 ratio", 
      "Vgs3=Vdd-Vss-Vgs1                 #Calculating Vgs3", 
      "wbylthr=Iref/(kn*(Vgs3-Vth)**2)   #calculating width by length 3 ratio", 
      "", 
      "#Results:", 
      "print(\"W/L2= %.1f\"%wbyltwo)", 
      "print(\"\\nVds(sat)= %.3f V\"%Vdssat)", 
      "print(\"\\nW/L1= %.1f\"%wbylone)", 
      "print(\"\\nVgs3= %.3f V\"%Vgs3)", 
      "print(\"\\nW/L3= %.2f\"% wbylthr)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "W/L2= 17.7", 
        "", 
        "Vds(sat)= 0.752 V", 
        "", 
        "W/L1= 22.1", 
        "", 
        "Vgs3= 3.248 V", 
        "", 
        "W/L3= 2.47"
       ]
      }
     ], 
     "prompt_number": 6
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 2.7, Page No: 75<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "cmrra=1000.0          #common mode rejection ratio", 
      "cmrrb=10000.0         #common mode rejection ratio ", 
      "v1a=100.0*10**-6      #input voltage in volt", 
      "v2a=-100.0*10**-6     #input voltage in volt", 
      "v1b=1100.0*10**-6     #input voltage in volt", 
      "v2b=900.0*10**-6      #input voltage in volt", 
      "", 
      "#Calculations", 
      "#for first set", 
      "vida=v1a-v2a                   #Calculating differential volatge", 
      "vcma=(v1a+v2a)/2               #calculating common mode voltage", 
      "vic=0.0                        #Calculating common mode voltage", 
      "voa=vida*(1+vic/(cmrra*vida))  #Calculating Output voltage", 
      "voa=voa*10**6                  #Calculating output volatge", 
      "", 
      "# for second set", 
      "vidb=v1b-v2b                   #Calculating differential volatge", 
      "vic=(v1b+v2b)/2                #calculating common mode voltage", 
      "vob=vidb*(1+vic/(cmrrb*vidb))  #Calculating Output voltage", 
      "vob=vob*10**6                  #Calculating Output voltage", 
      "", 
      "#Results:", 
      "print(\"\\nVo for second set= %.1f uV\"%vob)", 
      "print(\"Vo for first set= %.1f uV\"% voa)", 
      "", 
      "#answer in textbook is wrong"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Vo for second set= 200.1 uV", 
        "Vo for first set= 200.0 uV"
       ]
      }
     ], 
     "prompt_number": 7
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No.2.8, Page No.76<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "Beta=100.0               #Gain", 
      "Vee=15.0                 #Voltage Vee in volt", 
      "Vcc=15.0                 #Voltage Vcc in volt", 
      "Vbe=0.7                  #Voltage Vbe in volt", 
      "Re=65.0*10**3            #Resistance in ohm", 
      "Rc=65.0*10**3            #Resistance in ohm", 
      "alpha=100.0/101.0        #Gain", 
      "Ve=-0.7                  #Voltage Ve in volt", 
      "", 
      "#Calculations:", 
      "Ie=(Vee-Vbe)/(2*Re)      #Calculating emitter current", 
      "Ic=alpha*Ie              #Calculating collector current", 
      "Ib=Ic/Beta               #Calculating base current", 
      "", 
      "Vc=Vcc-Ic*Rc             #Calculating collector volatge", 
      "", 
      "Vce=Vc-Ve                #Calculating voltage between collector and emitter", 
      "", 
      "Ie=Ie*10**6              #Calculating emitter current", 
      "", 
      "Ic=Ic*10**6              #Calculating collector current", 
      "", 
      "Ib=Ib*10**6              #Calculating base current", 
      "", 
      "# by approximating, because Vee>>Vbe", 
      "", 
      "Ieapprox=Vee/(2*Re)      #calculating emitter current by approximation", 
      "Ieapprox=Ieapprox*10**6  #calculating emitter current by approximation", 
      "", 
      "#Results:", 
      "print('Ie= %.1f uA'%Ie)", 
      "print('\\nIc= %.1f uA'%Ic)", 
      "print('\\nIb= %.3f uA'%Ib)", 
      "print('\\nVc= %.3f V'%Vc)", 
      "print('\\nVce= %.3f V'%Vce)", 
      "", 
      "print('\\nIe (approx)= %.2f uA'%Ieapprox)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Ie= 110.0 uA", 
        "", 
        "Ic= 108.9 uA", 
        "", 
        "Ib= 1.089 uA", 
        "", 
        "Vc= 7.921 V", 
        "", 
        "Vce= 8.621 V", 
        "", 
        "Ie (approx)= 115.38 uA"
       ]
      }
     ], 
     "prompt_number": 8
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No.2.9, Page No.89<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "Vdd=12.0                     #Voltage Vdd in volt", 
      "Vss=-12.0                    #Voltage Vss in volt", 
      "Iss=175.0*10**-6             #Current Iss in amperes", 
      "Rd=65.0*10**3                #resistance Rd in ohm", 
      "kn=3.0*10**-3                #Transconductance", 
      "Vth=1.0                      #Voltage Vth in volt", 
      "", 
      "#Calculations:", 
      "Ids=Iss/2.0                  #Calculating Ids", 
      "", 
      "Vgs=Vth + math.sqrt(Iss/kn)  #Calculating Vgs", 
      " ", 
      "Vds = Vdd- Ids*Rd + Vgs      #Calculating Vds", 
      "", 
      "#Requirement for saturation", 
      "Vicmax= Vdd - Ids*Rd + Vth   #Calculating Vicmax", 
      "", 
      "Ids=Ids*10**6                #Calculating Ids", 
      "", 
      "#Results:", 
      "print('\\nIds=%.1f uA'% Ids)", 
      "print('\\nVgs=%.3f V'%Vgs)", 
      "print('\\nVds=%.2f V'% Vds)", 
      "print('\\nVicmax=%.2f V'% Vicmax)", 
      "print('\\nRequirement of saturation for M1 \\nfor non-zero Vic necessiates Vic <= 7.312 V')"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Ids=87.5 uA", 
        "", 
        "Vgs=1.242 V", 
        "", 
        "Vds=7.55 V", 
        "", 
        "Vicmax=7.31 V", 
        "", 
        "Requirement of saturation for M1 ", 
        "for non-zero Vic necessiates Vic <= 7.312 V"
       ]
      }
     ], 
     "prompt_number": 9
    }
   ]
  }
 ]
}