void SVPWM_CalcDutyCycle(s16 Va,s16 Vb)
{
signed short X,Y,Z,Tx,Ty;
unsigned short Ta,Tb,Tc;
signed short ua,ub,uc;
unsigned char A,B,C;
unsigned short Tcm1,Tcm2,Tcm3;
unsigned char Sector; //¿Õ¼äʸÁ¿ÉÈÇø
//unsigned short pot,adc,adc2;
//pot=(ADC_ConvertedValue[0]);
//adc=Udc;
//½«ÉÏÇűÛתΪÏÂÇű۱íʾµÄ£¬ÉÈÇø·´180¡ã£¬TIM1µÄPWMģʽҪÉèÖÃΪPWM1¾ÍÐÐÁË
Va=-Va;Vb=-Vb;
X=SQRT3MUL1000*Vb/1000*TS/Udc;
Y=(3*Va+SQRT3MUL1000*Vb/1000)*TS/(2*Udc);
Z=(-3*Va+SQRT3MUL1000*Vb/1000)*TS/(2*Udc);
ua=Vb;ub=(SQRT3MUL1000*Va/1000-Vb)/2;uc=-(SQRT3MUL1000*Va/1000+Vb)/2;
A=(ua>0)?1:0;
B=(ub>0)?1:0;
C=(uc>0)?1:0;
Sector=A+2*B+4*C;//get the sector number */
switch (Sector)
{
case 1:
Tx=Z;Ty=Y;break;
case 2:
Tx=Y;Ty=-X;break;
case 3:
Tx=-Z;Ty=X;break;
case 4:
Tx=-X;Ty=Z;break;
case 5:
Tx=X;Ty=-Y;break;
case 6:
Tx=-Y;Ty=-Z;break;
}
Ta=(u16)((TS-Tx-Ty)/4);
Tb=(u16)(Ta+Tx/2);
Tc=(u16)(Tb+Ty/2); //ÆäÖÐTc×î´ó£¬Ta×îС
switch(Sector)
{
case 4:
Sector=SECTOR_1;break;
case 6:
Sector=SECTOR_2;break;
case 2:
Sector=SECTOR_3;break;
case 3:
Sector=SECTOR_4;break;
case 1:
Sector=SECTOR_5;break;
case 5:
Sector=SECTOR_6;break;
}
/*************************************************/
switch (Sector)
{
case SECTOR_1:
Tcm1=Tc;Tcm2=Tb;Tcm3=Ta;
break;
case SECTOR_2:
Tcm1=Tb;Tcm2=Tc;Tcm3=Ta;
break;
case SECTOR_3:
Tcm1=Ta;Tcm2=Tc;Tcm3=Tb;
break;
case SECTOR_4:
Tcm1=Ta;Tcm2=Tb;Tcm3=Tc;
break;
case SECTOR_5:
Tcm1=Tb;Tcm2=Ta;Tcm3=Tc;
break;
case SECTOR_6:
Tcm1=Tc;Tcm2=Ta;Tcm3=Tb;
break;
}