Chapter 14:Digital to analog Converters

Example 14.1 Page no 403

In [3]:
#Given
n=8            #An 8-bit DAC wire
V1=0           #Voltage range
V2=5.12

#Calculation
R=2**n
dvo=V2/R
Vfs=V2*(1-1/R)

#Result
print"(a)The resolution is",R
print"(b)The output change per bit is",dvo*1000,"mV/bit"
print"(c)the ideal full scale output voltage is",Vfs,"V"
(a)The resolution is 256
(b)The output change per bit is 20.0 mV/bit
(c)the ideal full scale output voltage is 5.12 V

Example 14.2 Page no 404

In [4]:
#Given
Res=20        #mV/bit
#From the given code  00010110 and 10000000
#The binary weighted code for unipolar operation
b7=0
b6=0
b5=0
b4=1
b3=0
b2=1
b1=1
b0=0
#For part (b)
b7_=1
b6_=0
b5_=0
b4_=0
b3_=0
b2_=0
b1_=0
b0_=0

#Calculation
D=b7*2**7+b6*2**6+b5*2**5+b4*2**4+b3*2**3+b2*2**2+b1*2**1+b0*2**0
Vo=D*Res*10**-3
D_=b7_*2**7+b6_*2**6+b5_*2**5+b4_*2**4+b3_*2**3+b2_*2**2+b1_*2**1+b0_*2**0
Vo_=D_*Res*10**-3

#Resul
print"(a)The output voltage is",Vo,"V"
print"(b)The output voltage is",Vo_,"V"
(a)The output voltage is 0.44 V
(b)The output voltage is 2.56 V

Example 14.3 Page no 404

In [6]:
#Given
#From Example 14.1
n=8            #An 8-bit DAC wire
V1=0           #Voltage range
V2=5.12

#Calculation
dvo=2*V2/2**n    

#Result
print"The full scale  output voltage range",dvo*1000,"V"
The full scale  output voltage range 40.0 V

Example 14.4 Page no 405

In [9]:
#Given
Vref=10.24          #V, input ref voltage
p=0.05              #Percentage error
n=12                #12 bit unipolar DAC

#Calculation
Voff=0.05/100*Vref
dvo=Vref/(2**n)
a=Voff/dvo

#REsult
print"The offset voltage is",Voff*1000,"mV"
print"Interms of least significant bit(s) it is",dvo*1000,"mV/bit"
The offset voltage is 5.12 mV
Interms of least significant bit(s) it is 2.5 mV/bit

Example 14.5 Page no 407

In [7]:
#Given
n=8.0           #8-bit DAC
error=0.2     #percent
Vref=5.12     #V
Vos=0

#Calculation
V11=(((-error/100.0))+1)*(Vref)+Vos

#REsult
print"The minimum output voltage is",round(V11,1),"V"
The minimum output voltage is 5.1 V

Example 14.6 Page no 411

In [2]:
#Given
n=4.0            #4 bit resistance ladder
R=10.0           #kohm
Vref=10.0        #V

#Calculation
Res=Vref/(2**n*R*10**3)

#From dicimal value of binary 1111
D=15
Iout=Res*D

#Result
print"The resolution of 1 LSB is",Res*10**6,"microA"
print"output current is",Iout*1000,"microA"
The resolution of 1 LSB is 62.5 microA
output current is 0.9375 microA

Example 14.7 Page no 412

In [23]:
#Given
Io=62.5             #microA,  from ex. 14.6
Rf=10               #kohm , from fig.14.7
Vref=10             #V, reference voltage
R=Rf
n=4                 #no of bits

#Calculation
VR=Io*Rf*10**-3
D=15               #For a digital input of 1111
Vo=-VR*D

#REsult
print"The voltage resolution of 1 LSB is",VR,"V"
print"When digital input is 1111 , Vo is",Vo,"V"
The voltage resolution of 1 LSB is 0.625 V
When digital input is 1111 , Vo is -9.375 V

Example 14.8 Page no 416

In [30]:
#Given
Vref=10.0            #V, from fig. 14.8.  reference voltage
Rref=5.0            #kohm
n=8.0                #no of bits

#Calculation
Iref=Vref/Rref
I=Vref/(Rref*2**n)

#Result
print"The ladder input current is",Iref,"mA"
print"Current value of 1 LSB is",round(I*1000,3),"microA"
The ladder input current is 2.0 mA
Current value of 1 LSB is 7.813 microA

Example 14.9 Page no 417

In [35]:
#Given
I=7.812          #Current resolution from ex 14.8


#Calculation
Ifs=I*10**-3*255    #From eq. 14-15(a)
#The value of D for part (a),(b),(c)
D1=1            #for digital input 00000001
D2=128		#for digital input 10000000
D3=255		#for digital input 11111111
Iout1=I*D1
Iout2=I*D2
Iout3=I*D3
Iout_1=Ifs-Iout1*10**-3
Iout_2=Ifs-Iout2*10**-3
Iout_3=Ifs-Iout3*10**-3

#Result
print"(a) The Iout is",Iout1,"mA and Iout_ is",round(Iout_1,3),"mA"
print"(b) The Iout is",Iout2,"mA and Iout_ is",round(Iout_2,3),"mA"
print"(c) The Iout is",Iout3,"mA and Iout_ is",Iout_3,"mA"
(a) The Iout is 7.812 mA and Iout_ is 1.984 mA
(b) The Iout is 999.936 mA and Iout_ is 0.992 mA
(c) The Iout is 1992.06 mA and Iout_ is 0.0 mA

Example 14.10 Page no 417

In [43]:
#Given
#From fig 14.8 (a)
Vref=10         #V
Rf=5		#kohm
Rref=5.0		#kohm
n=8		#

#Calculation
VR=Vref*Rf/(Rref*2**n)
D1=1		#Value of D for 00000001
D2=255		#Value of D for 11111111
Vo1=VR*1000*D1
Vo2=VR*1000*D2

#Result
print"(a) Vo is ",round(Vo1,0),"V"
print"(b) Vo is ",round(Vo2/1000,3),"V"
(a) Vo is  39.0 V
(b) Vo is  9.961 V

Example 14.11 Page no 418

In [35]:
#Given
#From fig 14.9(a)
I=8             #microA,  value of 1 LSB
Rf=5		# kohm

#Calculation
#from eq 14-15(a)
Ifs=I*10**-3*255
D1=0 		#Value of D for 00000000
Iout1=I*D1
Iout_1=Ifs-Iout1
Vo1=(Iout1-Iout_1)*Rf

D2=127           #From digital value(b)
Iout2=I*D2
Iout_2=Ifs-Iout2/1000.0
Vo2=(Iout2/1000.0-Iout_2)*Rf

D3=128 		#Value of D for 00000000
Iout3=I*D3
Iout_3=Ifs-Iout3/1000.0
Vo3=(Iout3/1000.0-Iout_3)*Rf

D4=255 		#Value of D for 00000000
Iout4=I*D4
Iout_4=Ifs-Iout4/1000
Vo4=(Iout4/1000-Iout_4)*Rf

#Result
print"(a)Vo is ",Vo1,"V . (b)Vo is ",round(Vo2,3),"V. (c)Vo is ",Vo3,"V .(d)Vo is ",round(Vo4,0),"V"
 2.04
(a)Vo is  -10.2 V . (b)Vo is  -0.04 V. (c)Vo is  0.04 V .(d)Vo is  10.0 V