import math
##Example 16.3
Vdd=5.;
Vtnd=0.8;
Vtnl=0.8;
Kn=35.;
Vo=0.1;
Vi=4.2;
##W/L=Y
yl=0.5;
##Kd/Kl=x
x=(Vdd-Vo-Vtnl)**2/(2.*Vo*(Vi-Vtnd)-Vo**2);
print"%s %.2f %s"%('\nKd/Kl=\n',x,'')
##Kd/Kl=yd/yl
yd=12.6
yl=0.5
iD=Kn*yl*(Vdd-Vo-Vtnl)**2/2.;
print"%s %.2f %s"%('\ndrain current = ',iD,' microA\n')
P=iD*Vdd;
print"%s %.2f %s"%('\npower dissipation= ',P,' microW\n')
import math
##Example 16.4
Vdd=5.;
Vtnd=0.8;
Vtnl=-2.;
Kn=35.;
Vo=0.1;
Vi=5.;
##W/L=Y
yl=0.5;
##Kd/Kl=x
x=(-Vtnl)**2/(2.*Vo*(Vi-Vtnd)-Vo**2);
print"%s %.2f %s"%('\nKd/Kl=\n',x,'')
##Kd/Kl=yd/yl
yd=2.41
yl=0.5
iD=Kn*yl*(-Vtnl)**2/2.;
print"%s %.2f %s"%('\ndrain current= ',iD,' microA\n')
P=iD*Vdd;
print"%s %.2f %s"%('\npower dissipation = ',P,' microW\n')
import math
##Example 16.5
Voh=4.2;
Vol=0.1;
##x=Kd/Kl
x=25.1;
Vdd=5.;
Vtnl=0.8;
Vohu=4.2;
Vil=0.8;
Vtnd=0.8;
Vih=Vtnd+(Vdd-Vtnl)/x*((1+2*x)/math.sqrt(1.+3.*x)-1.);
print"%s %.2f %s"%('\nVih= ',Vih,' V\n')
Volu=(Vdd-Vtnl+x*(Vih-Vtnd))/(1.+2.*x);
print"%s %.2f %s"%('\noutput voltage corresponding to Vih= ',Volu,' V\n')
NMl=Vil-Volu;
print"%s %.2f %s"%('\nnoise margin= ',NMl,' V\n')
NMh=Vohu-Vih;
print"%s %.2f %s"%('\nnoise margin= ',NMh,' V\n')
import math
##Example 16.9
Vdd=5.;
Vtn=1.;
Vtp=-1.;
##Kn=Kp hence Kn/Kp=x=1;
x=1.;
Vit=(Vdd+Vtp+math.sqrt(x)*Vtn)/(1.+math.sqrt(x));
print"%s %.2f %s"%('\ninput voltage= ',Vit,' V\n')
Vipt=Vit;
Vopt=Vipt-Vtp;
print"%s %.2f %s"%('\noutput voltage at the transition point for PMOS = ',Vopt,' V\n')
Vint=Vit;
Vont=Vint-Vtn;
print"%s %.2f %s"%('\noutput voltage at the transition point for NMOS= ',Vont,' V\n')
Vdd=10.;
Vit=(Vdd+Vtp+math.sqrt(x)*Vtn)/(1.+math.sqrt(x));
print"%s %.2f %s"%('\ninput voltage = ',Vit,'V\n')
Vipt=Vit;
Vint=Vit;
Vopt=Vipt-Vtp;
print"%s %.2f %s"%('\noutput voltage at the transition point for PMOS = ',Vopt,' V\n')
Vont=Vint-Vtn;
print"%s %.2f %s"%('\noutput voltage at the transition point for NMOS = ',Vont,' V\n')
import math
##Example 16.10
Cl=2.*10**-6;
Vdd=5.;
f=100000.;
P=f*Cl*Vdd**2;
print"%s %.2f %s"%('\npower dissipation in the CMOS inverter= ',P,' microW\n')
import math
##Example 16.11
Vtn=1.;
Vtp=-1.;
Vdd=5.;
Vth=1.;
Vil=Vtn+3.*(Vdd+Vtp-Vth)/8.;
print"%s %.2f %s"%('\ninput voltage at the transition points Vil= ',Vil,' V\n')
Vih=Vtn+5.*(Vdd+Vtp-Vtn)/8.;
print"%s %.2f %s"%('\ninput voltage at the transition points Vih= ',Vih,' V\n')
Vohu=1.*(2.*Vil+Vdd-Vtn-Vtp)/2.;
print"%s %.2f %s"%('\noutput voltage = ',Vohu,' V\n')
Volu=1.*(2.*Vih-Vdd-Vtn-Vtp)/2.;
print"%s %.2f %s"%('\noutput voltage = ',Volu,' V\n')
NML=Vil-Volu;
print"%s %.2f %s"%('\nnoise margin = ',NML,' V\n')
NMH=Vohu-Vih;
print"%s %.2f %s"%('\nnoise margin= ',NML,' V\n')
import math
##Example 16.15
Vdd=3.;
Kn=60.;
Vtnd=0.5;
##W/L=x
xd=2.;
Vtnl=-1.;
xl=0.5;
R=2.;##(MOhm)
Vgsl=0.;
##solution with Depletion load
iD=Kn*xl*(Vgsl-Vtnl)**2/2.;
print"%s %.2f %s"%('\nfrain currents in M1 and M3 = ',iD,' microA\n')
P=iD*Vdd;
print"%s %.2f %s"%('\npower dissipation in the circuit= ',P,'microW\n')
##iD=Kn/2*x*(2*Vgsd-Vtnd)Vdsd-Vdsd^2
Q=50.5
p=0.25 - 5*(50.5) + 50.5
print(p)
##solution with Resistor load
##(Vdd-Q)/R=Kn/2*xd*(2*Vgsd-Vtnd)Q-Q^2
Q=0.005;
p1=0.25 - 5*(0.005) + 0.005
print(p1)
iD=(Vdd-Q)/R;
print"%s %.2f %s"%('\ndrain current = ',iD,' microA\n')
P=iD*Vdd;
print"%s %.2f %s"%('\npower dissipation in the circuit = ',P,' microW\n')