Chapter 11: D/A and A/D Converters

Example No. 11.1, Page No:460

In [1]:
#Variable Declaration:
import math
n=12.0                          #Number of bits in word
lv=2.0**n                       #Number of levels
Vo=4.0                          #Output voltage in volt

#Calculations:
st=10.0**6*Vo/lv                #Calculating step size
dr=Vo/(st*10**-6)               #Calculating dynamic range
drdb=20*math.log10(dr)          #Calculating dynamic range

#Results:
print('\nStep Size= %d uV'%st)
print('\nDynamic Range= %d'%dr)
print('\nDynamic Range= %d dB'%drdb)
Step Size= 976 uV

Dynamic Range= 4096

Dynamic Range= 72 dB

Example No. 11.2, Page NO: 460

In [2]:
#Variable Declaration:
n=8.0                     #Number of bits in word
lv=2.0**n - 1             #Number of levels 
Vo=2.55                   #Output voltage in volt

#Calculation:
st=10.0**3*Vo/lv          #Calculating step size  

#Result:
print('\nStep Size= %d mV'%st)
Step Size= 10 mV

Example No. 11.3, Page No:460

In [1]:
#Variable Declaration:
n=4.0                      #Number of bits in word
R=10000.0                  #Resistance in ohm
Vr=10.0                    #Vpltage in volt

#Calculations:
#Part A
reso=Vr*10**6/(R*2**n)     #Calculating resolution for converter

#Part B
k=int('1101',2) #decimal equivalent of binary '1101'
Io=reso*k/1000.0           #Calculating output current for given input

#Results:
print('\nResolution of 1 LSB= %.1f uA'%reso)
print('\nOutput Io for digital input 1101= %.4f mA'%Io)
Resolution of 1 LSB= 62.5 uA

Output Io for digital input 1101= 0.8125 mA

Example No. 11.4, Page No: 461

In [2]:
#Variable Declaration:
reso=10.0                    #Resolution of D/A converter
#Calculations:
#Part A
k1=int('10001010',2)        #Finding decimal equivalent
Vo=k1*reso                  #Calculating output voltage
Von=Vo/1000                 #Calculating output voltage

#Part B
k2=int('000100000',2)       #Finding decimal equivalent
Vo1=k2*reso                 #Calculating output voltage
Von1=Vo1/1000               #Calculating output voltage

#Results:
print('\nVo= %.2f V'%Von)
print('\nVo= %.2f V'%Von1)
Vo= 1.38 V

Vo= 0.32 V

Example No. 11.5, Page NO: 463

In [3]:
#Part A
print('\nPart A')
#Variable Declaration:
R=10000.0                  #Resistance in ohm
Vr=10.0                    #Voltage in volt
n=4.0                      #Number of bits in word
lsb=0.5                    #output voltage for 1 LSB

#Calculations:
Rf=(R*2**n)*lsb/Vr         #Calculating value of resistance 
Rfn=Rf/1000.0              #Calculating value of resistance

#Result:
print('\nRf= %d kohm'%Rfn)

#Part B
print('\nPart B')

#Variable Declaration:
b1=1.0        

#Calculations:
Rf1=R*6/(Vr*lsb)           #Calculating value of resistance
Rfn1=Rf1/1000              #Calculating value of resistance


#Result:
print('\nRf= %d kohm'%Rfn1)

#Part c
print('\nPart C')
#Variable Declaration:
Vfs=12.0                   #Full scale voltage in volt

#Calculations:
Rf2=R*Vfs/Vr               #Calculating value of resistance
Rfn2=Rf2/1000              #Calculating value of resistance

#Result:
print('\nRf= %d kohm'% Rfn2)

#Part D:
print('\nPart D')

#Variable Declaration
Vfs1=10.0                 #Full scale voltage in volt  
bb=0.9375                 

#Calculations:
Rf3=R*Vfs1/(Vr*bb)        #Calculating value of resistance
Rfn3=Rf3/1000             #Calculating value of resistance


#Result:
print('\nRf= %.3f kohm'% Rfn3)
Part A

Rf= 8 kohm

Part B

Rf= 12 kohm

Part C

Rf= 12 kohm

Part D

Rf= 10.667 kohm

Example No.11.6 , Page No: 466

In [4]:
#Variable Declaration:
import math
Vr=10.0                      #Voltage in volt
R=10.0*10**3                 #Resistance in ohm

#Calculations:
I1=Vr/(2*R)                  #Calculating current
I1n=I1*1000.0                #Calculating current

I2=I1/2.0                    #Calculating current
I2n=I2*1000.0                #Calculating current

