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 '
# 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 '
# 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 '
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 '
# 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'
# 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 '
# 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 '
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 '
# 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 '
# 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 '
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 '