# Chapter 11 Digital To Analog Converter(D/A Converter)¶

## Example 11.1 Pg 313¶

In :
from __future__ import division
from math import sqrt, pi
# to determine the full scale voltage of D/A
Vref = 12 #
Rf = 10 # # K ohm
R = 5 # # K ohm

# the full scale voltage of D/A converter
VFS = Vref*(Rf/R) #
print 'the full scale voltage of D/A converter VFS is = %0.2f'%VFS,' V '

the full scale voltage of D/A converter VFS is = 24.00  V


## Example 11.2 Pg 313¶

In :
 # determine the output voltage of D/A converter for the binary inputs a) 10101010  b) 11001100  c) 11101110 d) 00010001
Del = 12*10**-3 #  # mA

# the input voltage of D/A converter
#Vo = Del*binary input (BI)

# For BI 10101010 the output
BI = '10101010' #
BI = int(BI,2)#
Vo = Del*BI #
print 'For BI 10101010 the output of D/A converter is = ',Vo,' V '

# For BI 11001100 the output
BI = '11001100' #
BI = int(BI,2)#
Vo = Del*BI #
print 'For BI 11001100 the output of D/A converter is = ',Vo,' V '

# For BI 11101110 the output
BI = '11101110' #
BI = int(BI,2)#
Vo = Del*BI #
print 'For BI 11101110 the output of D/A converter is = ',Vo,' V '

# For BI 00010001 the output
BI = '00010001' #
BI = int(BI,2)#
Vo = Del*BI #
print 'For BI 00010001 the output of D/A converter is = ',Vo,' V '

For BI 10101010 the output of D/A converter is =  2.04  V
For BI 11001100 the output of D/A converter is =  2.448  V
For BI 11101110 the output of D/A converter is =  2.856  V
For BI 00010001 the output of D/A converter is =  0.204  V


## Example 11.3 Pg 314¶

In :
# determine the resolution of 4-bit D/A converter
VFS = 12.0 #
N = 4.0 #

# the resolution of 4-bit D/A converter is defined as
Resolution = VFS/(2**N-1) #
print 'the resolution of 4-bit D/A converter is = %0.2f'%Resolution,' V '

the resolution of 4-bit D/A converter is = 0.80  V


## Example 11.4 314¶

In :
from __future__ import division
from math import log10
# determine the number of bit required to design a 4-bit D/A converter
VFS = 5 #
Resolution = 10*10**-3 # # A

# the resolution of 4-bit D/A converter is defined as
# Resolution = VFS/(2**N-1) #
N = (VFS/Resolution)+1 #
N = log10(N)/log10(2)#
print 'the number of bit required to design a 4-bit D/A converter is = %0.2f'%N,'   = 9 '

the number of bit required to design a 4-bit D/A converter is = 8.97    = 9


## Example 11.5 Pg 315¶

In :
# determine the analog output voltage
Vref = 12  #
BI = 101 #   BI = 111 #   BI = 011 # BI = 001 #  BI = 100 #
Rf = 40*10**3 #
R = 0.25*Rf #

# The output voltage of given binary weighted resistor D/A converter is defined as

# Vo = -(Rf*Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2) #

# Vo = -(Rf*Vref/R)*(b0+2**-1*b1+2**-2*b2) #

# for the given value Rf,R and Vref the output voltage

# Vo = -48*(b0+2**-1*b1+2**-2*b2) #

# for the binary input 101 analog output is
b2 = 1 #
b1 = 0 #
b0 = 1 #
Vo = -48*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 101 analog output is = %0.2f'%Vo,' V '

# for the binary input 111 analog output is
b2 = 1 #
b1 = 1 #
b0 = 1 #
Vo = -48*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 111 analog output is = %0.2f'%Vo,' V '

# for the binary input 011 analog output is
b2 = 0 #
b1 = 1 #
b0 = 1 #
Vo = -48*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 011 analog output is = %0.2f'%Vo,' V '

# for the binary input 001 analog output is
b2 = 0 #
b1 = 0 #
b0 = 1 #
Vo = -48*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 001 analog output is = %0.2f'%Vo,' V '

# for the binary input 100 analog output is
b2 = 1 #
b1 = 0 #
b0 = 0 #
Vo = -48*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 100 analog output is = %0.2f'%Vo,' V'

for the binary input 101 analog output is = -60.00  V
for the binary input 111 analog output is = -84.00  V
for the binary input 011 analog output is = -72.00  V
for the binary input 001 analog output is = -48.00  V
for the binary input 100 analog output is = -12.00  V


## Example 11.6 Pg 316¶

