TMS320F28335_SVPWM完整程序

1、主函数

/*===============头文件================*/
#include "DSP2833x_Project.h"
#include "C28x_FPU_FastRTS.h"
#include 
//将用户定义的头文件包含进来
#include "SVPWM_2L.h"

int i;

SVPWM_2L Svpwm = SVPWM_2L_DEFAULTS;

float alpha[60]={200.0000, 198.8670, 195.4807, 189.8795, 182.1270, 172.3108,
        160.5423, 146.9548, 131.7023, 114.9575, 96.9102, 77.7648,
        57.7384, 37.0577, 15.9572, -5.3241, -26.5451, -47.4653,
        -67.8478, -87.4615, -106.0842, -123.5049, -139.5263, -153.9668,
        -166.6628, -177.4704, -186.2672, -192.9536, -197.4537, -199.7165,
        -199.7165, -197.4537, -192.9536, -186.2672, -177.4704, -166.6628,
        -153.9668, -139.5263, -123.5049, -106.0842, -87.4615, -67.8478,
        -47.4653, -26.5451, -5.3241, 15.9572, 37.0577, 57.7384, 77.7648,
        96.9102, 114.9575, 131.7023, 146.9548, 160.5423, 172.3108, 182.1270,
        189.8795, 195.4807, 198.8670, 200.0000};

float beta[60]={0.0000, 21.2587, 42.2765, 62.8153, 82.6424, 101.5332, 119.2735,
        135.6624, 150.5142, 163.6606, 174.9526, 184.2624, 191.4844,
        196.5368, 199.3624, 199.9291, 198.2306, 194.2860, 188.1401,
        179.8624, 169.5469, 157.3103, 143.2913, 127.6488, 110.5600,
        92.2185, 72.8321, 52.6205, 31.8127, 10.6444, -10.6444, -31.8127,
        -52.6205, -72.8321, -92.2185, -110.5600, -127.6488, -143.2913,
        -157.3103, -169.5469, -179.8624, -188.1401, -194.2860, -198.2306,
        -199.9291, -199.3624, -196.5368, -191.4844, -184.2624, -174.9526,
        -163.6606, -150.5142, -135.6624, -119.2735, -101.5332, -82.6424,
        -62.8153, -42.2765, -21.2587, -0.0000};

/* ===============函数声明================*/
void Dlog_init(void);   //Dlog初始化函数

/*=================主程序================*/
void main()
{
 InitSysCtrl(); //系统初始化
  DINT;//关闭全局中断
 InitPieCtrl();//初始化中断控制寄存器
  IER = 0x0000;//关闭CPU中断
  IFR = 0x0000;//清除CPU中断信号
 InitPieVectTable();//初始化中断向量表

  EINT; //开CPU中断
  ERTM;

  while(1)
      {
      //----两电平逆变器的控制-----------------------------------------------------------
      //两电平SVPWM算法
      for (i=0;i<60;i++)
          {
          Svpwm.Ualpha = alpha[i];
          Svpwm.Ubeta  = beta[i]; 
          Svpwm.Vdc = 300;  
          Svpwm.calc(&Svpwm);

          if(i==60)
          {i=0;}
          }
      }
}
//==============================================================
//End of file.
//==============================================================

2、svpwm.c

/*===============SVPWM_2L.c================*/
#include "DSP2833x_Project.h"
#include "C28x_FPU_FastRTS.h"
#include <math.h>
#include "SVPWM_2L.h"

