Saturday, October 21, 2017

Design Regular Sampled PWM 3 Phase Inverter using MATLAB

Draw a flowchart for the implementation of regular sample PWM for a 3 Phase inverter taking m, p, Fr as inputs and Sa, Sb, Sc as outputs. You may consider updating new inputs after each N no of reference cycles.(i.e Np no of carrier cycles).Implement your design for a 3 phase inverter with an input DC voltage of 600V,with a connected load of 10Ω and 30mH per phase in star. Give the Phase, Line and Pole voltages and Phase currents, DC input currents for following cases.
Case 1:
                     Fr=50 Hz, m=60%, p=99
Case 2:
                     Fr=50 Hz, m=60%, p=21
Assume no blanking time consideration

Flow Chart

Matlab Simulink Design
IGBT Bridge

Programming Part

Matlab code for Leg A
function Sa = fcn(clk)
m=0.6;   % Depth of modulation
Fr=50;   % desired FreQ
p=21;    % carrier ratio (no of sampling instances)
Fc=p*Fr;  % carrier freQ
Tc=1/Fc;  %carrier signal cycle time
Tr=1/Fr;  % Desired signal cycle time

Sa=0;  % begins with Sa=0

    Tha=zeros(1,21); % Build matrix of 1*21 to store Sa high times
    for k=1:p
        Tha(k)=(1+m*sin(2*pi*k/p))/(2*p*Fr);   % calculte and store Sa high time in matrix Tha
    end

    Tla=zeros(1,21);  % Build matrix of 1*21 to store Sa Low times
    for i=1:p
        Tla(i)=(Tc-Tha(i))/2; % sampling instant have [Tha low/2-- Tha High---Tha Low/2]
    end
  


    SwitchingDataA=zeros(1,63); % build matrix to store all the switching time periods
    AddTime=0; % this variable is used to add the time continuously
    var=0;
    for i=1:21     %store switching time periods in the matrix
        if(i==1)
            SwitchingDataA(i)=Tla(i);  % store 1st switching time
            AddTime=Tla(i);
            SwitchingDataA(i+1)=AddTime+Tha(i);
            AddTime=AddTime+Tha(i);
            SwitchingDataA(i+2)=AddTime+Tla(i);
            AddTime=AddTime+Tla(i);

        end
        if(i>1)
            SwitchingDataA(i+i+var)=AddTime+Tla(i);
            AddTime=AddTime+Tla(i);
            SwitchingDataA(i+i+1+var)=AddTime+Tha(i);
            AddTime=AddTime+Tha(i);
            SwitchingDataA(i+i+2+var)=AddTime+Tla(i);
            AddTime=AddTime+Tla(i);
            var=var+1;


        end

    end




timeInstantFromBegin=mod(clk,0.02);  % Get time from begining of desired cycle time


    for i=1:21    % give output signal according to the calculated Tha and Tla.Compare with time and apply
        if i<2
            if(timeInstantFromBegin>(SwitchingDataA(i)))&&(timeInstantFromBegin<(SwitchingDataA(i+1)))
                Sa=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataA(i+1)))&&(timeInstantFromBegin<(SwitchingDataA(i+2)))
                Sa=0;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataA(i+2)))&&(timeInstantFromBegin<(SwitchingDataA(i+3)))
                Sa=0;
              
                break;
            end
        elseif(i<21)&&(i>1)
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataA(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataA(i+i+x+1)))
                Sa=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataA(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataA(i+i+x+2)))
                Sa=0;
               
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataA(i+i+x+2)))&&(timeInstantFromBegin<(SwitchingDataA(i+i+x+3)))
                Sa=0;
                break;
            end
           
        else
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataA(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataA(i+i+x+1)))
                Sa=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataA(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataA(i+i+x+2)))
                Sa=0;
                break;
            end
        end
       
    
    end
   




Matlab Code for Leg B
function Sb = fcn(clk)
m=0.6;  % Depth of modulation
Fr=50;   % desired FreQ
p=21;  % carrier ratio (no of sampling instances)
Fc=p*Fr; % carrier freQ
Tc=1/Fc; %carrier signal cycle time
Tr=1/Fr;  % Desired signal cycle time


Sb=0; % begins with Sb=0;

    Thb=zeros(1,21);  % Build matrix of 1*21 to store Sb high times
    for k=1:p
        Thb(k)=(1+m*sin(2*pi*k/p-2*pi/3))/(2*p*Fr);   % calculte and store Sb high time in matrix Thb
    end


    Tlb=zeros(1,21);   % Build matrix of 1*21 to store Sb Low times
    for i=1:p
        Tlb(i)=(Tc-Thb(i))/2;  % sampling instant have [Tlb low/2-- Thb High---Tlb Low/2]
    end
  


    SwitchingDataB=zeros(1,63);% build matrix to store all the switching time periods
    AddTime=0;  % this variable is used to add the time continuously
    var=0;
    for i=1:21   %store switching time periods in the matrix
        if(i==1)
            SwitchingDataB(i)=Tlb(i);  % store 1st switching time
            AddTime=Tlb(i);
            SwitchingDataB(i+1)=AddTime+Thb(i);
            AddTime=AddTime+Thb(i);
            SwitchingDataB(i+2)=AddTime+Tlb(i);
            AddTime=AddTime+Tlb(i);

        end
        if(i>1)
            SwitchingDataB(i+i+var)=AddTime+Tlb(i);
            AddTime=AddTime+Tlb(i);
            SwitchingDataB(i+i+1+var)=AddTime+Thb(i);
            AddTime=AddTime+Thb(i);
            SwitchingDataB(i+i+2+var)=AddTime+Tlb(i);
            AddTime=AddTime+Tlb(i);
            var=var+1;


        end

    end