In :
# determine the analog output voltage and feed back current If
Vref = 12  #
BI = 1001 #   BI = 1101 #   BI = 1010 # BI = 0011 #
Rf = 25 #  # K ohm
R = 0.25*Rf #

# The output voltage of given binary weighted resistor D/A converter is defined as

# Vo = -(Rf*Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# Vo = -(Rf*Vref/R)*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# for the given value Rf,R and Vref the output voltage

# Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# for the binary input 1001 analog output is
b3 = 1 #
b2 = 0 #
b1 = 0 #
b0 = 1 #
Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1001 analog output is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 1101 analog output is
b3 = 1 #
b2 = 1 #
b1 = 0 #
b0 = 1 #
Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1101 analog output is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 1010 analog output is
b3 = 1 #
b2 = 0 #
b1 = 1 #
b0 = 0 #
Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1010 analog output is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 0011 analog output is
b3 = 0 #
b2 = 0 #
b1 = 1 #
b0 = 1 #
Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 0011 analog output is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

for the binary input 1001 analog output is = -67.50  V
the feedback current If is = 2.70  mA
for the binary input 1101 analog output is = -82.50  V
the feedback current If is = 3.30  mA
for the binary input 1010 analog output is = -37.50  V
the feedback current If is = 1.50  mA
for the binary input 0011 analog output is = -90.00  V
the feedback current If is = 3.60  mA


## Example 11.7 Pg 319¶

In :
# determine the feed back current If and analog output voltage
Vref = 8  #   # V
BI = 001 #
BI = 010 #
BI = 110 #
Rf = 25*10**3 # # Hz
R = 0.2*Rf #

# The output current of given binary weighted resistor D/A converter is defined as

# If = -(Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2) #

# If = -(Vref/R)*(b0+2**-1*b1+2**-2*b2) #

# for the given value Rf,R and Vref the output current

# If = -(1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #

# for the binary input 001 the feedback current If is given by
b2 = 0 #
b1 = 0 #
b0 = 1 #
If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 001 analog output is = %0.2f'%(If*1000),' mA '

# An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.2f'%Vo,' V '

# for the binary input 010 the feedback current If is given by
b2 = 0 #
b1 = 1 #
b0 = 0 #
If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 010 analog output is = %0.2f'%(If*1000),' mA'

# the An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.2f'%Vo,' V '

# for the binary input 110 the feedback current If is given by
b2 = 1 #
b1 = 1 #
b0 = 0 #
If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 110 analog output is = %0.2f'%(If*1000),' mA '

# the An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.2f'%Vo,' V '

for the binary input 001 analog output is = 1.60  mA
An analog output voltage Vo is = -40.00  V
for the binary input 010 analog output is = 0.80  mA
An analog output voltage Vo is = -20.00  V
for the binary input 110 analog output is = 1.20  mA
An analog output voltage Vo is = -30.00  V


## Example 11.8 Pg 320¶

In :
from __future__ import division
# determine the feed back current If and analog output voltage
Vref = 5  #
BI = 101 #   BI = 011 #   BI = 100 #  BI = 001 #
Rf = 25*10**3 #
R = 0.2*Rf #

# The output current of given R-2R ladder D/A converter is defined as

# If = -(Vref/2*R)*(2**0*b0+2**-1*b1+2**-2*b2) #

# If = -(Vref/2*R)*(b0+2**-1*b1+2**-2*b2) #

# for the given value Rf,R and Vref the output current

# If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #

# for the binary input 101 the feedback current If is given by
b2 = 1 #
b1 = 0 #
b0 = 1 #
If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 101 analog output is = %0.3f'%(If*1e3),' mA '

# An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.3f'%Vo,' V '

# for the binary input 011 the feedback current If is given by
b2 = 0 #
b1 = 1 #
b0 = 1 #
If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 011 analog output is = %0.2f'%(If*1e3),' mA'

# the An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.3f'%Vo,' V '

# for the binary input 100 the feedback current If is given by
b2 = 1 #
b1 = 0 #
b0 = 0 #
If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 100 analog output is = %0.3f'%(If*1e3),'mA '

# the An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.2f'%Vo,' V '

# for the binary input 001 the feedback current If is given by
b2 = 0 #
b1 = 0 #
b0 = 1 #
If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #
print 'for the binary input 001 analog output is = %0.1f'%(If*1e3),' mA '

# the An analog output voltage Vo is
Vo = -If*Rf #
print 'An analog output voltage Vo is = %0.2f'%Vo,' V '

