{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter2 - Digital to Analog Converters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 2_9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input resistance (kohm) =  12.5\n",
      "feedback resistance (kohm) =  10.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_1,pg 2_9\n",
    "#calculate the input resistance and feedback resistance\n",
    "#given\n",
    "Vr=10.\n",
    "n=4.\n",
    "Res=0.5#resolution\n",
    "Rf=10*10**3\n",
    "#calculations\n",
    "Rt=Vr/((2**n)*Res)\n",
    "R=Rt*Rf\n",
    "#results\n",
    "print \"input resistance (kohm) = \",R/1000.\n",
    "print \"feedback resistance (kohm) = \",Rf/1000."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 2_11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "resolution through method-1 =  256\n",
      "resolution through method-2 (mV) =  10.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_2,pg 2_11\n",
    "#calculate the resolution through both methods\n",
    "#given\n",
    "n=8\n",
    "Vofs=2.55#full scale output voltage\n",
    "#calculations\n",
    "Res1=2**n\n",
    "Res2=Vofs/(Res1-1)\n",
    "#results\n",
    "print \"resolution through method-1 = \",Res1\n",
    "print \"resolution through method-2 (mV) = \",Res2*1000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 2_12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output voltage (V) =  6.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_3,pg 2_12\n",
    "#calculate the output voltage\n",
    "#given\n",
    "n=4.\n",
    "Vofs=15.\n",
    "#calculations\n",
    "Res=Vofs/((2**n)-1)\n",
    "D=int('0110',base=2)#decimal equivalent\n",
    "Vo=Res*D\n",
    "#results\n",
    "print\"output voltage (V) = \",Vo\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 2_12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output voltage (V) =  2.56\n",
      "full scale output voltage (V) =  5.1\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_4,pg 2_12\n",
    "#calculate the output voltage\n",
    "#given\n",
    "Res=20*10**-3\n",
    "n=8\n",
    "#calculations\n",
    "Vofs=Res*((2**n)-1)\n",
    "D=int('10000000',base=2)\n",
    "Vo=Res*D\n",
    "print\"output voltage (V) = \",Vo\n",
    "print\"full scale output voltage (V) = \",Vofs\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 2_12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output voltage1 (V) =  2.6667\n",
      "output voltage2 (V) =  5.0\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_5,pg 2_12\n",
    "#calculate the output voltage\n",
    "#given\n",
    "n=4.\n",
    "Vofs=5.\n",
    "#calculations\n",
    "Res=Vofs/((2**n)-1)\n",
    "D1=int('1000',base=2)\n",
    "Vo1=Res*D1\n",
    "D2=int('1111',base=2)\n",
    "Vo2=Res*D2\n",
    "#results\n",
    "print\"output voltage1 (V) = \",round(Vo1,4)\n",
    "print\"output voltage2 (V) = \",Vo2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 2_13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full scale output voltage (V) =  32.76\n",
      "percentage resolution =  0.02442\n",
      "output voltage (V) =  11.112\n"
     ]
    }
   ],
   "source": [
    "#Chapter-2,Example2_6,pg 2_13\n",
    "#calculate the full scale output voltage, percentage resolution\n",
    "#given\n",
    "n=12.\n",
    "Res=8.*10**-3\n",
    "#calculations\n",
    "Vofs=Res*((2**n) -1)\n",
    "perR=Res/Vofs*100.\n",
    "Vo=Res*int('010101101101',base=2)\n",
    "#results\n",
    "print \"Full scale output voltage (V) = \",Vofs\n",
    "print\"percentage resolution = \",round(perR,5)\n",
    "print\"output voltage (V) = \",Vo\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}