timeInstantFromBegin=mod(clk,0.02); % Get time from begining of desired cycle time


    for i=1:21  % give output signal according to the calculated Thb and Tlb.Compare with time and apply
        if i<2
            if(timeInstantFromBegin>(SwitchingDataB(i)))&&(timeInstantFromBegin<(SwitchingDataB(i+1)))
                Sb=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataB(i+1)))&&(timeInstantFromBegin<(SwitchingDataB(i+2)))
                Sb=0;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataB(i+2)))&&(timeInstantFromBegin<(SwitchingDataB(i+3)))
                Sb=0;
              
                break;
            end
        elseif(i<21)&&(i>1)
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataB(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataB(i+i+x+1)))
                Sb=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataB(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataB(i+i+x+2)))
                Sb=0;
               
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataB(i+i+x+2)))&&(timeInstantFromBegin<(SwitchingDataB(i+i+x+3)))
                Sb=0;
                break;
            end
           
        else
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataB(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataB(i+i+x+1)))
                Sb=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataB(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataB(i+i+x+2)))
                Sb=0;
                break;
            end
        end
       
    
    end





Matlab Code for Leg C
function Sc = fcn(clk)

m=0.6;   % Depth of modulation
Fr=50;   % desired FreQ
p=21;  % carrier ratio (no of sampling instances)
Fc=p*Fr;  % carrier freQ
Tc=1/Fc;  %carrier signal cycle time
Tr=1/Fr;   % Desired signal cycle time

Sc=0;   % begins with Sc=0;

    Thc=zeros(1,21);  % Build matrix of 1*21 to store Sc high times
    for k=1:p
        Thc(k)=(1+m*sin(2*pi*k/p-4*pi/3))/(2*p*Fr);   % calculte and store Sc high time in matrix Thc
    end

    Tlc=zeros(1,21);  % Build matrix of 1*21 to store Sc Low times
    for i=1:p
        Tlc(i)=(Tc-Thc(i))/2;   % sampling instant have [Tlc low/2-- Thc High---Tlc Low/2]
    end
  


    SwitchingDataC=zeros(1,63); % build matrix to store all the switching time periods
    AddTime=0;  % this variable is used to add the time continuously
    var=0;
    for i=1:21   %store switching time periods in the matrix
        if(i==1)
            SwitchingDataC(i)=Tlc(i);   % store 1st switching time
            AddTime=Tlc(i);
            SwitchingDataC(i+1)=AddTime+Thc(i);
            AddTime=AddTime+Thc(i);
            SwitchingDataC(i+2)=AddTime+Tlc(i);
            AddTime=AddTime+Tlc(i);

        end
        if(i>1)
            SwitchingDataC(i+i+var)=AddTime+Tlc(i);
            AddTime=AddTime+Tlc(i);
            SwitchingDataC(i+i+1+var)=AddTime+Thc(i);
            AddTime=AddTime+Thc(i);
            SwitchingDataC(i+i+2+var)=AddTime+Tlc(i);
            AddTime=AddTime+Tlc(i);
            var=var+1;


        end

    end




timeInstantFromBegin=mod(clk,0.02);  % Get time from begining of desired cycle time


    for i=1:21    % give output signal according to the calculated Thc and Tlc.Compare with time and apply
        if i<2
            if(timeInstantFromBegin>(SwitchingDataC(i)))&&(timeInstantFromBegin<(SwitchingDataC(i+1)))
                Sc=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataC(i+1)))&&(timeInstantFromBegin<(SwitchingDataC(i+2)))
                Sc=0;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataC(i+2)))&&(timeInstantFromBegin<(SwitchingDataC(i+3)))
                Sc=0;
              
                break;
            end
        elseif(i<21)&&(i>1)
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataC(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataC(i+i+x+1)))
                Sc=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataC(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataC(i+i+x+2)))
                Sc=0;
               
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataC(i+i+x+2)))&&(timeInstantFromBegin<(SwitchingDataC(i+i+x+3)))
                Sc=0;
                break;
            end
           
        else
            x=i-2;
            if(timeInstantFromBegin>(SwitchingDataC(i+i+x)))&&(timeInstantFromBegin<(SwitchingDataC(i+i+x+1)))
                Sc=1;
                break;
            end
            if(timeInstantFromBegin>(SwitchingDataC(i+i+x+1)))&&(timeInstantFromBegin<(SwitchingDataC(i+i+x+2)))
                Sc=0;
                break;
            end
        end
       
    
    end





Case 1: Fr=50 Hz, m=60%, p=99

Leg A, B, C signals ( Sa, Sb, Sc)

DC input Current

Pole Voltages

Phase Voltages
Line Voltages
Phase Currents

Case 2 : Fr=50, m=60%, p=21

Leg A, B, C signals (Sa, Sb, Sc)
DC input Current


Pole Voltages
Phase Voltages
Line Voltages
Phase Currents