%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Name : tam20131205_SVPWM
%% Author : tam (tangaiming_@126.com)
%% Date : 20131205
%% Description : SVPWM generator,
%% way1: do as the TI's datasheet.
%% way2: do as the TI's programm.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;clf;
T = 1;
time=1:1:360;
for theta=1:1:360;
theta_rad=theta/180*pi;
sin_theta=sin(theta_rad);
cos_theta=cos(theta_rad);
Ualfa=0.1*cos_theta-0.3*sin_theta;
Ubeta=0.1*sin_theta+0.3*cos_theta;
%%%%%%%%%%%%%%%%%%%%%%%%%%% way1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Va= Ubeta;
Vb=-1/2*Ubeta+sqrt(3)/2*Ualfa;
Vc=-1/2*Ubeta-sqrt(3)/2*Ualfa;
sector1=0;
if(Va>0) sector1=sector1+1;
end
if(Vb>0) sector1=sector1+2;
end
if(Vc>0) sector1=sector1+4;
end
Va= Ubeta;
Vb=1/2*Ubeta+sqrt(3)/2*Ualfa;
Vc=1/2*Ubeta-sqrt(3)/2*Ualfa;
if (sector1==1)
t1 = Vc;
t2 = Vb;
Tb1=(1-t1-t2)/2;
Ta1=Tb1+t1;
Tc1=Ta1+t2;
elseif(sector1==2)
t1 = Vb;
t2 =-Va;
Ta1=(1-t1-t2)/2;
Tc1=Ta1+t1;
Tb1=Tc1+t2;
elseif(sector1==3)
t1 =-Vc;
t2 = Va;
Ta1=(1-t1-t2)/2;
Tb1=Ta1+t1;
Tc1=Tb1+t2;
elseif(sector1==4)
t1 =-Va;
t2 = Vc;
Tc1=(1-t1-t2)/2;
Tb1=Tc1+t1;
Ta1=Tb1+t2;
elseif(sector1==5)
t1 = Va;
t2 =-Vb;
Tb1=(1-t1-t2)/2;
Tc1=Tb1+t1;
Ta1=Tc1+t2;
elseif(sector1==6)
t1 =-Vb;
t2 =-Vc;
Tc1=(1-t1-t2)/2;
Ta1=Tc1+t1;
Tb1=Ta1+t2;
end
Ta1=2*(Ta1-0.5);
Tb1=2*(Tb1-0.5);
Tc1=2*(Tc1-0.5);
y_Ualfa(theta,1)=Ualfa;
y_Ubeta(theta,1)=Ubeta;
y_Va(theta,1)=Va;
y_Vb(theta,1)=Vb;
y_Vc(theta,1)=Vc;
y_sector1(theta,1)=sector1;
y_Ta1(theta,1)=Ta1;
y_Tb1(theta,1)=Tb1;
y_Tc1(theta,1)=Tc1;
%%%%%%%%%%%%%%%%%%%%%%%%%%% way2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tmp1= Ubeta;
tmp2= 1/2*Ubeta+sqrt(3)/2*Ualfa;
tmp3=-1/2*Ubeta+sqrt(3)/2*Ualfa; % tmp2-tmp1;
sector2=3;
if(tmp2>0) sector2=sector2-1;
end
if(tmp3>0) sector2=sector2-1;
end
if(tmp1<0) sector2=7-sector2;
end
if (sector2==1||sector2==4)
Ta2= tmp2;
Tb2= tmp1-tmp3;
Tc2=-tmp2;
elseif(sector2==2||sector2==5)
Ta2= tmp3+tmp2;
Tb2= tmp1;
Tc2=-tmp1;
elseif(sector2==3||sector2==6)
Ta2= tmp3;
Tb2=-tmp3;
Tc2=-(tmp1+tmp2);
end
y_Ualfa(theta,1)=Ualfa;
y_Ubeta(theta,1)=Ubeta;
y_tmp1(theta,1)=tmp1;
y_tmp2(theta,1)=tmp2;
y_tmp3(theta,1)=tmp3;
y_sector2(theta,1)=sector2;
y_Ta2(theta,1)=Ta2;
y_Tb2(theta,1)=Tb2;
y_Tc2(theta,1)=Tc2;
end
% draw the picture
% way 1
figure(1);
subplot(221);
plot(time,y_Ualfa,'r',time,y_Ubeta,'g');
xlabel('Ualfa,Ubeta');
subplot(222);
plot(time,y_Va,'r',time,y_Vb,'g',time,y_Vc,'b');
xlabel('Va,Vb,Vc');
subplot(223);
plot(time,y_sector1);
xlabel('sector1');
subplot(224);
plot(time,y_Ta1,'r',time,y_Tb1,'g',time,y_Tc1,'b');
xlabel('Ta1,Tb1,Tc1');
% way 2
figure(2);
subplot(221);
plot(time,y_Ualfa,'r',time,y_Ubeta,'g');
xlabel('Ualfa,Ubeta');
subplot(222);
plot(time,y_tmp1,'r',time,y_tmp2,'g',time,y_tmp3,'b');
xlabel('tmp1,tmp2,tmp3');
subplot(223);
plot(time,y_sector2);
xlabel('sector2');
subplot(224);
plot(time,y_Ta2,'r',time,y_Tb2,'g',time,y_Tc2,'b');
xlabel('Ta2,Tb2,Tc2');
% PWM
figure(4);
set(gcf,'Color','w');
line([-0.25,1.25],[0,0],'Color','k');
line([0.5,0.5],[-1,-0.5],'Color','k');
line([0,0],[-1,0.5],'Color','k');
line([1,1],[-1,0.5],'Color','k');
line([-0.25,0],[0,0.5]);
line([0,0.5],[0.5,-0.5]);
line([0.5,1],[-0.5,0.5]);
line([1,1.25],[0.5,0]);
line([-0.25,1.25],[y_Ta2(1,1),y_Ta2(1,1)],'Color','r');
line([-0.25,1.25],[y_Tb2(1,1),y_Tb2(1,1)],'Color','r');
line([-0.25,1.25],[y_Tc2(1,1),y_Tc2(1,1)],'Color','r');
line([-0.25,1.25],[-1,-1],'Color','k');
line([0.1,0.1],[0.3017,-1],'Color','g');
line([0.17,0.17],[0.1641,-1],'Color','g');
line([0.4,0.4],[-0.3017,-1],'Color','g');
line([0.6,0.6],[-0.3017,-1],'Color','g');
line([0.83,0.83],[0.1641,-1],'Color','g');
line([0.9,0.9],[0.3017,-1],'Color','g');
% PWM1
line([0,0.17],[-0.7,-0.7],'Color','m');
line([0.17,0.83],[-0.65,-0.65],'Color','m');
line([0.83,1],[-0.7,-0.7],'Color','m');
line([0.17,0.17],[-0.7,-0.65],'Color','m');
line([0.83,0.83],[-0.7,-0.65],'Color','m');
% PWM2
line([0,0.1],[-0.8,-0.8],'Color','m');
line([0.1,0.9],[-0.75,-0.75],'Color','m');
line([0.9,1],[-0.8,-0.8],'Color','m');
line([0.1,0.1],[-0.8,-0.75],'Color','m');
line([0.9,0.9],[-0.8,-0.75],'Color','m');
% PWM3
line([0,0.4],[-0.9,-0.9],'Color','m');
line([0.4,0.6],[-0.85,-0.85],'Color','m');
line([0.6,1],[-0.9,-0.9],'Color','m');
line([0.4,0.4],[-0.9,-0.85],'Color','m');
line([0.6,0.6],[-0.9,-0.85],'Color','m');
text(-0.05,0.1841,'Ta');
text(-0.05,0.3217,'Tb');
text(-0.05,-0.2817,'Tc');
text(-0.1,-0.7,'PWM1');
text(-0.1,-0.8,'PWM2');
text(-0.1,-0.9,'PWM3');
line([0.17,0.19],[-0.7,-0.7],'Color','c');
line([0.19,0.19],[-0.7,-0.65],'Color','c');
line([0.83,0.85],[-0.65,-0.65],'Color','c');
line([0.85,0.85],[-0.7,-0.65],'Color','c');
line([0.1,0.12],[-0.8,-0.8],'Color','c');
line([0.12,0.12],[-0.8,-0.75],'Color','c');
line([0.9,0.92],[-0.75,-0.75],'Color','c');
line([0.92,0.92],[-0.8,-0.75],'Color','c');
line([0.4,0.42],[-0.9,-0.9],'Color','c');
line([0.42,0.42],[-0.9,-0.85],'Color','c');
line([0.6,0.62],[-0.85,-0.85],'Color','c');
line([0.62,0.62],[-0.9,-0.85],'Color','c');
%%%%%%%%%%%%%%%%%%%%%%%%%%% The end of the program %%%%%%%%%%%%%%%%%%%%%%%%
文章评论(0条评论)
登录后参与讨论