CHAPTER 5: DIGITAL INSTRUMENT BASICS

Example 5-1, Page Number: 120

In [2]:
import math

#Variable Declaration

Vcc=5                #in V
R1=1*10**3           #in ohm 
Vd=0.7               #Diode voltage in V
I0=1*10**-3          #High output current in A
Vilow=0              #Low input voltage

#Calculation
Voh=Vcc-I0*R1
Vol=Vilow+Vd

print "High output voltage(Voh)=",Voh,"V"
print "Low output voltage(Vol)=",Vol,"V"
High output voltage(Voh)= 4.0 V
Low output voltage(Vol)= 0.7 V

Example 5-2, Page Number: 121

In [31]:
import math

#Variable Declaration

Vbe=0.7                 #Base emitter voltage in V
Vce_sat=0.2             #Saturation voltage in V
R1=15*10**3             #in ohm
R2=27*10**3             #in ohm
Vcc=5                   #in V
Vbb=-5                  #in V
Rc1=2.7*10**3           #in ohm
R11=15*10**3            #in ohm
R21=27*10**3            #in ohm

#Calculation
#With Q2 on,
Vc2=Vce_sat             #Q2 is ON  
Vr1r2=Vc2-Vbb           #KVL
Vr1=R1*Vr1r2/(R1+R2)    #Voltage Divider Rule

Vb1=Vc2-Vr1             #KVL

#With Q1 off, 
Vrc1=Rc1*(Vcc-Vbb)/(Rc1+R11+R21)     #Voltage Divider Rule
Vc1=Vcc-Vrc1                         #KVL


#Results

print "With Q2 ON,"
print "Vc2=",round(Vc2,1),"V"
print "Vr1r2=",round(Vr1r2,1),"V"
print "Vr1=",round(Vr1,1),"V"
print "Vb1=",round(Vb1,1),"V"
print
print "With Q1 OFF,"
print "Vrc1=",round(Vrc1,1),"V"
print "Vc1=",round(Vc1,1),"V"

#Note: A round off error of 0.1 V is observed in Vr1 and Vb1 variables
With Q2 ON,
Vc2= 0.2 V
Vr1r2= 5.2 V
Vr1= 1.9 V
Vb1= -1.7 V

With Q1 OFF,
Vrc1= 0.6 V
Vc1= 4.4 V

Example 5-3, Page Number: 124

In [34]:
import math

#Variable Declaration

If=20*10**-3                  #Forward current in A

#Calcualtions
#For the LED display
I7=7*If                       #Seven Segment Current in A
I_1by2=2*If                   #Current for 1/2 digit in A
It=3*I7+I_1by2                #Total Current in A

print "For the LED Display,"
print "Current for each 7 segment display=",round(I7*10**3),"mA"
print "Current for 1/2 (2 segment) display=",round(I_1by2*10**3),"mA"
print "Total current for 3 and 1/2 digits=",round(It*10**3),"mA"


#For the LCD Display
If=300*10**-6

I7=7*If                       #Seven Segment Current in A
I_1by2=2*If                   #Current for 1/2 digit in A
It=3*I7+I_1by2                #Total Current in A

print
print "For the LCD Display,"
print "Current for each 7 segment display=",round(I7*10**3,1),"mA"
print "Current for 1/2 (2 segment) display=",round(I_1by2*10**6),"micro ampere"
print "Total current for 3 and 1/2 digits=",round(It*10**3,1),"mA"
For the LED Display,
Current for each 7 segment display= 140.0 mA
Current for 1/2 (2 segment) display= 40.0 mA
Total current for 3 and 1/2 digits= 460.0 mA

For the LCD Display,
Current for each 7 segment display= 2.1 mA
Current for 1/2 (2 segment) display= 600.0 micro ampere
Total current for 3 and 1/2 digits= 6.9 mA

Example 5-4, Page Number: 130

In [35]:
import math

#Variable Declaration
T0=1*10**-6        #Oscillator time period in s
N=16              #Modulus of the counters 
n=3               #No. of counters

#Calculations
T=T0*N**n         #Time period in s
f=1/T             #Frequency in Hz

#Results
print "Time period=",round(T*10**3,1),"ms"
print "Frequency=",round(f),"Hz"
Time period= 4.1 ms
Frequency= 244.0 Hz

Example 5-5, Page Number: 131

In [41]:
import math

#Variable Declaration
Vr=1.25                     #in V
tr=125*10**-3               #in s
f=1.0*10**6                 #in Hz

#For Vi=0.9
Vi=0.9                     #in V
t1=tr*Vi/Vr                #in s 
T=1/f                      #in s
N=t1/T                     #No. of pulses counted  

print "For Vi=0.9V,"
print "t=",round(t1*10**3),"ms"
print "Pulses counted=",round(N)

#For Vi=0.75
Vi=0.75                   #in V
t1=tr*Vi/Vr               #in s 
N=t1/T                    #No. of pulses counted 

print "For Vi=0.75V,"
print "t=",round(t1*10**3),"ms"
print "Pulses counted=",round(N)

#**********************Error********************************
##Note:The count values obtained in text book are 900 and 750 
##Whereas the actual values are 900000 and 75000 respectively
For Vi=0.9V,
t= 90.0 ms
Pulses counted= 90000.0
For Vi=0.75V,
t= 75.0 ms
Pulses counted= 75000.0

Example 5-6, Page Number: 133

In [47]:
import math

#Variable Declaration

#For 1% quantizing error count, count>=100
N=1
while(N):
    count=2**N-1
    if(count>=100):
        break 
    N=N+1

print "N=",N,"bit ADC is requird for quantizing error less than 1%"
        
N= 7 bit ADC is requird for quantizing error less than 1%

Example 5-7, Page Number: 135

In [50]:
import math

#Variable Declaration
a3=1          #bit
a2=0          #bit
a1=1          #bit
a0=0          #bit
Vi=10        #in V

#Calculations

Vo=(2**3*a3+2**2*a2+2**1*a1+a0)*Vi/16.0

print "Vo=",round(Vo,2),"V"
 
Vo= 6.25 V