#v_s is sinusoidal input voltage with peak 24V
#battery charges to 12V
I_d=(24-12)/100.0
max_v_rev=24+12.0;
print round(I_d,2),"peak value of diode current (A)\n",round(max_v_rev,2),"maximum reverse voltage acrossthe diode (V)"
print "Consider fig 3.6(a). Assume both diodes are conducting"
I_D2=(10-0)/10.0;
I=(0-(-10))/5.0-I_D2; # node eqution at B for fig 3.6(a)
V_B=0;
V=0;
print I,"= I (mA)\n", V,"= V (V)\n" ,"D_1 is conducting as assumed originally"
print "Consider fig 3.6(a). Assume both diodes are conducting"
I_D2=(10-0)/5.0;
I=(0-(-10.0))/10-2; # node eqution at B for fig 3.6(b)
print I,"= I (mA)\n ", V,"=V (V)"
print "Implies assumption is wrong. lets assume D_1 is off and D_2 is on"
I_D2=(10-(-10))/15.0;
V_B=-10+10.0*I_D2;
I=0;
print I,"= I (mA)\n", round(V_B,1),"= V (V)\n D_1 is reverse biased"
#i-I_S*exp(v/(n*V_T)) implies I_S=i*exp(-v/(n*V_T))
n=1;
i=10**-3; # (A)
v=700; # (V)
V_T=25; # (V)
I_S=i*exp(-v/(n*V_T))
print round(I_S,17),"= I_S (A) for n=1"
n=2;
I_S=i*exp(-v/(n*V_T))
print round(I_S,11),"= I_S (A) for n=2"
print "These values implies I_S is 1000 times greater "
V_DD=5; # (V)
R=1000; # (ohm)
I_1=1*10**-3; # (A)
V_D=0.7; # (V)
V_1=V_D;
I_D=(V_DD-V_D)/R;
I_2=I_D;
V_2=V_1+0.1*log10(I_2/I_1);
I_D=(V_DD-V_2)/R;
print round(I_D*1000.0,3),"= The diode current (mA)"
V_D=V_2+0.1*log10(I_D/I_2)
print round(V_D,3),"= The diode volage (V)"
V_D0=0.65; # (V)
r_D=20; # (ohm)
R=1000; # (ohm)
V_DD=5; # (V)
I_D=(V_DD-V_D0)/(R+r_D);
print round(I_D*1000,2),"= I_D (mA)"
V_D=V_D0+I_D*r_D;
print round(V_D,3),"= The diod voltage (V)"
V_S=10; # V_S=V_+
V_D=0.7; # (V)
R=10*10**3; # (ohm)
n=2;
V_T=25*10**-3; # (V)
V_s=1; # (V)
I_D=(V_S - V_D)/R;
r_D=n*V_T/I_D;
v_d=V_s*r_D/(R+r_D);
print round(v_d*1000,2),"= v_d(peak (mV))"
V_DD=10; # (V)
V_D=0.7*3; # string of 3 diodes provide this constant voltage
R=1*10**3;
I_D=(V_DD-V_D)/R;
n=2;
V_T= 25*10**-3; # (V)
r_d=n*V_T/I_D; # incremental resistance
r=3*r_d; # total incremental resistance
deltav_O=2*r/(r+R); # deltav is peak to peak change in output voltage
print round(deltav_O*1000,1),"is Percentage change (mV) in regulated voltage caused by 10% change in power supply"
I=2.1*10**-3; # The current drawn from the diode string
deltav_O=-I*r; # Decrease in voltage across diode string
print round(deltav_O*1000,1),"is Decrease in voltage across diode string (mV)"
# The answer in the textbook is slightly different due to approximation
V_Z=6.8; # (V)
I_Z=0.005; # (A)
r_Z=20; # (ohm)
V=10; # V=V_+
R=0.5*10**3; # (ohm)
# 3.8a
V_ZO=V_Z-r_Z*I_Z;
I_Z=(V-V_ZO)/(R+r_Z)
V_O=V_ZO+I_Z*r_Z;
print round(V_O,2),"= V_O (V)"
# 3.8b
deltaV=1; # change in V is +1 and -1
deltaV_O=deltaV*r_Z/(R+r_Z); # corresponding change in output voltage
print round(deltaV_O*1000,1),"= Line regulation (mV/V)"
# 3.8c
I_L=1*10**-3; # load current
deltaI_L=1*10**-3;
deltaI_Z=-1*10**-3; # change in zener current
deltaV_O=r_Z*deltaI_Z;
print round(deltaV_O*1000),"= Load regulation (mV/mA)"
# 3.8d
I_L=6.8/2000; # load current with load resistance of 2000
deltaI_Z=-I_L;
deltaV_O=r_Z*deltaI_Z;
print round(deltaV_O*1000,2),"= Corresponding change in zener voltage (mV) for zener current change of -3.4mA"
# 3.8e
R_L=0.5*10**3; # (ohm)
V_O=V*R_L/(R+R_L);
print V_O,"V_O (V) for R_L=0.5K ohm"
# 3.8f
I_Z=0.2*10**-3; # Zener t be at the edge of breakdown I_Z=I_ZK
V_Z=6.7; # V_Z=V_ZK
I_Lmin=(9-6.7)/0.5; # Lowest current supplied to R
I_L=I_Lmin-I_Z; # load current
R_L=V_Z/I_L;
print round(R_L,1),"= R_L (Kohm)"
# Example 3.9 : Value of capacitance C that will result in peak-peak ripple of 2V
V_P=100.0; # (V)
V_r=2.0; # (V)
f=60.0; # (Hz)
R=10.0*10**3; # (ohm)
I_L=V_P/R;
C=V_P/(V_r*f*R);
print round(C*1000000,1),"= C (microF)"
wdeltat=math.sqrt(2*V_r/V_P);
print wdeltat,"= Conduction angle (rad)"
i_Dav=I_L*(1+math.pi*math.sqrt(2*V_P/V_r));
print round(i_Dav*1000),"= i_Dav (A)"
i_Dmax=I_L*(1+2*math.pi*math.sqrt(2*V_P/V_r));
print round(i_Dmax*1000),"= i_Dmax (mA)"