#Ex 6.1
n=8 #no. of bits
V1=0 #V
V2=5.12 #V
Res=2**n #resolution
print Res," =(a) Resolution"
delVo=(V2-V1)/Res*1000 #mV/bit
print int(delVo)," =(b) Output change per bit(mV/bit) "
VFS=V2*(1-1/2**n) #V
print round(VFS,1)," =(c) Full scale Output voltage(V) "
#Ex 6.2
import math
step=10.3 #mV
reading='101101111' #reading
Vo=step*int(reading,2)/1000 #V
print round(Vo,2)," = Output voltage(V) "
#Ex 6.3
n=8.0 #no. of bits
V=10 #volts
LSB=V*1/2**n #V
MSB=V*1/2**0 #V
VFS=MSB-LSB #V
print int(LSB*1000)," = LSB(mV) "
print MSB," = MSB(V) "
print round(VFS,3)," = VFS(V) "
#Ex 6.4
import math
#(i)2-bit DAC
n=2.0 #no. of bits
V=10.0 #max Voltage
step=V/2**n #V
reading='10' #input in binary
Vo=step*int(reading,2) #V
print Vo," =(i) Output Voltage(V) "
#(ii)4-bit DAC
n=4.0 #no. of bits
step=V/2**n #V
reading='0110' #input in binary
Vo=step*int(reading,2) #V
print Vo," =(ii) Output Voltage(V) "
#(i)8-bit DAC
n=8.0 #no. of bits
step=V/2**n #V
reading='10111100' #input in binary
Vo=step*int(reading,2) #V
print round(Vo,2)," =(iii) Output Voltage(V) "
#Ex 6.5
import math
n=8.0 #no. of bits
Res=20.0 #mV/bit(Resolution)
reading='00010110' #input in binary
Vo=Res*int(reading,2) #V
print Vo/1000," =(a) Output Voltage(V) "
reading='10000000' #input in binary
Vo=Res*int(reading,2) #V
print Vo/1000," =(b) Output Voltage(V) "
#Ex 6.6
n=12 #no. of bits
Eoff=0.05 #% #maximum offset error
Vref=10.24 #V
Voffset=Eoff/100*Vref #V
print int(Voffset*1000)," =(a) Offset voltage(mV) "
delVo=Vref/2**n #V/bit
Voff_dash=Voffset/delVo #in terms of LSB
print int(Voff_dash)," =(b) Offset voltage in terms of LSB "
#Ex 6.7
n=8 #no. of bits
E=0.2 #% #maximum gain error
Vref=5.1 #V
V11=(100-E)*Vref/100 #V
print V11," =Minimum output voltage(V) "
#Ex 6.8
n=8.0 #no. of bits
V=10.0 #V maximum
Vin=5.2 #V
oneLSB=V/2**n #V
print round(oneLSB*1000,1)," =(a) Minimum voltage for 1 LSB in mV "
Vifs=round(V-oneLSB,3) #V
print Vifs," =(b) For all ones input voltage should be (V) "
D=Vin/oneLSB #Digital output in decimal
print int(D)," =(c) Digital Output "
#Ex 6.9
n=8 #no. of bits
f=1 #MHz(Clock frequency)
TC=1/f*(n+1) #seconds
print TC," = time in micro seconds "