for the binary input 101 analog output is = 0.625  mA
An analog output voltage Vo is = -15.625  V
for the binary input 011 analog output is = 0.75  mA
An analog output voltage Vo is = -18.750  V
for the binary input 100 analog output is = 0.125 mA
An analog output voltage Vo is = -3.12  V
for the binary input 001 analog output is = 0.5  mA
An analog output voltage Vo is = -12.50  V


## Example 11.9 Pg 322¶

In :
 # determine the analog output voltage and feed back current If
Vref = 10  #
BI = 1001 #   BI = 1100 #   BI = 1010 # BI = 0011 #
Rf = 50 #  # K ohm
R = 0.4*Rf #

# The output voltage of given R-2R ladder D/A converter is defined as

# Vo = -(Rf*Vref/2R)*(2**0*b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# Vo = -(Rf*Vref/2R)*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# for the given value Rf,R and Vref the output voltage

# Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #

# for the binary input 1001 analog output is
b3 = 1 #
b2 = 0 #
b1 = 0 #
b0 = 1 #
Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1001 analog output is = %0.4f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 1100 analog output is
b3 = 1 #
b2 = 1 #
b1 = 0 #
b0 = 0 #
Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1100 analog output is = %0.4f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 1010 analog output is
b3 = 1 #
b2 = 0 #
b1 = 1 #
b0 = 0 #
Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 1010 analog output is = %0.4f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.2f'%If,' mA '

# for the binary input 0011 analog output is
b3 = 0 #
b2 = 0 #
b1 = 1 #
b0 = 1 #
Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #
print 'for the binary input 0011 analog output is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.3f'%If,' mA '

for the binary input 1001 analog output is = -14.0625  V
the feedback current If is = 0.28  mA
for the binary input 1100 analog output is = -4.6875  V
the feedback current If is = 0.09  mA
for the binary input 1010 analog output is = -7.8125  V
the feedback current If is = 0.16  mA
for the binary input 0011 analog output is = -18.75  V
the feedback current If is = 0.375  mA


## Example 11.10 Pg 324¶

In :
 # determine the analog output voltage and feed back current If
Vref = 15  #
BI = 1000 #
Rf = 40 #  # K ohm
R = 0.4*Rf #

# by using voltage divider rule Vin can be calculated as
Vin = -(Vref*2*R)/(2*R+2*R) #

# The output voltage of given R-2R ladder D/A converter is defined as

# Vo = -(Rf*Vin/R)

Vo = (Vref*Rf)/(2*R)
print 'for the binary input 1000 output voltage is = %0.2f'%Vo,' V '

# the feedback current If is given by
If = -(Vo/Rf) #
print 'the feedback current If is = %0.3f'%If,' mA '

for the binary input 1000 output voltage is = 18.75  V
the feedback current If is = -0.469  mA


## Example 11.11 Pg 326¶

In :
from __future__ import division
# to find the resolution and analog output voltage of 8-bit D/A converter
VFS = 10 #
N = 8 #
BI = 10101111 #
BI = 11100011 #
BI = 00101001 #
BI = 01000110

# the resolution of 8-bit D/A converter is defined as
Resolution = VFS/(2**N-1) #

# An analog output voltage of D/A converter is given by
# Vo = Resolution*(2**-0*b0+2**-1*b1+....+2**-N*bn-1)
# Vo = Resolution*(2**-0*b0+2**-1*b1+2**-2*b2+2**-3*b3+2**-4*b4+2**-5*b5+2**-6*b6+2**-7*b7)#

# For the BI 10101111 output analog voltage is
BI = '10101111'#
BI = int(BI,2)#
Vo = Resolution*BI #
print 'For the BI 10101111 output analog voltage is = %0.2f'%Vo,' V '

# For the BI 11100010 output analog voltage is
BI = '11100010'#
BI = int(BI,2)#
Vo = Resolution*BI #
print 'For the BI 11100010 output analog voltage is = %0.4f'%Vo,' V '

# For the BI 00101001 output analog voltage is
BI = '00101001'#
BI = int(BI,2)#
Vo = Resolution*BI #
print 'For the BI 00101001 output analog voltage is = %0.4f'%Vo,' V '

# For the BI 01000110 output analog voltage is
BI = '01000110'#
BI = int(BI,2)#
Vo = Resolution*BI #
print 'For the BI 01000110 output analog voltage is = %0.3f'%Vo,' V '

For the BI 10101111 output analog voltage is = 6.86  V
For the BI 11100010 output analog voltage is = 8.8627  V
For the BI 00101001 output analog voltage is = 1.6078  V
For the BI 01000110 output analog voltage is = 2.745  V