# Threshold voltages(refer fig. 8.20)
import math
#Variable declaration
Vcc = 15 # positive saturation voltage
Vee = -15 # Negative saturation voltage
R1 = 120.0 # resistance R1
R2 = 51*10**3 # resistance R2
vin = 1 # input voltage
#Calculations
Vut = Vcc*R1/(R1+R2)
Vult = Vee*R1/(R1+R2)
#Result
print("Vut = %.1f mV\nVult = %.1f mV"%(Vut*1000,Vult*1000))
# Values of R1 and R2
import math
# Variable declaration
Vcc = 12.0 # positive saturation voltage
Vee = -12.0 # negative saturation voltage
Vh = 6.0 # hysteresis width
#Calculations
R1 = 10*10**3
R2 = (1-(Vh/(Vcc-Vee)))*R1/(Vh/(Vcc-Vee))
#Result
print("R1 = %.0f k-ohm\nR2 = %.0f k-ohm"%(R1/1000,R2/1000))
# Schmitt trigger
import math
#Variable declaration
Vh = 2.0 # hysteresis width
Vlt = -1.5 # lower threshold
Vpp = 5.0 # sine wave amplitude
f = 1000.0 # frequency
# Calculations
Vut = Vh - abs(Vlt)
Vm = Vpp/2
theta = math.asin(-Vlt/Vm)
theta = theta*180/math.pi
T = 1/f
T1 = T*(180.0+theta)/360.0
T2 = T-T1
#Result
print("Time duration for negative portion , T1 = %.3f ms\nTime duration for positive portion , T2 = %.3f ms"%(T1*1000,T2*1000))
# Schmitt Trigger
import math
#Variable declaration
Vh = 10.0 # ligher threshold
Vl = -10.0 # lower threshold
Imax = 100*10**-6 # maximum current through R1 and R2
Vhv = 0.1 # hysteresis width
#Calculations
R2 = 1000.0 # assumed
R1= R2*(1-(Vhv/(2*Vh)))/(Vhv/(2*Vh))
R = R1*R2/(R1+R2)
#Result
print("R1 = %.0f k-ohm\nR2 = %.0f k-ohm\nR1||R2 = %.0f ohm"%(R1/1000,R2/1000,R))
# R1||R2 value is in ohm and not in k-ohm
print("Theoretical example")
# Threshold voltages and hysteresis voltage (refer fig. 8.26)
import math
#Variable declaration
VsatP = 12.0 # Positive saturation voltage
VsatN = -12.0 # Negative saturation voltage
R1 = 1000.0 # Resistor R1
R2 = 3*10**3 # Resistor R2
#Result
Vlt = -VsatP*R1/R2
Vut = -VsatN*R1/R2
Vh = (R1/R2)*abs(VsatP-VsatN)
#Result
print("Vlt = %.0f V\nVut = %.0f V\nVh = %.0f V"%(Vlt,Vut,Vh))
# Schmitt's trigger (refer fig. 8.27)
import math
#Variable declaration
Vcc = 12.5 # positive supply voltage
Vee = -12.5 # negative supply voltage
R1 = 80.0*10**3 # Resistor R1
R2 = 20.0*10**3 # Resistor R2
#Calcualtions
Vut = R2*Vcc/(R1+R2)
Vlt = R2*Vee/(R1+R2)
Vhv = R2*2*Vcc/(R1+R2)
#Result
print("Vlt = %.1f V\nVut = %.1f V\nVh = %.1f V"%(Vlt,Vut,Vhv))
print("Theoretical example")
# Sample and hold circuit
import math
#Variable declaration
del_Vin = 5.0 # changes in input volage
FRR = 80.0 # feedthrough rejection ratio
#Calculations
math.sqrt(5)
del_Vout = del_Vin/math.pow(10,FRR/20)
#Result
print("Change in output = %.4f V = %.1f mV"%(del_Vout,del_Vout*1000))
# Threshold voltages and frequency of oscillation ( refer fig.8.72)
import math
#Variable declaration
R1 = 86*10**3 # Resistor R1
R2 = 100*10**3 # Resistor R2
Vcc = 15.0 # positive saturation voltage
Vee = -15.0 # negative saturation voltage
Rf = 100*10**3 # feedback resistance
C = 0.1*10**-6 # capacitance
#Calculations
Vut = R1*Vcc/(R1+R2)
Vlt = R1*Vee/(R1+R2)
fo = 1/(2*Rf*C*math.log((Vcc-Vlt)/(Vcc-Vut)))
#Result
print("(i) Vut = %.2f V\n(ii) Vlt = %.2f \n(iii)fo = %.0f Hz"%(Vut,Vlt,fo))
print("Theoretical example")