+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Newbie level 1
    Points: 39, Level: 1

    Join Date
    Jul 2019
    Posts
    3
    Helped
    0 / 0
    Points
    39
    Level
    1

    SVPWM crooked 3-phase inverter output. What is wrong with the circuit ?[PROTEUS]

    Im simulating a 3 phase inverter circuit driven via SVPWM method. Im using Arduino for code. As it can been seen in diagrams, my input in as it should be.But output is weird, I dont know is causing it. I reviewed my design, but I cant find the issue after spending alot of time. Kindly review it, I/P signal and O/P signals are given below along with the code and schematic.
    Mosfet state table with respect to each sector is shown below.
    Mosfet Table
    Click image for larger version. 

Name:	Screenshot (98).png 
Views:	5 
Size:	18.1 KB 
ID:	154522
    Im using symmetric switching pattern as shown in table.
    Switch Table
    Click image for larger version. 

Name:	sequence table.jpg 
Views:	4 
Size:	29.1 KB 
ID:	154521
    INPUT
    Click image for larger version. 

Name:	Screenshot (96).png 
Views:	7 
Size:	142.2 KB 
ID:	154518
    OUTPUT
    Click image for larger version. 

Name:	Screenshot (95).png 
Views:	7 
Size:	143.5 KB 
ID:	154519
    SCHEMATIC
    Click image for larger version. 

Name:	Screenshot (92).png 
Views:	12 
Size:	74.6 KB 
ID:	154520
    CODE
    Code:
    #include <math.h>
    int sector_pos = 1; //current sector.
    const float freq_sth = 5000.00; // Switching freqency 5000Hz
    float tz = ((1 / freq_sth))/pow(10,-6); // Total switching time Tz in (us)
    float freq = 50.0; // Variable fundamental freqency 
    float m = 0.6; // modulation index (Controls max Vref magnitude) 0>=m<=1.
    int vdc = 100; //rectified voltage
    float timer1 = 0, timer2 = 0, timer0 = 0; //Switching times
    float sample_time = freq_sth / freq; // sample_time(per cycle) = switching_time/fundamental_output_freq.
    float angle = 0; // (in degrees, must be changed to radians.) Gives us angle to be incremented per 'Tz' seconds.
    float base_angle = 360.0 / sample_time; //Base angle will be used to increment angle per cycle.
    float timer_div = 0; // Constant in time calculation equations. (refer to t1,t2 equations)
    double theta1 = 0, theta2 = 0; // trignometric part of t1,t2 equations, computated seperately to reduce clutering of code in one line.(i.e t1 = timer_div*theta1)
    float angle_rad = 0; //Angle in radians.Computed for each 'Tz' seconds in time_cal().
    const int mf1 = 2, mf2 = 3, mf3 = 4, mf4 = 5, mf5 = 6, mf6 = 7; // Arduino digital pins
    int vref = (vdc) * (m); //vref, controlled by some modulation index.
    
    
    
    
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(mf1, OUTPUT);
      pinMode(mf2, OUTPUT);
      pinMode(mf3, OUTPUT);
      pinMode(mf4, OUTPUT);
      pinMode(mf5, OUTPUT);
      pinMode(mf6, OUTPUT);
      digitalWrite(mf1, LOW);
      digitalWrite(mf2, LOW);
      digitalWrite(mf3, LOW);
      digitalWrite(mf4, LOW);
      digitalWrite(mf5, LOW);
      digitalWrite(mf6, LOW);
    
    
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      
      
      sector_tracker();
      time_cal();
      mosfet_switch();  
      angle_incr();
       
    
     // delay(1000);
    
    }
    
    
    void sector_tracker()
    {
     if(angle >= 60) //When angle is >= 60 that means we have covered one 1 sector.
     {
          if(sector_pos != 7) // this condition is here to make sure we are never in sector 7 (i.e wer
          {
          angle = 0;
          sector_pos = sector_pos + 1;
          }
          if(sector_pos == 7) // if after expression 'sector_pos = sector_pos + 1' in above case,we get 7, we need to set everything to initial point since no sector 7 exists.
          { //reason for putting this condition after the above condition is because there was a case when sector_pos = 7 after we update the sector_pos.
            angle = 0;
            sector_pos = 1;
          }
     }
    }
    void angle_incr() {
      angle = angle + base_angle;
    }
    
    void time_cal() {
      timer_div = (2/sqrt(3) * tz * m);
      angle_rad =  angle * (M_PI / 180); //converting angle->degrees to angle->radians. Need radian term for sin.
      theta1 = sin((M_PI/3.0)-angle_rad);
      theta2 = sin(angle_rad);
      timer1 = timer_div * theta1;
      timer2 = timer_div * theta2;
      timer0 = (tz - (timer1 + timer2))/2.0;
      //all time in (us)
      timer1 = round(timer1);
       timer2 = round(timer2);
        timer0 = round(timer0);
      /*Serial.print("Sector: ");
      Serial.println(sector_pos);
      Serial.println("Timer 1:");
      Serial.println(timer1, 5);
      Serial.println("Timer 2:");
      Serial.println(timer2, 5);
      Serial.println("Timer 0:");
      Serial.println(timer0, 5);*/
      
    
    
    }
    void mosfet_switch() {
       //Symmetric switching pattern/sequences used for optimal results.(low THD etc)
       //refer to 'document' for rules for each V-state switches. 
       //switches in each V-state are defined by table( using the one given at wikipedia)
      if (sector_pos == 1)
      {
        //v0-v1-v2-v7-v2-v1-v0
        //-----
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v1:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v2:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v2:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v1:
         digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
      }
      if (sector_pos == 2)
      {
        //v0-v3-v2-v7-v2-v3-v0
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v3:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v2:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v2:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v3:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        
      }
      if (sector_pos == 3)
      {
        //v0-v3-v4-v7-v4-v3-v0
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v3:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v4:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v4:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v3:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer1);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
      }
      if (sector_pos == 4)
      {
        //v0-v5-v4-v7-v4-v5-v0
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v5:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v4:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v4:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v5:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
      }
      if (sector_pos == 5)
      {
        //v0-v5-v6-v7-v6-v5-v0
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v5:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v6:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v6:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer2);
        //v5:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
      }
      if (sector_pos == 6)
      {
        //v0-v1-v6-v7-v6-v1-v0
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        //v1:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v6:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v7:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,HIGH);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,LOW);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer0);
        //v6:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,HIGH);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,LOW);
        delayMicroseconds(timer1);
        //v1:
        digitalWrite(mf1,HIGH);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,LOW);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer2);
        //v0:
        digitalWrite(mf1,LOW);
        digitalWrite(mf3,LOW);
        digitalWrite(mf5,LOW);
        digitalWrite(mf2,HIGH);
        digitalWrite(mf4,HIGH);
        digitalWrite(mf6,HIGH);
        delayMicroseconds(timer0);
        
      }
    
    
    
    }

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 77,827, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,771
    Helped
    3590 / 3590
    Points
    77,827
    Level
    68

    Re: SVPWM crooked 3-phase inverter output. What is wrong with the circuit ?[PROTEUS]

    Hi,

    Without the information what the scope pictures show, they are about useless.
    Where dud you connect "input" and "output"?

    If possible show all scope pictures with the same timing setup...at least when the signals relate to each other.
    Please (use paper and pencil to) show us how you expect the signals to be.

    10nF as bootstrap capacitor is relatively small - especially with your low frequency. Also I doubt the 1N4148 is suitable. Please read datasheet and application notes of the driver manufacturer. There is a good reason why they wrote them.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



--[[ ]]--