//======== Definations for functions ===========================
//**********************************
/*
  @ Description:
  @ Param
  @ Return
*/
//**********************************
void svpwm_2l_calc(SVPWM_2L *p)
{
 float temp;
 float X,Y,Z, t1,t2;
 Uint16 A,B,C,N,Sector;
 float Ta, Tb, Tc;
 float K=1.73205081;//sqrt(3)


 p->T=1.0;//将整个调制周期归一化处理

 X= K*p->Ubeta/p->Vdc*p->T;
 Y=(K*p->Ubeta+3*p->Ualpha)/(2*p->Vdc)*p->T;
 Z=(K*p->Ubeta-3*p->Ualpha)/(2*p->Vdc)*p->T;
//
 if(p->Ubeta>0)
   {A=1;}
 else
   {A=0;}

 if( (K*p->Ualpha - p->Ubeta)>0 )
   {B=1;}
 else
   {B=0;}

 if((-K*p->Ualpha - p->Ubeta)>0)
   {C=1;}
 else
   {C=0;}

 N=A+2*B+4*C;
//
 switch(N)
 {
case 1:{Sector=2;break;}
case 2:{Sector=6;break;}
case 3:{Sector=1;break;}
case 4:{Sector=4;break;}
case 5:{Sector=3;break;}
case 6:{Sector=5;break;}
 default:{;}
 }
 //
switch(Sector)
{
case 1: {t1=-Z; t2= X;break;}
case 2: {t1= Z; t2= Y;break;}
case 3: {t1= X; t2=-Y;break;}
case 4: {t1=-X; t2= Z;break;}
case 5: {t1=-Y; t2=-Z;break;}
case 6: {t1= Y; t2=-X;break;}
  default:{;}
}

if((t1+t2)>p->T)//对过调制情况进行调整
 {
  temp=t1+t2;
  t1=t1*p->T/temp;
  t2=t2*p->T/temp;
 }

//
 Ta=(p->T-t1-t2)/4;//作用时间分配
 Tb=Ta+t1/2;
 Tc=Tb+t2/2; 

 switch(Sector)
  {
    case 1: {p->Tcmpa=Ta; p->Tcmpb=Tb; p->Tcmpc=Tc; break;}
    case 2: {p->Tcmpa=Tb; p->Tcmpb=Ta; p->Tcmpc=Tc; break;}
    case 3: {p->Tcmpa=Tc; p->Tcmpb=Ta; p->Tcmpc=Tb; break;}
    case 4: {p->Tcmpa=Tc; p->Tcmpb=Tb; p->Tcmpc=Ta; break;}
    case 5: {p->Tcmpa=Tb; p->Tcmpb=Tc; p->Tcmpc=Ta; break;}
    case 6: {p->Tcmpa=Ta; p->Tcmpb=Tc; p->Tcmpc=Tb; break;} 
      default:{;}

  }
}

//==============================================================
//End of file.
//==============================================================

3、svpwm.h

/*===============SVPWM_2L.h================*/
#ifndef SVPWM_2L_H
#define SVPWM_2L_H
#include "C28x_FPU_FastRTS.h"

//-----------------------------------------------------------------------------
//  Define the structure of the POSSPEED Object 
//-----------------------------------------------------------------------------
typedef struct  { float  Ualpha;  // Input: reference alpha-axis phase voltage 
          float  Ubeta;   // Input: reference beta-axis phase voltage 
          float  Vdc;     // Input: DC voltage
          float  T;       // Input: PWM Modulation Period 
          float  Tcmpa; // Output: reference phase-a switching function     
          float  Tcmpb; // Output: reference phase-b switching function 
          float  Tcmpc; // Output: reference phase-c switching function
          void (*calc)();       // Pointer to calculation function
        } SVPWM_2L;



//-----------------------------------------------------------------------------
// Define a POSSPEED_handle
//-----------------------------------------------------------------------------
typedef SVPWM_2L *SVPWM_2L_handle;


//-----------------------------------------------------------------------------
// Default initializer for the POSSPEED Object.
//-----------------------------------------------------------------------------
#define SVPWM_2L_DEFAULTS {0,0,0,1.0,\
                           1,1,1,\
                           (void (*)(Uint32))svpwm_2l_calc}

//-----------------------------------------------------------------------------
//  Prototypes for the functions in posspeed.c                                 
//-----------------------------------------------------------------------------
void svpwm_2l_calc(SVPWM_2L_handle);

#endif

//==============================================================
//End of file.
//==============================================================

你可能感兴趣的:(dsp)