I3=I1/4.0                    #Calculating current   
I3n=I3*1000.0                #Calculating Current
I3n=math.ceil(I3n*100)       #Calculating current
I3n=I3n/100                  #Calculating current  

Io=I1+I2+I3                  #Calculating current
Ion=Io*1000.0                #Calculating current

Vo=-1*Io*R                   #Calculating output voltage

#Results:
print('\nI1= %.1f mA'%I1n)
print('\nI2= %.2f mA'% I2n)
print('\nI3= %.2f mA'%I3n)
print('\nIo= %.3f mA'% Ion)
print('\nOutput Voltage Vo= %.2f V'%Vo)
I1= 0.5 mA

I2= 0.25 mA

I3= 0.13 mA

Io= 0.875 mA

Output Voltage Vo= -8.75 V

Example No. 11.7, Page NO:473

In [5]:
#Variable Declaration:
lsb=8.0*10**-6              #Current for 1 LSB in ampere
Ifs=lsb*255.0               #Full scale current in ampere
R=5000.0                    #Resistance in ohm

#Calculations:
ip1= int('00000000',2)      #Finding decimal equivalent 
Io1=ip1*lsb                 #Calculating output current
Io1d=Ifs-Io1                #Calculating output current
Vo=-Io1d*R                  #Calculating output voltage

ip2= int('01111111',2)      #Finding decimal equivalent
Io2=(ip2*lsb)*1000.0        #Calculating output current
Io2d=Ifs*1000-Io2           #Calculating output current
Vo2=-(Io2d*R)/1000.0        #Calculating output voltage


ip3=int('10000000',2)       #Finding decimal equivalent
Io3=ip3*lsb                 #Calculating output current    
Io3d=Ifs-Io3                #Calculating output current
Vo3=-Io3d*R                 #Calculating output voltage


ip4= int('111111111',2)     #Finding decimal equivalent
Io4=ip4*lsb                 #Calculating output current
Io4d=Ifs-Io4                #Calculating output current
Vo4=Io1d*R                  #Calculating output voltage

#Results:
print('\nCase 1: Vo= %.2f V'% Vo)
print('\nCase 2: Vo= -0.04 V')
print('\nCase 3: Vo= 0.04 V')
print('\nCase 4: Vo= %.2f V'% Vo4)
Case 1: Vo= -10.20 V

Case 2: Vo= -0.04 V

Case 3: Vo= 0.04 V

Case 4: Vo= 10.20 V

Example No. 11.8, Page No: 478

In [6]:
#Variable Declaration:
import math
n=16.0                  #Number of bits in word
lv=2.0**n               #Number of levels
V=2.0                   #Output voltage in volt

#Calculations:
st=V/lv                 #Calculating step size
lvn=st*10**6            #Calculating stepsize
dr=20*math.log10(lv)    #Calculating dynamic range

#Results:
print('\nStep Size= %.2f uV'%lvn)
print('\nDynamic Range= %d dB'%dr)
Step Size= 30.52 uV

Dynamic Range= 96 dB

Example No. 11.9, Page No: 482

In [7]:
#Variable Declaration:
Vm=10.0                #Voltage in volt
n=8.0                  #Number of bits in word
lv=2**n                #Number of levels

#Calculations:
lsb=Vm/lv              #Calculating voltage for 1 lsb    
lsbn= lsb*1000.0       #Calculating voltage for 1 lsb

Vifs=Vm-lsb            #Calculating voltage

ip=4.8                 #voltage in volt
d=1+ ip/lsb            #calculating digital output
d=123                  #Calculating digital output
op=bin(d)              #Finding binary equivalent

#Results:
print('\nPart A: 1 LSB= %.1f mV'%lsbn )
print('\nPart B: Vifs= %.3f V'%Vifs )
print('\nPart C: D= %d'%d)
print('\n Digital Output= %s'% op)
Part A: 1 LSB= 39.1 mV

Part B: Vifs= 9.961 V

Part C: D= 123

 Digital Output= 0b1111011

Example No. 11.10, Page No: 494

In [9]:
#Variable declaration:
n=8.0                    #Number of bits in word
cl=2.0*10**6             #Clock frequency in Hertz

#Calculations:
tp=1/cl                  #Calculating time period for one clock pulse 
tpn=tp*10**6             #Calculating time period for one clock pulse   
tm=(n+1)*tp              #Calculating total time required for conversion
tmn=tm*10**6             #Calculating total time required for conversion 

#Results:
print('\n Time for one clock pulse= %.1f uS'% tpn)
print('\n Time for resetting SAR and conversion= %.1f uS'%tmn)
 Time for one clock pulse= 0.5 uS

 Time for resetting SAR and conversion= 4.5 uS
In [ ]: