{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5 : Waveform Generator"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.1, Page No.186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Astable multivibrator using IC555\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "C = 0.01*10**-6              # capacitance\n",
      "RA = 2*10**3                 # Resistance RA\n",
      "RB = 100*10**3               # Resistance RB\n",
      "\n",
      "#Calculations\n",
      "T_high = 0.693*(RA+RB)*C\n",
      "T_low = 0.693*RB*C\n",
      "T= T_high+T_low\n",
      "f = 1/T\n",
      "D = T_high*100/T\n",
      "\n",
      "#Result\n",
      "print(\"Frequency of oscillations, f = %.1f Hz\\nDuty cycle = %.1f%%\"%(f,D))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency of oscillations, f = 714.4 Hz\n",
        "Duty cycle = 50.5%\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.2, Page No.186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Astable multivibrator using IC555\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "C = 1.0*10**-6               # capacitance \n",
      "C1 = 0.01*10**-6             # capacitance C1\n",
      "RA = 4.7*10**3               # Resistance RA\n",
      "RB = 1.0*10**3               # Resistance RB\n",
      "\n",
      "#Calculations\n",
      "Ton = 0.693*(RA+RB)*C\n",
      "Toff = 0.693*RB*C\n",
      "T= T_high+T_low\n",
      "f = 1.4/((RA+2*RB)*C)\n",
      "D = (RA+RB)*100/((RA+2*RB))\n",
      "\n",
      "#Result\n",
      "print(\"T_on = %.2f ms\\nT_off = %.3f ms\"%(Ton*1000,Toff*1000))\n",
      "print(\"Frequency of oscillations, f = %.1f Hz\\nDuty cycle = %.0f%%\"%(math.floor(f*10)/10,D))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "T_on = 3.95 ms\n",
        "T_off = 0.693 ms\n",
        "Frequency of oscillations, f = 208.9 Hz\n",
        "Duty cycle = 85%\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.3, Page No. 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Astable multivibrator using IC555\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "f = 1000.0               # frequency\n",
      "d = 50.0/100.0           # duty cycle\n",
      "C = 0.01*10**-6          # capacitance\n",
      "\n",
      "#Calculations\n",
      "T = 1/f\n",
      "Ton = d*T\n",
      "Toff = d*T\n",
      "RA = 1.44/(2*f*C)\n",
      "\n",
      "#Result\n",
      "print(\"RA = RB = %.0f k-ohm\"%(RA/1000))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "RA = RB = 72 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.4, Page No. 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# IC555 timer as an astable multivibrator\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "f = 700.0                 # frequency\n",
      "d = 0.5                   # duty cycle\n",
      "C = 0.01*10**-6           # capacitor value assumed\n",
      "\n",
      "#Calculations\n",
      "Ra = 1.44/(2*f*C)\n",
      "\n",
      "#Result\n",
      "print(\"C  = %.2f micro-F\\nRA = RB = %.0f k-ohm (100 k-ohm standard value)\"%(C*10**6,Ra/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C  = 0.01 micro-F\n",
        "RA = RB = 103 k-ohm (100 k-ohm standard value)\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.5, Page No. 188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# IC555 timer as an astable multivibrator\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "f = 800.0                 # frequency\n",
      "d = 0.6                   # duty cycle\n",
      "C = 0.01*10**-6           # capacitor value assumed\n",
      "\n",
      "#Calculations\n",
      "Ra = 1.44/(5*f*C)  # since Rb = 2Ra and f = 1.44/(Ra+2Rb)*C\n",
      "Rb = 2*Ra\n",
      "\n",
      "\n",
      "#Result\n",
      "print(\"C  = %.2f micro-F\\nRA = %.0f k-ohm\\nRB = %.0f k-ohm\"%(C*10**6,Ra/1000,Rb/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C  = 0.01 micro-F\n",
        "RA = 36 k-ohm\n",
        "RB = 72 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.6, Page No. 189"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Timer design(refer fig. 5.11)\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "Ton = 5.0         # On timing oof the timer\n",
      "\n",
      "# Calculations\n",
      "C = 10*10**-6     # assumed value\n",
      "R = Ton/(1.1*C)\n",
      "\n",
      "#Result\n",
      "print(\"C = %.0f micro-F\\nR = %.2f ohm\"%(C*10**6,R))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C = 10 micro-F\n",
        "R = 454545.45 ohm\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.7, Page No. 189"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Design of astable multivibrator(refer fig. 5.12)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Ton  = 3.0             # ON time\n",
      "Toff = 1.0             # OFF time\n",
      "\n",
      "#Calculations\n",
      "C = 10*10**-6          # Capacitor assumed value\n",
      "R2 = Toff/(0.693*C)\n",
      "R1 = (Ton/(0.693*C))-R2\n",
      "\n",
      "\n",
      "#Result\n",
      "print(\"C = %.0f micro-F\\nR1 = %.0f ohm\\nR2 = %.0f ohm\"%(C*10**6,R1,R2))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C = 10 micro-F\n",
        "R1 = 288600 ohm\n",
        "R2 = 144300 ohm\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.8, Page No.190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Monostable and astable mode of IC555\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Ton = 10*10**-3               # ON timing\n",
      "C = 0.22*10**-6               # Capacitance\n",
      "V = 1.4                       # LED voltage drop\n",
      "I = 20*10**-3                 # current provided by circuit\n",
      "f = 1000.0                    # frequency of astable multivibrator\n",
      "d = 0.95                      # duty cycle of astable multivibrator\n",
      "\n",
      "\n",
      "#calculations\n",
      "R = Ton/(1.1*C)\n",
      "R = math.ceil(R/100)/10\n",
      "Vcc = 15.0                    # standard, assumed\n",
      "Vbe = 0.7                     # standard, assumed\n",
      "VECsat = 0.2                  # standard, assumed\n",
      "Vo = Vcc -2*Vbe-VECsat\n",
      "Rled = (Vo-V)/I\n",
      "\n",
      "C1 = 0.01*10**-6              # capacitor for noise immunity\n",
      "x = 1.44/(f*C1)               # x = R1+2*R2.......(i)\n",
      "y = (1-d)/(d*2-1)             # y = R2/R1.........(ii)\n",
      "y = math.floor(y*10**4)/10**4\n",
      "R1 = x/(1+2*y)                # using (i) and (ii)\n",
      "R2 = y*R1\n",
      "\n",
      "#Result\n",
      "print(\"For LED driving circuit:\\nCapacitance = %.2f micro-F\\nResistancce = %.1f ohm\\nVo = %.1f V\\nRled = %.0f ohm\"%(C*10**6,R,Vo,Rled))\n",
      "print(\"\\nFor astable multivibrator:\\nC = %.2f micro-F\\nR1 = %.1f ohm\\nR2 = %.2f ohm\"%(C1*10**6,R1/1000,R2/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For LED driving circuit:\n",
        "Capacitance = 0.22 micro-F\n",
        "Resistancce = 41.4 ohm\n",
        "Vo = 13.4 V\n",
        "Rled = 600 ohm\n",
        "\n",
        "For astable multivibrator:\n",
        "C = 0.01 micro-F\n",
        "R1 = 129.6 ohm\n",
        "R2 = 7.19 ohm\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.9, Page No. 191"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# IC555 as a monostable multivibrator(refer fig. 5.15)\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "T = 5*10**-3                # output pulse width\n",
      "\n",
      "\n",
      "#Calculations\n",
      "C = 0.1*10**-6              # capacitance\n",
      "R = T/(1.1*C)\n",
      "\n",
      "#Result\n",
      "print(\"R = %.2f k-ohm\\nThe value of R should be less than 100 k-ohm, as obtained.\"%(R/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R = 45.45 k-ohm\n",
        "The value of R should be less than 100 k-ohm, as obtained.\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.10, Page No. 191"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# IC555 based square wave generator\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "f = 1000.0                 # required frequency\n",
      "Vcc = 12.0                 # input voltage\n",
      "\n",
      "#Calculations\n",
      "T = 1/f\n",
      "Td = T/2\n",
      "C  = 0.1*10**-6           # assumed\n",
      "R2 = Td/(0.69*C)\n",
      "\n",
      "#Result\n",
      "print(\"R2 = %.2f k-ohm\\nR1 = 100 ohm + 10 k-ohm pot(With pot, precise squre wave can be obtained)\"%(R2/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R2 = 7.25 k-ohm\n",
        "R1 = 100 ohm + 10 k-ohm pot(With pot, precise squre wave can be obtained)\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.11, Page No. 192"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Clock with 50% duty cycle\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "f = 2000.0              # required output frequency \n",
      "\n",
      "#Calculations\n",
      "T = 1/f\n",
      "Td = T/2\n",
      "C = 0.1*10**-6                 # assumed\n",
      "R2 = Td/(0.69*C)\n",
      "\n",
      "#Result\n",
      "print(\"R1 = R2 = %.3f k-ohm\"%(R2/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 = R2 = 3.623 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.12, Page No.193"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Rectangular waveform using astable multivibrator\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "T = 1.0*10**-3         # Total time period of output waveform\n",
      "Ton = 0.6 *10**-3      # Ton time\n",
      "\n",
      "\n",
      "#Calculations\n",
      "D = Ton/T\n",
      "x = (1-D)/(2*D-1)      # Rb/Ra\n",
      "f = 1/T\n",
      "C = 0.1*10**-6         # assumed\n",
      "Ra = (1.44/(f*C))/5\n",
      "Rb = x*Ra\n",
      "\n",
      "#Result\n",
      "print(\"C = %.2f micro-F\\nRa = %.2f k-ohm\\nRb = %.2f k-ohm\"%(C*10**6,Ra/1000,Rb/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C = 0.10 micro-F\n",
        "Ra = 2.88 k-ohm\n",
        "Rb = 5.76 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.13, Page No.195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 555 timer in astable mode\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "Ra = 4.0*10**3              # Resistance Ra\n",
      "Rb = 4.0*10**3              # Resistance Rb\n",
      "C = 0.01*10**-6           # Capacitance\n",
      "\n",
      "#Calculations\n",
      "f = 1.44/((Ra+2*Rb)*C)\n",
      "D = (Ra+Rb)/(Ra+2*Rb)\n",
      "\n",
      "#Result\n",
      "print(\"frequency  = %.0f KHz\\nDuty cycle = %.2f%%\"%(f/1000,D*100))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "frequency  = 12 KHz\n",
        "Duty cycle = 66.67%\n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.14, Page No. 195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Timer design\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "Ton = 5                 # ON time width\n",
      "\n",
      "# Calculations\n",
      "C = 10*10**-6           # assumed\n",
      "R = Ton/(1.1*C)\n",
      "\n",
      "#Result\n",
      "print(\"R = %.2f k-ohm\"%(R/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R = 454.55 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.15, Page No.196"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Astable multivibrator\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "f = 2000.0               # output frequency\n",
      "D = 0.75                 # duty cycle\n",
      "\n",
      "\n",
      "#Calculations\n",
      "x = (1-D)/(2*D-1)        # Rb/Ra\n",
      "C = 0.1 *10**-6          # assumed\n",
      "Ra = (1.44/f)/(C*2)\n",
      "Rb = x*Ra\n",
      "\n",
      "#Result\n",
      "print(\"C  = %.1f micro-F\\nRa = %.1f k-ohm\\nRb = %.1f k-ohm\"%(C*10**6,Ra/1000,Rb/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C  = 0.1 micro-F\n",
        "Ra = 3.6 k-ohm\n",
        "Rb = 1.8 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.16, Page No.197"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 555 as astable mode to generate square wave(refer fig.5.25)\n",
      "\n",
      "import math\n",
      "# Variable declarations\n",
      "f = 1000.0                      # output square wave frequency\n",
      "Vo = 5.0                        # output voltage\n",
      "Ton = 0.5*10**-3                # ON time of suare wave\n",
      "Toff= 0.5*10**-3                # OFF time of suare wave\n",
      "Vl = 5.0                        # Lamp voltage rating\n",
      "Il = 50*10**-3                  # lamp current rating\n",
      "\n",
      "#Calculations\n",
      "C = 0.1*10**-6                  # capacitance, assumed\n",
      "Rb = Toff/(0.69*C)\n",
      "Rb = Rb/1000.0                  #k-ohm\n",
      "VLed = 0.7                      # voltage drop accross LED\n",
      "R =(Vo-VLed)/(Il)\n",
      "R = 100                         #standard value  \n",
      "P = (Il**2)*R\n",
      "\n",
      "# Result\n",
      "print(\"duty cycle is 50%% hence,\\nRa = Rb = %.3f k-ohm\\nCurrent limiting Resistance for LED is, R = %.0f ohm\\nP = %.2f W\"%(Rb,R,P))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "duty cycle is 50% hence,\n",
        "Ra = Rb = 7.246 k-ohm\n",
        "Current limiting Resistance for LED is, R = 100 ohm\n",
        "P = 0.25 W\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.17, Page No. 199"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Ramp generator using IC555\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "f = 5000.0                 # output frequency\n",
      "Vcc = 5.0                  # input voltage\n",
      "\n",
      "\n",
      "# Calculations\n",
      "Vd = 0.7                   # = Vbe, assumed \n",
      "Ic = (Vcc-Vd)\n",
      "RC = 3*Ic/(Vcc*f)\n",
      "C = 0.05*10**-6            # assumed\n",
      "R = RC/C\n",
      "Ic = Ic/R\n",
      "\n",
      "#Result\n",
      "print(\"C = %.2f micro-F\\nR = %.2f k-ohm\\nIc = %.3f mA\"%(C*10**6,R/1000,math.floor(Ic*10**6)/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C = 0.05 micro-F\n",
        "R = 10.32 k-ohm\n",
        "Ic = 0.416 mA\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.18, Page No.205"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Triangular wave generator\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "f = 5000.0                     # output frequency \n",
      "Vo = 10.5                      # output voltage\n",
      "Vsat = 15                      # saturation voltage\n",
      "\n",
      "\n",
      "#Calculations\n",
      "x = 2*Vsat/Vo                   # R3/R2:: this value is wrong in the book\n",
      "R2 = 10*10**3                   # assumed\n",
      "R3 = 4*R2                       # calculationg using value given in book\n",
      "C1 = 0.01*10**-6                # assumed\n",
      "R1 = R3/(4*C1*R2*f)\n",
      "\n",
      "\n",
      "#Result\n",
      "print(\"C1 = %.2f micro-F\\nR1 = %.0f k-ohm\\nR2 = %.0f k-ohm\\nR3 = %.0f k-ohm\"%(C*10**6,R1/1000,R2/1000,R3/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C1 = 0.05 micro-F\n",
        "R1 = 20 k-ohm\n",
        "R2 = 10 k-ohm\n",
        "R3 = 40 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "exxample 5.19, Page No. 213"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "exxample 5.20, Page No. 220"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "exxample 5.21, Page No.221"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Oscillation frequency(refer fig 5.21)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "R = 5.1*10**3                     # resistance\n",
      "C = 0.001*10**-6                  # capacitance\n",
      "R3 = 6.0*10**3                      # Resistance of R3\n",
      "R4 = 2.0*10**3                      # Resistance of R4\n",
      "\n",
      "#Calculations\n",
      "A = 1+(R3/R4)\n",
      "f = 1/(2*math.pi*R*C)\n",
      "\n",
      "#Result\n",
      "print(\"A = %d\\nAs A > 3, this satisfies the required oscillating condition. Hence, Circuit will work as oscillator.\\n\"%(A))\n",
      "print(\"frequency of oscillations = %.4f kHz\"%(f/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A = 4\n",
        "As A > 3, this satisfies the required oscillating condition. Hence, Circuit will work as oscillator.\n",
        "\n",
        "frequency of oscillations = 31.2069 kHz\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.22, Page No. 221"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# design of wein bridge oscillator(refer fig.5.58)\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "f = 1000.0                 # frequency of oscillation\n",
      "V = 15                     # supply voltage\n",
      "g = 3                      # gain of non-inverting op-amp for  circuit to be oscillator \n",
      "\n",
      "#Calculations \n",
      "C = 0.05*10**-6            # assumed\n",
      "R = 1/(2*math.pi*C*f)\n",
      "R4 = 10*10**3              # assumed\n",
      "R3 = (g-1)*R4\n",
      "\n",
      "#Result\n",
      "print(\"C1 = C2 = C = %.2f micro-F\\nR1 = R2 = R = %.3f k-ohm\\nR3 = %.0f k-ohm\\nR4 = %.0f k-ohm\"%(C*10**6,R/1000,R3/1000,R4/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C1 = C2 = C = 0.05 micro-F\n",
        "R1 = R2 = R = 3.183 k-ohm\n",
        "R3 = 20 k-ohm\n",
        "R4 = 10 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.23, Page No. 225"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# output frequency range\n",
      "\n",
      "import math\n",
      "#Variable declararion\n",
      "R = 10*10**3                          # Resistor R\n",
      "C = 1.25*10**-9                       # Capacitance\n",
      "Vut = 10.0                            # Upper threshold voltage\n",
      "Vlt = 0.0                             # lower threshold voltage\n",
      "Vmin = 10*10**-3                      # minimum voltage \n",
      "Vmax = 10                             # Maximum voltage \n",
      "\n",
      "#Calculations\n",
      "Kv = 1/(8*R*C*(Vut-Vlt))\n",
      "fmin = Vmin*Kv\n",
      "fmax = Vmax*Kv\n",
      "\n",
      "#Result\n",
      "print(\"Range over whoich output frequency can be varied is %.0f Hz to %.0f KHz.\"%(fmin,fmax/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Range over whoich output frequency can be varied is 10 Hz to 10 KHz.\n"
       ]
      }
     ],
     "prompt_number": 38
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 5.24, Page No. 229"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# output frequency(refer fig. 5.67 and 5.68)\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "V = 10                   # supply voltage\n",
      "R1 = 10*10**3            # Resistor R1\n",
      "R2 = 1.2*10**3           # Resistor R2\n",
      "R3 = 10*10**3            # Resistor R3\n",
      "C1 = 0.001*10**-6        # Capacitance\n",
      "Vc1 = 7.7                # Voltage at pin 5\n",
      "Vc2 = 9.5                # Voltage at pin 5\n",
      "\n",
      "#Calcualtions\n",
      "# (a)\n",
      "Vc = R3*V/(R2+R3)\n",
      "Vc = math.floor(Vc*1000)/1000\n",
      "fo = 2*(V-Vc)/(C1*R1*V) \n",
      "fo = fo/1000             # kHz\n",
      "# (b)\n",
      "fo1 = 2*(V-Vc1)/(C1*R1*V)\n",
      "fo1 = fo1/1000\n",
      "fo2 = 2*(V-Vc2)/(C1*R1*V)\n",
      "fo2 = fo2/1000\n",
      "\n",
      "#Result\n",
      "print(\"(a)\\nVc = %.3f V\\nfo = %.2f kHz\\n\\n(b)\\nfo1 = %.0f kHz\\nfo2 = %.0f kHz\\nChange in frequency is %.0f kHz\"%(Vc,fo,fo1,fo2,fo1-fo2))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        "Vc = 8.928 V\n",
        "fo = 21.44 kHz\n",
        "\n",
        "(b)\n",
        "fo1 = 46 kHz\n",
        "fo2 = 10 kHz\n",
        "Change in frequency is 36 kHz\n"
       ]
      }
     ],
     "prompt_number": 48
    }
   ],
   "metadata": {}
  }
 ]
}