%% POWER STAGE CALCULATIONS
% Please refer to the LT16810 datasheet for many of these calculations. 
clear; close all;
%% Some Constants
Vin = 15; %volts
Vout = [3.3 5];%volts

%% FB Resistor Network
% Referring to scott's original circuit, we have to reset the value of the
% divider.
%
% $R1 = R2(\frac{V_{out}}{0.970} = 1)$
%
% Originally it was:

R1 = [620e3 866e3];
R2 = [243e3 200e3];
VoutOrig = (R1./R2+1)*0.970

% Let's reset for 3.3 and 5. Let's keep R2
R1new = [1e6 1e6];
R2new = [412e3 243e3];
VoutNew = (R1new./R2new+1)*0.970

% Determine the quiescent current
Iq = (1.7e-6 + (VoutNew/(R1new+R2new))*(VoutNew/Vin)*(1/.8) ) * 1e6 %uA

%% Max Frequency of Switching

% First some supporting variables.
Vswbot = 0.15; 
Vswtop = 0.3;
tonmin = 45e-9;
fswmax = Vout;

%The resulting operating frequencies (MHz) are 

fswmax = ( Vout + Vswbot) ./ (tonmin * (Vin - Vswtop + Vswbot))*1e-6
fsw = 0.200; %MHz

%% Minimum Input.
toffmin = 80e-9;
Vinmin = (Vout+Vswbot)./(1-fsw*toffmin) - Vswbot + Vswtop


%% Inductor Selection
% This a simple suggestion for where to start based on sampling frequency
fsw %MHz
Vout %V
Lmin = (Vout + Vswbot)/fsw %uH

L = 220; %uH

%% Current Limit

% Peak to peak ripple curent
Ilim = 2.8; %at DC=0.8
Vout
ILdelta = Vout./(L*fsw) .* (1-Vout./Vin)
IoutMax = Ilim-ILdelta./2


