{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 10 : D-A and A-D Converters" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.1 Page No.357" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Given Data \n", "\n", "n = 9\n", "s = 10.3*10**-3\n", "a = '0b101101111'\n", "\n", "# Solution \n", "# Converting the given value into its equivalent decimal value\n", "x = int(a,2)\n", "#multiplying with the resolution to get the output\n", "\n", "V = round(x*s,2)\n", "\n", "print \"The output value will be =\",V,\"V\" \n", "\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The output value will be = 3.78 V\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.2 Page No.357" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from fractions import Fraction \n", "# Given data \n", "\n", "n = 8\n", "v = 10.0\n", "\n", "# Solution \n", "LSB = 1.0/2**n\n", "Vlsb =v/2**n\n", "MSB = v/2\n", "Vo = v - Vlsb\n", "\n", "# Dispalying the output\n", "\n", "print \"The value of LSB = \",Fraction(LSB).limit_denominator(256)\n", "print \"The voltage of LSB = \",int(Vlsb*10**3),\"mV\"\n", "print \"The MSB = \",int(MSB)\n", "print \"The value of full scale output is = \",round(Vo,3),\"V\"\n", " \n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The value of LSB = 1/256\n", "The voltage of LSB = 39 mV\n", "The MSB = 5\n", "The value of full scale output is = 9.961 V\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.3 Page No.357" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "V = 10.0 # Range of the DAC is 0 -10 voltage \n", "\n", "# define a function for performing the DAC action\n", "\n", "def DAC(Vo):\n", " j = 1\n", " sum = 0.0\n", " x = len(Vo)\n", " for i in range(x):\n", " sum = sum + ((Vo[i])*(0.5**j))\n", " j += 1\n", " \n", " return (V*sum)\n", "# part 1 \n", "Vo1 = np.array([1, 0])\n", "# part 2\n", "Vo2 = np.array([0, 1, 1, 0])\n", "#part 3\n", "Vo3 = np.array([1, 0, 1, 1, 1, 1, 0, 0])\n", "\n", "# Finding the solution for all 3 parts and printing the outputs \n", "\n", "print \" The output for part 1\",int(DAC(Vo1)),\"V\"\n", "print \" The output for part 2\",(DAC(Vo2)),\"V\"\n", "print \" The output for part 3\",round(DAC(Vo3),2),\"V\"\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " The output for part 1 5 V\n", " The output for part 2 3.75 V\n", " The output for part 3 7.34 V\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.4 Page No.365" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Given data \n", "n = 16 \n", "Clockrate = 4*10**6\n", "V = 10.0\n", "c = 0.1*10**-6\n", "va = -8.0\n", "\n", "# Solution \n", "\n", "t21 = (2.0**n)/(Clockrate)\n", "R = ((-V/va)*t21)/c\n", "\n", "print \"The value of (t2-t1) =\",round(t21*10**3,2),\"ms\"\n", "print \"The value of Resistor R =\",int(round(R*10**-3)),\"kilo Ohms\"\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The value of (t2-t1) = 16.38 ms\n", "The value of Resistor R = 205 kilo Ohms\n" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.5 Page No.365" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Given data \n", "\n", "Va = 4.129\n", "n = 16\n", "Vr = 8\n", "\n", "# Solution \n", "\n", "N = int(round((2**n)*(Va/Vr)))\n", "out = bin(N) # Converting the voltage value into its binary equivalent\n", "\n", "print \"The binary equivalent is = \",out\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The binary equivalent is = 0b1000010000100001\n" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 10.6 Page No.368" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Given data \n", "\n", "d = 3.5 \n", "print \"The last 3 digit can be\",000,\"To\",(10**int(d))-1\n", "print \"Hense the 3 1/2 digit DVM reading varies from\",0000,\"to\",\"1\"+str((10**int(d))-1)\n", "# Reference voltage is 2V\n", "Vref = 2.0\n", "# Resolution R \n", "\n", "R = Vref/2000\n", "print \"The resolution of a 3 1/2 digit DVM is =\",int(R*10**3),\"mV\"\n", "\n", "# Similarly for 4 1/2 digit DVM\n", "\n", "R1 = Vref/20000\n", "\n", "print \"Thus resolution of a 4 1/2 digit DVM is =\",R1*10**3,\"mV\"\n", "\n", "print \"So the resolution of 4 1/2 digit DVM is better than 3 1/2 digit DVM\"\n", " \n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The last 3 digit can be 0 To 999\n", "Hense the 3 1/2 digit DVM reading varies from 0 to 1999\n", "The resolution of a 3 1/2 digit DVM is = 1 mV\n", "Thus resolution of a 4 1/2 digit DVM is = 0.1 mV\n", "So the resolution of 4 1/2 digit DVM is better than 3 1/2 digit DVM\n" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }