# error in space vector modulation function .

2 views (last 30 days)
Mohit kumar on 28 Mar 2021
Commented: Mohit kumar on 4 Apr 2021
I have written a code in matlab function block to generate switching pulses for three phase VSI ,but i am getting an error ,please suggest something valuable. Thanks in advance.
code:
%Inputs are magnitude u1(:),angle u2(:)
%ramp signal for comparison u3(:)
function [sa,sb,sc]=AAA(u)
ts=0.0002; Vdc=1; peak_peak_max=Vdc/sqrt(3);
x=u(1);y=u(2); mag=(u/peak_peak_max)*ts;
% sector 1
if (x >=0) && (x < (pi/6))
ta=mag*sin(pi/3 - x); tb=mag*sin(x);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 1, 1, 1,1,1,1]; v2=[1,1,0,0,1,1]; v3=[1,0,0,0,0,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 1.1
elseif(x >=pi/6) && (x < (pi/3))
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 0, 1, 1,1,1,0]; v2=[0,0,1,1,0,0]; v3=[0,0,0,0,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 2
elseif (x >=pi/3) && (x < (pi/2))
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 0, 0, 1,1,0,0]; v2=[0,1,1,1,0,0]; v3=[0,0,0,0,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 2.1
elseif (x >=pi/2) && (x < (2*pi/3))
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[ 1, 1, 0,0,1,1]; v2 =[1,1,1,1,1,1]; v3 = [1,0,0,0,0,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 3
elseif (x >=2*pi/3) && (x < (5*pi/6))
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[ 1,0,0,0,0,1]; v2 =[1,1,1,1,1,1]; v3 = [1,1,0,0,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 3.1
elseif (x >=5*pi/6) && (x < pi )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,0,0,0,0,0]; v2 =[0,1,1,1,1,0]; v3 = [0,0,1,1,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 4
elseif (x >=pi) && (x < 7*pi/6 )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,0,0,0,0,1]; v2 =[1,1,0,0,1,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 4.1
elseif (x >=7*pi/6) && (x < 4*pi/3 )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,0,0,0,0,1]; v2 =[1,1,0,0,1,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 5
elseif (x >=4*pi/3) && (x < 3*pi/2 )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,0,0,1,1,0]; v2 =[0,0,0,0,0,0]; v3 = [0,1,1,1,1,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 5.1
elseif (x >=3*pi/2) && (x < 5*pi/3 )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,1,0,0,1,1]; v2 =[1,0,0,0,0,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 6
elseif (x >=5*pi/3) && (x < 11*pi/6 )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,1,1,1,1,0]; v2 =[0,0,0,0,0,0]; v3 = [0,0,1,1,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb= v2(j); sc= v3(j);
%sector 6.1
elseif (x >=11*pi/6) && (x < 2*pi )
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,1,1,1,1,1]; v2 =[1,0,0,0,0,1]; v3 = [1,1,0,0,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb= v2(j); sc= v3(j);
end
Error i am getting: not able to relate like what it is talking about.

Chidvi Modala on 31 Mar 2021
Reason : Your 'x' might fall out of the ranges you've specified. Hence the error 'Output argument sa is not assigned on some execution paths'
Workaround : You may try assigning an initial value for sa or you can replace the last elseif with else, whichever suits your case.
Mohit kumar on 4 Apr 2021
okay sir, I will try it out. Thank you for your precious advice.

### Categories

Find more on Switches and Breakers in Help Center and File Exchange

R12.1

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!