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