{
 "metadata": {
  "name": "",
  "signature": "sha256:f64bf7a670dc36e359e5aa56e0bfa29f09c70f7a0babc95be4c64434f164d9d6"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter10 - Comparators"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 10.1 - page : 334"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import pi, sin\n",
      "t=range(0,5) #sec(Assumed)\n",
      "Vin=5*sin(2*pi*t[0]) #V\n",
      "VCC=15 #V\n",
      "R2=1 #kohm\n",
      "R1=6.8 #kohm\n",
      "VEE=-15 #V\n",
      "Vsat=13 #V\n",
      "Vref=R2*VCC/(R1+R2) #V\n",
      "print \"Reference Voltage = %0.2f V \" %Vref\n",
      "print \"If Vin>Vref , Vout = %0.2f V \" %Vsat \n",
      "print \"If Vin<Vref , Vout = %0.2f V \" %-Vsat"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Reference Voltage = 1.92 V \n",
        "If Vin>Vref , Vout = 13.00 V \n",
        "If Vin<Vref , Vout = -13.00 V \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 10.2 - page 340"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Vsat=7 #V\n",
      "R1=68 #kohm\n",
      "R2=82 #kohm\n",
      "VUTP=R2*Vsat/(R1+R2) #V\n",
      "VLTP=R2*-Vsat/(R1+R2) #V\n",
      "print \"Upper trip point = %0.2f V \" %VUTP \n",
      "print \"Lower trip point = %0.2f V \" %VLTP"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Upper trip point = 3.83 V \n",
        "Lower trip point = -3.83 V \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 10.3 - page : 340"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from numpy import arcsin, pi\n",
      "#Vin=5*sin(omega*t)\n",
      "Vm=5 #V\n",
      "Vsat=7 #V\n",
      "R1=68 #kohm\n",
      "R2=82 #kohm\n",
      "VUTP=R2*Vsat/(R1+R2) #V\n",
      "fi=arcsin(VUTP/Vm)*180/pi #degree\n",
      "print \"Phase shift = %0.2f degree \" %fi \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Phase shift = 49.94 degree \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 10.4 - page : 344"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "VZ1=4.7 #V\n",
      "VZ2=4.7 #V\n",
      "R1=68 #kohm\n",
      "R2=15 #kohm\n",
      "Vout=VZ1+0.7 #V(As one zener diode is always forward biased)\n",
      "VR1=Vout #V\n",
      "IR1=VR1/R1*1000 #micro A\n",
      "IR2=IR1 #micro A\n",
      "VR2=IR2*10**-3*R2 #V\n",
      "Vout=VR1+VR2 #V\n",
      "VUTP=(R2/(R1+R2))*Vout #V\n",
      "VLTP=(R2/(R1+R2))*(-Vout) #V\n",
      "print \"VUTP = %0.2f V \" %VUTP \n",
      "print \"VLTP = %0.2f V \" %VLTP"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "VUTP = 1.19 V \n",
        "VLTP = -1.19 V \n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 10.5 - page : 346"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Vsat=12.5 #V\n",
      "Vref=-12.5 #V\n",
      "R1=80 #kohm\n",
      "R2=20 #kohm\n",
      "Beta=R2/(R1+R2) #unitless\n",
      "UTP=Beta*Vsat+(1-Beta)*Vref #V\n",
      "LTP=-Beta*Vsat+(1-Beta)*Vref #V\n",
      "VH=UTP-LTP #V\n",
      "R3=R1*R2/(R1+R2) #kohm\n",
      "print \"UTP = %0.2f V \" %UTP \n",
      "print \"LTP = %0.2f V \" %LTP \n",
      "print \"Hysteresis Voltage, VH = %0.2f V \" %VH \n",
      "print \"Use R3 = %0.2f kohm \" %R3 "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "UTP = -7.50 V \n",
        "LTP = -12.50 V \n",
        "Hysteresis Voltage, VH = 5.00 V \n",
        "Use R3 = 16.00 kohm \n"
       ]
      }
     ],
     "prompt_number": 16
    }
   ],
   "metadata": {}
  }
 ]
}