//###########################################################################
//TITLE:
//
//###########################################################################
// 版本 | 年 月 日 | Description of changes
// =====|=============|====== |===============================================
// 1.0 | 2012 09 18 | | test
//###########################################################################
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "float.h"
#define PI 3.1415926
#define PERIODIC 3750
#define N 200 //开环测试设定细分
#define delta 2* PI/N //每步角度
#define baserpm 500
interrupt void epwm1_isr(void)
{
GpioDataRegs.GPBDAT.bit.GPIO39 = 1;
encoder();
Adconv();
clark(); //clark变换-----------A,B,C->αβ
park(); //park变换------------αβ->dq
//-----------开环测试-------------------------------------------------------
Ualpha=Kp* cos(i* delta); //w=2*PI*F
Ubeta =Kp* sin(i* delta);
i++;
if(i>=N){i=1;}
svpwm();
GpioDataRegs.GPBDAT.bit.GPIO39 = 0;
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void svpwm(void)
{
//float Va,Vb,Vc,t1,t2,Ta,Tb,Tc;
//int sector=0;
//-----------clark逆变换---------------------------------αβ->a,b,c 扇区判断
Va=Ubeta;
Vb=(-0.5)* Ubeta+0.8660254* Ualpha;
Vc=(-0.5)* Ubeta-0.8660254* Ualpha;
sector=0;
if(Va>0){sector=1;}
if(Vb>0){sector=sector+2;}
if(Vc>0){sector=sector+4;}
//------------------------X,Y,Z(Va,Vb,Vc),计算导通时间----------------------------
Va=Ubeta;
Vb=(0.5)* Ubeta+0.8660254* Ualpha;
Vc=(0.5)* Ubeta-0.8660254* Ualpha;
if(sector==3) //扇区1 100
{
t1=-Vc;
t2=Va;
Ta=0.25* (1-t1-t2);
Tb=Ta+ 0.5* t1;
Tc=Tb+ 0.5* t2;
}
else if(sector==1)//扇区2 110
{
t1=Vc;
t2=Vb;
Tb=0.25* (1-t1-t2);
Ta=Tb+ 0.5* t1;
Tc=Ta+ 0.5* t2;
}
else if(sector==5)//扇区3 010
{
t1=Va;
t2=-Vb;
Tb=0.25* (1-t1-t2);
Tc=Tb+ 0.5* t1;
Ta=Tc+ 0.5* t2;
}
else if(sector==4)//扇区4 011
{
t1=-Va;
t2=Vc;
Tc=0.25* (1-t1-t2);
Tb=Tc+ 0.5* t1;
Ta=Tb+ 0.5* t2;
}
else if(sector==6)//扇区5 001
{
t1=-Vb;
t2=-Vc;
Tc=0.25* (1-t1-t2);
Ta=Tc+ 0.5* t1;
Tb=Ta+ 0.5* t2;
}
else if(sector==2)//扇区6 101
{
t1=Vb;
t2=-Va;
Ta=0.25* (1-t1-t2);
Tc=Ta+ 0.5* t1;
Tb=Tc+ 0.5* t2;
}
else //扇区0,扇区7
{
Ta=0.5;
Tb=0.5;
Tc=0.5;
}
tmr1=Ta* PERIODIC;
tmr2=Tb* PERIODIC;
tmr3=Tc* PERIODIC;
EPwm1Regs.CMPA.half.CMPA = tmr1;
EPwm2Regs.CMPA.half.CMPA = tmr2;
EPwm3Regs.CMPA.half.CMPA = tmr3;
}
//--------------------------------------循环
void alldeal(void)
{
for(;;)
int800=0x0;
}
//***************************end***********************************
//===========================================================================
// No more.
//===========================================================================
|