# Chapter 13: Basic Op-amp Circuits

### Example 13.1, Page Number: 433

In [177]:
%matplotlib inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
In [178]:
import pylab
import numpy

R2=1.0*10**3;
R1=8.2*10**3;
V=15.0;
V_REF=R2*V/(R1+R2);
print('V_REF = %f V'%V_REF)
############PLOT##################################

t = arange(0.001, 2.0, 0.005)
k = arange(0.0001, 0.0529, 0.0005)
k1= arange(0.0529, 0.447, 0.0005)
k2= arange(0.447, 1.053, 0.0005)
k3= arange(1.053,1.447, 0.0005)
k4= arange(1.447,2.0, 0.0005)
m=arange(-12,12,0.0005)

x5=(0.0529*m)/m
x10=(0.447*m)/m
x15=(1.053*m)/m
x25=(1.447*m)/m
subplot(211)
plot(t, 5*sin(2*pi*t))
plot(t,(1.63*t)/t,'--')
ylim( (-5,5) )
ylabel('Vin')
title('Input Waveform')

subplot(212)
plot(k,-12*k/k,'b')
plot(k1,12*k1/k1,'b')
plot(k2,-12*k2/k2,'b')
plot(k3,12*k3/k3,'b')
plot(k4,-12*k4/k4,'b')
plot(x5,m,'b')
plot(x10,m,'b')
plot(x15,m,'b')
plot(x25,m,'b')

ylim( (-13,13) )
ylabel('Vout')
xlabel('each time the input exceeds +1.63V,o/p switches to +12 and vice-versa')
title('Output Waveform')

V_REF = 1.630435 V
Out[178]:
<matplotlib.text.Text at 0x2f58bd2c>

### Example 13.2, Page Number: 436

In [179]:
R1=100.0*10**3;
R2=R1;
V_out_max=5.0;
V_UTP=R2*V_out_max/(R1+R2);
V_LTP=-V_out_max*R2/(R1+R2);
print('upper trigger point = %.1f Volts'%V_UTP)
print('lower trigger point = %.1f Volts'%V_LTP)

upper trigger point = 2.5 Volts
lower trigger point = -2.5 Volts

### Example 13.3, Page Number: 437

In [180]:
import pylab
import numpy

R1=100.0*10**3;
R2=47.0*10**3;
V_R1=4.7+0.7;    #one zener is always forward biased with forward voltage 0.7V
#V_R1 can be positive or negative
I_R1=V_R1/R1;
I_R2=I_R1;
V_R2=R2*I_R2;
V_out=V_R1+V_R2;    #positive or negative

print ('I_R1 = Â±%d uA' %(I_R1*10**6))
print ('V_R2 = Â±%.2f V' %(V_R2))
print('max output voltage = Â± %.2f V'%V_out)
print('\nV_UTP = + %.2f V' %(V_R2))
print('V_LTP = - %.2f V' %(V_R2))

################PLOT######################################
t = arange(0.0, 1.0, 0.0005)
t1=arange(0.0001,0.085,0.0005)
t2=arange(0.0001,0.585,0.0005)
t3=arange(0.585,1.0,0.0005)
t4=arange(0.085,0.585,0.0005)

m=arange(-7.94,7.94,0.0005)
x1=(0.085*m)/m
x5=(0.585*m)/m

subplot(211)
plot(t, 5*sin(2*pi*t))
plot(t1,2.54*t1/t1,'--')
plot(t2,-2.54*t2/t2,'--')
text(0.09,1.95,'(0.085,2.54)')
text(0.586,-2,'(0.585,-2.54)')
#annotate('(0.085,2.54)',(0.085,2.54),(0.3,2.5),arrowprops = dict(facecolor='black',shrink=0.09,xycoords='data',textcoords='axes fraction'))
ylim( (-6,6) )
ylabel('Vin')
title('Input Waveform')

