是基于峰值电流控制的BUCK转换器基础编程,还望大佬们帮新手看看吧!一下是源代码:
E=20
L=3.3e-3
C=1e-3
R=19
T=4e-4
A2 = [0,-1/L;1/C,-1/R*C]
A1 = A2
A3=[0,0;0,-1/C*R]
B1=[1/L;0]
B2=[0;0]
B3=B2
O=A1^-1
O=A2^-1
I=[1,0;0,1]
for m=1:150
Iref=0.1+0.01*(m-1)
i(1)=0
u(1)=0
for n=1:1000
Ib1=Iref-E*T/L
if i(n)<=Ib1
i(n+1)=exp(A1*T)*i(n)+(exp(A1*T)-I)*O*B1*E
u(n+1)=exp(A1*T)*u(n)+(exp(A1*T)-I)*O*B1*E
else
t1 = (Iref-i(n))*L/E
Ib2 = Iref-E*(T-t1)/L
t2=T-t1
if i(n) < Ib2
i(n+1)=exp(A2*t2)*exp(A1*t1)*i(n)+exp(A2*t2)*(exp(A1*t1)-I)*O*B1*E
u(n+1)=exp(A2*t2)*exp(A1*t1)*u(n)+exp(A2*t2)*(exp(A1*t1)-I)*O*B1*E
else
t1 = (Iref-i(n))*L/E
t2=Iref*L/E
t3=T-t1-t2
i(n+1)=0
u(n+1)=exp(A3*t3)*exp(A2*t2)*exp(A1*t1)*u(n)+exp(A3*t3)*exp(A2*t2)*(exp(A1*t1)-I)*O*B1*E
end
end
end
i1(m,:) = i(end-80:end)
uo(m,:) = u(end-80:end)
H= plot(Iref*ones(1,length(uo(m,:))),uo(m,:))
set(H,'linestyle','none','marker','.','markersize',3)
hold on
drawnow
end