%-------------------------------
% EXAMEN CCIAC, Mai 2007, EX.I 
%-------------------------------

%----------------------------
% technology
%----------------------------
VthN = 0.7 ;
VthP = 0.8 ;
Un = 350e-4 ;
Up = 100e-4 ;
Eox = 34.5e-12 ;
tox = 9e-9 ;
Cox = Eox / tox ;
lambdan=0.1;
lambdap=0.2;
LDP=0.09e-6;

%----------------------------
% Specifications 
%----------------------------
Avdb = 60.0;
Av = 10^(Avdb/20)
Av2 = sqrt(Av);

I5=100e-6;
I1=10e-6;
Cout=0.5e-12;
Vds5 = 1.5;
L=2e-6;

%----------------------------
% (1) et (2) Calculez VEG 
%----------------------------
VEG = (1/(lambdap+lambdan)) * sqrt(4/Av)

%----------------------------
% Calculez W5 et en deduire CY 
%----------------------------
W5 = (2 * I5 * (L-2*LDP)) / (Up * Cox * (VEG)^2 * (1+lambdap*Vds5) )
CY = 2/3 * W5 * L * Cox

%----------------------------
% Calculez Rout et RY 
%----------------------------
Rout = (1/((lambdap+lambdan)*I5))
RY = (1/((lambdap+lambdan)*I1))

%----------------------------
% Calculez wout et wY 
%----------------------------
wout = 1/(Rout*Cout)
wY = 1/(RY*CY)

%----------------------------
% Calculez la frequence de transition
%----------------------------
Aout = 10^(log(wY/wout)+3);
Aout_dB = 20*log10(wY/wout) + 60
wT = wout / (10^(-Aout_dB/40))

%----------------------------
% Calculez la marge de phase 
%----------------------------
phase_margin = (-atan(wT/wY) -atan(wT/wout))*180/pi - (-180)

%----------------------------
% Calculate the value of CC for a phase margin of 60 degrees
% Assuming wY << wT
%----------------------------
gm5 = 2*I5/VEG
wout_new = gm5/(CY+Cout)
wT_new = wout_new * tan(30*pi/180)
wY_new = 1e-3*wT_new
CC = (1/(1+Av2))*((1/(wY_new*RY)) -CY)

%----------------------------
% Integrator
%----------------------------
wT_int = wT/10;
Rint = 1/(wT_int*Cout)