subplot(212)
plot(t1,7.94*t1/t1,'b')
plot(t3,7.94*t3/t3,'b')
plot(t4,-7.94*t4/t4,'b')
plot(x1,m,'b')
plot(x5,m,'b')
ylim( (-9,9) )
title('Source and output AC voltage')

I_R1 = Â±54 uA
V_R2 = Â±2.54 V
max output voltage = Â± 7.94 V

V_UTP = + 2.54 V
V_LTP = - 2.54 V
Out[180]:
<matplotlib.text.Text at 0x2f9fbf2c>

### Example 13.4, Page Number: 440

In [181]:
V_IN1=3.0;
V_IN2=1.0;
V_IN3=8.0;
#all resistors are of equal value so weight of each input is 1
V_OUT=-(V_IN1+V_IN2+V_IN3);
print('output voltage = %d Volts'%V_OUT)

output voltage = -12 Volts

### Example 13.5, Page Number: 440

In [182]:
R_f=10.0*10**3;
R1=1.0*10**3;
R2=R1;
R=R1;
V_IN1=0.2;
V_IN2=0.5;
V_OUT=-(R_f/R)*(V_IN1+V_IN2);
print('output voltage of the summing amplifier = %d Volts'%V_OUT)

output voltage of the summing amplifier = -7 Volts

### Example 13.6, Page Number: 441

In [183]:
R_f=25.0*10**3;
R1=100.0*10**3;
R2=R1;
R3=R1;
R4=R1;
R=R1;
V_IN1=1.0;
V_IN2=2.0;
V_IN3=3.0;
V_IN4=4.0;
V_OUT=-(R_f/R)*(V_IN1+V_IN2+V_IN3+V_IN4);
print('output voltage = %.1f Volts'%V_OUT)
V_IN_avg=(V_IN1+V_IN2+V_IN3+V_IN4)/4;
if abs(V_OUT)==V_IN_avg:
print('The amplifier produces an output whose magnitude\n is the mathematical average of the input voltages')

output voltage = -2.5 Volts
The amplifier produces an output whose magnitude
is the mathematical average of the input voltages

### Example 13.7, Page Number: 442

In [184]:
V_IN1=3.0;
V_IN2=2.0;
V_IN3=8.0;
R_f=10.0*10**3;
R1=47.0*10**3;
R2=100.0*10**3;
R3=10.0*10**3;
weight_of_input1=R_f/R1;
weight_of_input2=R_f/R2;
weight_of_input3=R_f/R3;
V_OUT=-(weight_of_input1*V_IN1+weight_of_input2*V_IN2+weight_of_input3*V_IN3);
print('weight_of_input1 = %f'%weight_of_input1)
print('weight_of_input2 = %.1f'%weight_of_input2)
print('weight_of_input3 = %d'%weight_of_input3)
print('output voltage = %f Volts'%V_OUT)

weight_of_input1 = 0.212766
weight_of_input2 = 0.1
weight_of_input3 = 1
output voltage = -8.838298 Volts

### Example 13.8, Page Number: 444

In [185]:
import pylab
import numpy

R_i=10.0*10**3;
C=0.01*10**-6;
V_in=2.5-(-2.5);
PW=100.0*10**-6;    #pulse width
T=2*PW;
A=2.5;
op_change_cap_charge=-V_in/(R_i*C);
op_change_cap_discharge=V_in/(R_i*C);
print('rate of change of output voltage with respect to time when capacitor is charging = %.1f V/sec'%op_change_cap_charge)
print('rate of change of output voltage with respect to time when capacitor is discharging =%.1f V/sec'%op_change_cap_discharge)
del_V_OUT=op_change_cap_discharge*PW;
print('\n\nwhen input is positive, the slope is negative,\nwhen input is negative, the slope is negative. \nSo, the output is a triangular wave varying from zero to %.1f V'%(-del_V_OUT))

