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);
void main()
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EINT;
ERTM;
while(1)
{
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;}
}
}
}
2、svpwm.c
#include "DSP2833x_Project.h"
#include "C28x_FPU_FastRTS.h"
#include <math.h>
#include "SVPWM_2L.h"
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;
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:{;}
}
}
3、svpwm.h
#ifndef SVPWM_2L_H
#define SVPWM_2L_H
#include "C28x_FPU_FastRTS.h"
typedef struct { float Ualpha;
float Ubeta;
float Vdc;
float T;
float Tcmpa;
float Tcmpb;
float Tcmpc;
void (*calc)();
} SVPWM_2L;
typedef SVPWM_2L *SVPWM_2L_handle;
#define SVPWM_2L_DEFAULTS {0,0,0,1.0,
1,1,1,
(void (*)(Uint32))svpwm_2l_calc}
void svpwm_2l_calc(SVPWM_2L_handle);
#endif