下面的代码就是楼主上传的附件的内容
- DSP28335SVPWM例程,仅供供大家参考:
- //---------------T1UFINT_ISR------------------------------------------------------
- float Sin_Value(Uint16 Degree)//suitable for N=6,12,18,24
- {
- int Sign=1;
- Uint16 Degree_Index;
- float SinValue;
-
- if(Degree>=360)Degree-=360; //for Cos
- if(Degree>=180)
- {
- Degree-=180;
- Sign=-1;
- }
- Degree_Index=Degree/5;
- SinValue=Sign*Sin180_Table[Degree_Index];
- return(SinValue);
- }
- Uint16 *SoftSvpwmGen(Uint16 *Pa,Uint16 Tpwm,Uint16 Sita,float VectTime)//SW_SVPWM
- { //Vref.Angle<=360degree;Tpwm(Carrier Period Number):Ts/TpwmClk
- volatile float T0,T1,T2,B0,B1,B2;//
- Uint16 Sector=0,alfa=0,k;
- k=Sita/60;
- alfa=Sita-60*k;
-
- if(k==0)Sector=3;
- if(k==1){Sector=1;alfa=60-alfa;}
- if(k==2)Sector=5;
- if(k==3){Sector=4;alfa=60-alfa;}
- if(k==4)Sector=6;
- if(k==5){Sector=2;alfa=60-alfa;}
- if(k>5)Sector=3;
-
- T1=VectTime*Sin_Value(60-alfa);//Cos(alfa+30)=Sin_Value(alfa+120)=Sin_Value(60-alfa)
- T2=VectTime*Sin_Value(alfa);
-
- if((T1+T2)>Tpwm)
- {
- //T0=T1+T2;
- T1*=(Tpwm/(T1+T2));
- //T2*=(Tpwm/T0);
- B0=0; //Taon
- B1=T1/2; //Tbon
- B2=Tpwm/2; //Tcon
-
- }
- else
- {B0=(Tpwm-T1-T2)/4; //Taon
- B1=B0+T1/2; //Tbon
- B2=B1+T2/2; //Tcon
- }
-
-
- switch(Sector)
- {case 1://b,a,c
- {
- *(Pa+0)=B1;
- *(Pa+1)=B0;
- *(Pa+2)=B2;
- }
- break;
- case 2://a,c,b
- {
- *(Pa+0)=B0;
- *(Pa+1)=B2;
- *(Pa+2)=B1;
- }
- break;
- case 3://a,b,c
- {
- *(Pa+0)=B0;
- *(Pa+1)=B1;
- *(Pa+2)=B2;
- }
- break;
- case 4://c,b,a
- {
- *(Pa+0)=B2;
- *(Pa+1)=B1;
- *(Pa+2)=B0;
- }
- break;
- case 5://c,a,b
- {
- *(Pa+0)=B2;
- *(Pa+1)=B0;
- *(Pa+2)=B1;
- }
- break;
- case 6://b,c,a
- {
- *(Pa+0)=B1;
- *(Pa+1)=B2;
- *(Pa+2)=B0;
- }
- break;
- default: {// Sector=0:Vref.Mag=0
- *(Pa+0)=B0;
- *(Pa+1)=B0;
- *(Pa+2)=B0;
- }
- }
- return(Pa);
-
- }
- interrupt void _EPWM1_UFINT_ISR(void) // EV-A
- {
- Uint16 CMPR[3];
- Uint16 *Pcmpr;
- //GpioDataRegs.GPATOGGLE.bit.GPIOA15=1;//XOR(PA15):Communication LED Flash !!
- Vref.Angle+= 360/N;
- if(Vref.Angle>=360)Vref.Angle-=360;
-
- //if(Starting!=0x55 )//(Starting!=0x55) ||(Vref.Mag>=2000.0)||(Vref.Mag<=0)
- //Vref.Mag=2000.0;//FOR TEST!!! 2007.7.21:50->AC:5v
-
- PwmCount++;
- if(PwmCount>=N)PwmCount=0;
-
- //Temp=PwmCount&0x1;
- //if(Temp==0x1)AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;// Enable SW To SOC to start SEQ(SEQ1/SEQ2)
-
- if(PwmCount==0)
- {//:当PwmCount=N(Tr=2.5ms),更新
- //TpwmNum=TPWM_NUM;move to main 2007.8.26
- //Ud=2800;// 2007.12.23
- if(Vref.Mag<0)Vref.Mag=0;
- UoutTime=(SQRT2*TpwmNum*Vref.Mag)/(Ud);
- if(UoutTime>TpwmNum)UoutTime=TpwmNum;
- }
-
- Pcmpr=SoftSvpwmGen(CMPR,TpwmNum,Vref.Angle, UoutTime);
-
- EPwm1Regs.CMPA.half.CMPA = *(Pcmpr+0);
- EPwm2Regs.CMPA.half.CMPA = *(Pcmpr+1);
- EPwm3Regs.CMPA.half.CMPA = *(Pcmpr+2);
- //EPwm4Regs.CMPA.half.CMPA = *(Pcmpr+0);//FOR THREE LEVEL SVPWM
- //EPwm5Regs.CMPA.half.CMPA = *(Pcmpr+1);
- //EPwm6Regs.CMPA.half.CMPA = *(Pcmpr+2);
-
- // Clear INT flag for this timer
- EPwm1Regs.ETCLR.bit.INT = 1;
-
- PieCtrlRegs.PIEACK.all |= PIEACK_GROUP3; // Acknowledge interrupt to PIE
- // Uncomment this line after adding ISR Code
- //return;
- }
复制代码
|
|
|
|
|