##############PLOT#############################
t = arange(0.0, 10.0, 0.0005)
t1= arange(10.0, 20.0, 0.0005)
t2= arange(20.0, 30.0, 0.0005)
t3= arange(30.0, 40.0, 0.0005)

k = arange(0.0001, 10.0, 0.0005)
k1= arange(10.0, 20.0, 0.0005)
k2= arange(20.0, 30.0, 0.0005)
k3= arange(30.0,40.0, 0.0005)

m=arange(-2.5,2.5,0.0005)
x1=(0.001*m)/m
x5=(10*m)/m
x10=(20*m)/m
x15=(30*m)/m
x25=(39.99*m)/m

subplot(211)
plot(k,2.5*k/k,'b')
plot(k1,-2.5*k1/k1,'b')
plot(k2,2.5*k2/k2,'b')
plot(k3,-2.5*k3/k3,'b')
plot(x1,m,'b')
plot(x5,m,'b')
plot(x10,m,'b')
plot(x15,m,'b')
plot(x25,m,'b')

ylim( (-3,3) )
ylabel('Vin')
xlabel('us')
title('Input to Opamp Integrator')

subplot(212)
plot(t,(-0.5*t),'b')
plot(t1,(0.5*t-5),'b')
plot(t2,(-0.5*t),'b')
plot(t3,(0.5*t-5),'b')

ylim( (-5,0) )
ylabel('Vout')
xlabel('us')
title('Output of an Integrator')

rate of change of output voltage with respect to time when capacitor is charging = -50000.0 V/sec
rate of change of output voltage with respect to time when capacitor is discharging =50000.0 V/sec

when input is positive, the slope is negative,
when input is negative, the slope is negative.
So, the output is a triangular wave varying from zero to -5.0 V
Out[185]:
<matplotlib.text.Text at 0x303b512c>

### Example 13.9, Page Number: 447

In [186]:
import pylab
import numpy

R_f=2.2*10**3;
C=0.001*10**-6;
Vc=5.0-(-5.0);
A=5.0;
time_const=R_f*C;
T=10.0*10**-6;
t=T/2;
slope=Vc/t;
V_out=slope*time_const;    #V_out is negative when input is positive and V_out is positive when input is negative
print('output voltage = %.1f V'%V_out)
print('max output voltage = %.1f V'%V_out)
print('min output voltage = %.1f V'%(-V_out))

##################PLOt############################

t = arange(0.0, 5.0, 0.0005)
t1= arange(5.0, 10.0, 0.0005)
t2= arange(10.0, 15.0, 0.0005)
t3= arange(15.0, 20.0, 0.0005)

k = arange(0.0001, 5.0, 0.0005)
k1= arange(5.0, 10.0, 0.0005)
k2= arange(10.0, 15.0, 0.0005)
k3= arange(15.0, 20.0, 0.0005)

m=arange(-4.4,4.4, 0.0005)
x1=(0.001*m)/m
x5=(5*m)/m
x10=(10*m)/m
x15=(15*m)/m

subplot(211)
plot(t,(2*t-5),'b')
plot(t1,(-2*t+5),'b')
plot(t2,(2*t-5),'b')
plot(t3,(-2*t+5),'b')
ylim( (-6,6) )
ylabel('Vin')
xlabel('us')
title('Triangular wave input')

subplot(212)
plot(k,-4.4*k/k,'b')
plot(k1,4.4*k1/k1,'b')
plot(k2,-4.4*k2/k2,'b')
plot(k3,4.4*k3/k3,'b')
plot(x1,m,'b')
plot(x5,m,'b')
plot(x10,m,'b')
plot(x15,m,'b')
ylim( (-5,5) )
ylabel('Vout')
xlabel('us')
title('Output of Opamp Differentiator')

output voltage = 4.4 V
max output voltage = 4.4 V
min output voltage = -4.4 V
Out[186]:
<matplotlib.text.Text at 0x30f01b4c>