{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "CHAPTER 22 NONLINEAR OP-AMP CIRCUITS"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-4, Page 854"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "Vin=10                                #ac input(V)\n",
      "Vs=15                                 #non-inverting input voltage(V)\n",
      "R1=200.0*10**3                        #non-inverting input resistance R1(Ohm)\n",
      "R2=100.0*10**3                        #non-inverting input resistance R2(Ohm)\n",
      "C=10*10**-6                           #capacitance at non-inverting input(F)\n",
      "\n",
      "Vref=Vs/3                                      #reference voltage at trip point(V)\n",
      "fc=(2*math.pi*((R1**-1+R2**-1)**-1)*C)**-1      #cutoff frequency(Hz)\n",
      "\n",
      "print 'trip point voltage Vref = ',Vref,'V'\n",
      "print 'cutoff frequency of bypass circuit fc = ',round(fc,2),'Hz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "trip point voltage Vref =  5 V\n",
        "cutoff frequency of bypass circuit fc =  0.24 Hz\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-5, Page 855"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "Vp=10.0                                #sine peak(V)\n",
      "Vin=5.0                                #input voltage(V)    \n",
      "\n",
      "theta=math.ceil((math.asin(Vin/Vp))*180/math.pi)  #angle theta (deg)\n",
      "D=(150-theta)/360.0                              #duty cycle\n",
      "\n",
      "print 'theta = ',theta,'degrees'\n",
      "print 'duty cycle D = ',round((D*100),2),'%'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "theta =  31.0 degrees\n",
        "duty cycle D =  33.06 %\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-6, Page 860"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "R1=1.0                              #non-inverting input resistance R1(KOhm)\n",
      "R2=47.0                             #feedback path resistance R2(KOhm)\n",
      "Vsat=13.5                           #saturation voltage(V)\n",
      "\n",
      "B=R1/(R1+R2)                       #feedback fraction\n",
      "UTP=B*Vsat                         #upper trip point\n",
      "LTP=-B*Vsat                        #lower trip point\n",
      "H=UTP-LTP                          #hysteresis\n",
      "\n",
      "print 'lower trip point LTP = ',round(LTP,2),'V'\n",
      "print 'upper trip point LTP = ',round(UTP,2),'V'\n",
      "print 'hysteresis is ',round(H,2),'V'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "lower trip point LTP =  -0.28 V\n",
        "upper trip point LTP =  0.28 V\n",
        "hysteresis is  0.56 V\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-7, Page 865"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "R=2                                #inverting input resistance R1(KOhm)\n",
      "C=1*10**-6                         #feedback path capacitance (F)\n",
      "T=1*10**-3                         #time period(s)\n",
      "Vin=8                              #input pulse voltage(V)\n",
      "AVOL=100000                        #open loop voltage gain\n",
      "\n",
      "V=Vin*T/(R*C)/1000                      #output voltage(V)\n",
      "t=R*C*(AVOL+1)*1000                     #time constant(s)\n",
      "\n",
      "print 'Magnitude of negative output voltage at end of the pulse = ',V,'V'\n",
      "print 'closed loop time constant = ',t,'s'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Magnitude of negative output voltage at end of the pulse =  4.0 V\n",
        "closed loop time constant =  200.002 s\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-8, Page 868"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "R1=1*10**3                         #inverting input resistance R1(Ohm)\n",
      "R2=10*10**3                        #feedback path resistance R2(Ohm)\n",
      "C=10*10**-6                        #feedback path capacitance (F)\n",
      "Vin=5                              #input pulse voltage(V)\n",
      "f=1*10**3                          #input frequency(Hz)\n",
      "\n",
      "Vout=Vin/(2*f*R1*C)                 #output voltage(V)\n",
      "\n",
      "print 'peak to peak output voltage = ',Vout,'Vpp'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "peak to peak output voltage =  0.25 Vpp\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-9, Page 868"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "Vs=15.0                               #non-inverting input voltage(V)\n",
      "Rw=5.0*10**3                          #inverting input wiper resistance(Ohm)\n",
      "R1=10.0*10**3                         #inverting input resistance R1(Ohm)\n",
      "f=1.0                                 #input frequency(KHz) \n",
      "\n",
      "Vref=Vs*(Rw/(Rw+R1))                  #reference voltage(V)\n",
      "T=1/f                                 #period of signal(s)\n",
      "W=2*(T/2)*((Vs/2)-Vref)/Vs            #output pulse width\n",
      "D=W/T                                 #duty cycle\n",
      "\n",
      "print 'duty cycle D = ',round((D*100),2),'%'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "duty cycle D =  16.67 %\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-10, Page 871"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "R1=18.0                             #non-inverting input resistance R1(KOhm)\n",
      "R2=2.0                              #feedback path resistance R2(KOhm)\n",
      "R=1.0                               #feedback path resistance R(KOhm)\n",
      "C=0.1*10**-6                        #feedback path capacitance (F)\n",
      "\n",
      "B=R1/(R1+R2)                             #feedback fraction\n",
      "T=10**9*2*R*C*math.log((1+B)/(1-B))      #period of output(us)\n",
      "f=1000*1/T                               #frequency(KHz)\n",
      "\n",
      "print 'period T = ',round(T,2),'us'\n",
      "print 'frequency f = ',round(f,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "period T =  588.89 us\n",
        "frequency f =  1.7 KHz\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-11, Page 871"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "Vsat=13.5                          #saturation voltage given(V)\n",
      "R4=10*10**3                        #given resistance R4(Ohm)\n",
      "C2=10*10**-6                       #given capacitance C2(F)\n",
      "T=589*10**-6                       #period from preceding example(s)\n",
      "\n",
      "Vout=Vsat*T/(2*R4*C2)              #output voltage (V) \n",
      "\n",
      "print 'Output voltage = ',round((Vout*1000),2),'mVpp'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output voltage =  39.76 mVpp\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22-12, Page 873"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "R1=1*10**3                        #resistance R1(Ohm)\n",
      "R2=100*10**3                      #resistance R2(Ohm)\n",
      "R3=10*10**3                       #resistance R3(Ohm)\n",
      "C=10*10**-6                       #capacitance (F)\n",
      "\n",
      "UTP=Vsat*R1/R2                     #UTP value (V)\n",
      "Vout=2*UTP                         #output voltage/hysteresis (V)\n",
      "f=R2/(4*R1*R3*C)                   #frequency(Hz)\n",
      "\n",
      "print 'Vout = H = ',Vout,'V'\n",
      "print 'frequency f = ',f,'Hz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vout = H =  0.27 V\n",
        "frequency f =  250.0 Hz\n"
       ]
      }
     ],
     "prompt_number": 37
    }
   ],
   "metadata": {}
  }
 ]
}