clc;
clear all;
close all;
Uz = 30;
Pz = 5;
Uf = 3.7;
Ud = 230*sqrt(2);
Udd = 17;
Ivdd = 0.2;
f = 52e3;
Utr = 120%120.7;
eta = 0.8;           %% účinnost
Bmax = 0.3;
kpcu = 0.4;
sigma = 3e6;
uo = 4*pi*10^-7;


%% ETD2910 CF138
% ao = 9.5e-3;
% bo = 2.5e-3;
% ui = 2100;                     %%ue = 1572 ui = 2100;
% Al = 2350e-9;          %% nH
% lFe = 71e-3;
% SFe = 76e-6;
%%


%% E1605 CF279
ao = 9.7e-3;
bo = 2.45e-3;
ui = 2300;                     %%ue = 1572 ui = 2100;
Al = 1100e-9;          %% nH
lFe = 37.6e-3;
SFe = 20.1e-6;

%% E2005 CF297
 ao = 12e-3;
 bo = 2.95e-3;
 ui = 2300;                     %%ue = 1572 ui = 2100;
 Al = 1700e-9;          %% nH
 lFe = 44.9e-3;
 SFe = 33.5e-6;

%% E1304 CF139
% ao = 7.3e-3;
% bo = 1.75e-3;
% ui = 2100;                     %%ue = 1572 ui = 2100;
% Al = 850e-9;          %% nH
% lFe = 29.6e-3;
% SFe = 12.4e-6;

%% E2507 CF195
% ao = 15.2e-3;
% bo = 8.4e-3;
% ui = 3200;                     %%ue = 3200 ui = 5000;
% lFe = 57.5e-3;
% SFe = 52.5e-6;
%%
So = ao*bo
UCEmax = Ud + Utr;
smax = 1 - Ud/UCEmax;
L1 = Ud^2*smax^2/(2*f*Pz/eta);
Iu1max = Ud*smax/(f*L1);
SoSj = 2*sqrt(smax/3)*L1*Iu1max^2/(Bmax*kpcu*sigma);  %minimalizace jádra
sqrt(SoSj)
SoSFe = So*SFe;
N1 = L1*Iu1max/(Bmax*SFe);
Al1 = L1/N1^2;
%N1 = 169
L = N1^2*Al; %% L < L1 proto přepočet závitů N
%% pro příliš malou indukčnost L1
lvp = N1*uo*Iu1max/Bmax-lFe/ui;
lv = 1e-4;
Rmv = (1/(uo))*lv/SFe
RmFe = 1/Al
N1 = sqrt(L1*(Rmv+RmFe));
Rmcelk = N1^2/L1

RmFe = (1/(uo*ui))*lFe/SFe;    %%SFe/(uo*ui*lFe);
Rmcelk = N1^2/L1;
Rmv = Rmcelk - RmFe;
lv2 = uo*SFe*Rmv

N2 = N1*(Uz+Uf)/Utr;
%N2 = 71;
L2 = N2^2*Al1;
%%N1 = N2*Utr/(Uz+Uf);
N3 = N1*(Udd+1)/Ud;
%N3 = 15;
U3 = 11*Ud/N1
L3 = N3^2*Al1;
Iu2str = Pz/Uz;
Iu1ef = Iu1max*sqrt(smax)/sqrt(3);
%Iu2max = Iu1max*N1/N2;
s2 = smax*Ud/Utr;
Iu2ef = 2*Iu2str/(sqrt(1-smax)*sqrt(3));
Iu2max = Iu2ef*sqrt(3)/sqrt(1-smax);
%Iu2ef = Iu2max*sqrt(s2)/sqrt(3);

ro = 3;
Scu1 = Iu1ef/ro;
Scu2 = Iu2ef/ro;
Scu3 = Ivdd*sqrt(smax)/ro;
d1 = sqrt(Scu1*4/pi);
d2 = sqrt(Scu2*4/pi);
d3 = sqrt(Scu3*4/pi);
Scutot = Scu1*N1 + Scu2*N2 + Scu3*N3;
kpcu = Scutot*10^-6/So

%N1 = 188
%N2 = 53
%N3 = 11
Iu1efvdd = Ivdd*N2/N1*sqrt(smax); %% Iu3ef
d1z = 0.2;
d2z = 0.3;
d3z = 0.2;
Scu1z = pi*d1z^2/4;
Scu2z = pi*d2z^2/4;
Scu3z = pi*d3z^2/4;
Scutot = Scu1z*N1 + Scu2z*N2 + Scu3z*N3;
kpcu1 = Scutot*10^-6/So
sigma1 = (Iu1ef+Iu1efvdd)/Scu1z;
sigma2 = Iu2ef/Scu2z;
sigma3 = Ivdd*sqrt(smax)/Scu3z;
%% Isense
UIsense = 1;
%%PIsense = UIsense*Iu1ef;
RIsense = UIsense/Iu1max;
PIsense = RIsense*Iu1ef^2;

%% v�st kondenztor
%deltaUa = 0.033
deltaUa = 0.05
s2 = smax*Ud/Utr;
%Iu2max = Iu2ef*2/(1-s2) chujovina jak sv�t
tnab = (1-smax)*(Iu2max-Iu2str)/(f*Iu2max)
C = (Iu2max-Iu2str)*tnab/0.1
%%C2 = Iu2str*tnab/0.01;
C3 = Iu2str*(1/f-tnab)/deltaUa;
C1 = Iu2str*smax/f/deltaUa;
t = (s2)/f
t1 = tnab;
t2 = (1/f-tnab);
t3 = smax/f
t4 = 1/f
%% V�st LC filtr
deltaUza = 66e-6;
Au = deltaUa/deltaUza
AudB = 20*log10(Au);
fr = f/10^(AudB/40);
L = 800e-6; %800e-6
dIL = deltaUa*smax/4/L/f;
Cv = 1/(2*pi*fr)^2/L
%% filt kondenzátor
Iu1str = Iu1max*smax/2;
dU = 20;
thetha = abs(asin((Ud-dU)/Ud))*180/pi;
tvyb = 1/4*20e-3+thetha/180/2*1/4*20e-3;
Cf = Iu1str* tvyb/dU
%% dimenzování propustné diody
% DPAK tepelný odpor
%https://www.researchgate.net/publication/4336082_Investigation_of_thermal_performance_of_various_power-device_packages
Iu2str = Pz/Uz;
k = N2/N1;
Urr = (Ud*k + Uz)*1.6
UF = 1;
PDztr = Iu2str*UF;
RthJC = 3.5;
RthJa = 70;
deltaTd = (RthJC+RthJa)*(PDztr)
Td = 40+deltaTd
%% dimenzování tranzistoru
fpwm = 52e3;
ton = (10+8)*1e-9;
toff = (60+13)*1e-9;
T = 60;
Rds_on = 1.15; % pro 25°C 0.95 pro 150 °C 2.22 ohmu
Pzv = Rds_on*Iu1ef^2
Psv = 1/2*f*Ud*Iu1max*(ton+toff)
RthJC = 3.41;
RthJa = 62;
deltaT = 60-40;
Rth = deltaT/(Pzv+Psv)-RthJC
deltaT = (RthJC+RthJa)*(Pzv+Psv)
T = 40+deltaT
%%
cp = 0.9 %coupling factor of transformer
Lsigma = L1*0.05%%(1-cp^2);
Pzd = f*1/2*Lsigma*Iu1max^2
Pzd1 = Pz/eta*0.1
