#Ex21_1 Pg-1067
#calculate Pulse width
print'%s'%("Refer to figure 21.10")
R=5000. #resistor R in ohm
C=0.1*10.**(-6.) #capacitance in farad
tau=1.1 #time constant
tON=tau*R*C #pulse width in sec
print'%s %.2f'%("Pulse width = msec",tON*1e3)
#Ex21_2 Pg-1068
#calculate time output
print '%s' %("Refer to figure 21.12")
R1=20000. #timing resistor R1 in ohm
R2=R1 #timing resistor R2 in ohm
C=0.1*10.**(-6.) #capacitance in farad
tau=0.69 #time constant
tHIGH=tau*(R1+R2)*C #time output that will remain high
print '%s %.2f' %("Time output = msec",tHIGH*1e3)
#Ex21_3 Pg-1069
#calculate time output
print '%s' %("Refer to figure 21.12")
R2=20000. #timing resistor R2 in ohm
C=0.1*10.**(-6.) #capacitance in farad
tau=0.69 #time constant
tLOW=tau*(R2)*C #time output that will remain high
print '%s %.2f' %("Time output = msec",tLOW*1e3)
#Ex21_4 Pg-1069
#calculate output frequency
R1=20000. #timing resistor R1 in ohm
R2=R1 #timing resistor R2 in ohm
C=0.1*10.**(-6.) #capacitance in farad
f0=1.45/((R1+2.*R2)*C) #output frequency
print '%s %.2f' %("Output frequency = Hz",f0)
#Ex21_5 Pg-1069
#calculate duty cycle
print '%s' %("Refer to figure 21.12")
R1=20000. #timing resistor R1 in ohm
R2=R1 #timing resistor R2 in ohm
D=(R1+R2)/(R1+2.*R2)*100. #duty cylce
print '%s %.1f' %("Duty cycle =",D)
#Ex21_6 Pg-1070
#calculate R1 and R2
C=0.01*10.**(-6.) #capacitance in farad
f0=2000. #frequency in Hz
Req=1.45/(f0*C) #equivalent resistance or R1+R2
print '%s' %("Because a square wave has duty cycle of 50% each resistor must be the same")
R1=Req/2.
R2=R1
print'%s %.2f' %("R1 = R2 = kohm",R2*1e-3)
#Ex21_7 Pg-1073
#calculate pulse width
R=260000. #resistor R in ohm
C=25*10.**(-6.) #capacitance in farad
tau=1.1 #time constant
t_delay=tau*R*C #pulse width in sec
print '%s %.2f' %("Pulse width = sec",t_delay)
#Ex21_8 Pg-1076
#calculate Binary value of 253
dec=253 #decimal number
bina=bin(dec) #binary value of 253
print bina