Chapter 10 : D-A and A-D Converters

Example 10.1 Page No.357

In [1]:
# Given Data 

n = 9
s = 10.3*10**-3
a = '0b101101111'

# Solution 
# Converting the given value into its equivalent decimal value
x = int(a,2)
#multiplying with the resolution to get the output

V = round(x*s,2)

print "The output value will be =",V,"V" 
The output value will be = 3.78 V

Example 10.2 Page No.357

In [2]:
from fractions import Fraction 
# Given data 

n = 8
v = 10.0

# Solution 
LSB = 1.0/2**n
Vlsb =v/2**n
MSB = v/2
Vo = v - Vlsb

# Dispalying the output

print "The value of LSB                  = ",Fraction(LSB).limit_denominator(256)
print "The voltage of LSB                = ",int(Vlsb*10**3),"mV"
print "The MSB                           = ",int(MSB)
print "The value of full scale output is = ",round(Vo,3),"V"
     
The value of LSB                  =  1/256
The voltage of LSB                =  39 mV
The MSB                           =  5
The value of full scale output is =  9.961 V

Example 10.3 Page No.357

In [1]:
import numpy as np
V = 10.0                 # Range of the DAC is 0 -10 voltage 

# define a function for performing the DAC action

def DAC(Vo):
    j = 1
    sum = 0.0
    x = len(Vo)
    for i in range(x):
        sum = sum + ((Vo[i])*(0.5**j))
        j += 1
    
    return (V*sum)
# part 1 
Vo1 = np.array([1, 0])
# part 2
Vo2 = np.array([0, 1, 1, 0])
#part 3
Vo3 = np.array([1, 0, 1, 1, 1, 1, 0, 0])

# Finding the solution for all 3 parts and printing the outputs 

print " The output for part 1",int(DAC(Vo1)),"V"
print " The output for part 2",(DAC(Vo2)),"V"
print " The output for part 3",round(DAC(Vo3),2),"V"
 The output for part 1 5 V
 The output for part 2 3.75 V
 The output for part 3 7.34 V

Example 10.4 Page No.365

In [3]:
#Given data 
n = 16 
Clockrate = 4*10**6
V = 10.0
c = 0.1*10**-6
va = -8.0

# Solution 

t21 = (2.0**n)/(Clockrate)
R = ((-V/va)*t21)/c

print "The value of (t2-t1)    =",round(t21*10**3,2),"ms"
print "The value of Resistor R =",int(round(R*10**-3)),"kilo Ohms"
The value of (t2-t1)    = 16.38 ms
The value of Resistor R = 205 kilo Ohms

Example 10.5 Page No.365

In [4]:
# Given data 

Va = 4.129
n = 16
Vr = 8

# Solution 

N = int(round((2**n)*(Va/Vr)))
out = bin(N)    # Converting the voltage value into its binary equivalent

print "The binary equivalent is = ",out
The binary equivalent is =  0b1000010000100001

Example 10.6 Page No.368

In [5]:
# Given data 

d = 3.5 
print "The last 3 digit can be",000,"To",(10**int(d))-1
print "Hense the 3 1/2 digit DVM reading varies from",0000,"to","1"+str((10**int(d))-1)
# Reference voltage is 2V
Vref = 2.0
# Resolution R 

R = Vref/2000
print "The resolution of a 3 1/2 digit DVM is =",int(R*10**3),"mV"

# Similarly for 4 1/2 digit DVM

R1 = Vref/20000

print "Thus resolution of a 4 1/2 digit DVM is =",R1*10**3,"mV"

print "So the resolution of 4 1/2 digit DVM is better than 3 1/2 digit DVM"
 
The last 3 digit can be 0 To 999
Hense the 3 1/2 digit DVM reading varies from 0 to 1999
The resolution of a 3 1/2 digit DVM is = 1 mV
Thus resolution of a 4 1/2 digit DVM is = 0.1 mV
So the resolution of 4 1/2 digit DVM is better than 3 1/2 digit DVM
In [ ]: