void SVPWM(const AB_OBJ *pInVect2, SVPWM_OBJ *pOutSVPWM)
{
float fTemp1, fTemp2, fTemp3, ftemp4;
char byTemp1=0;
pOutSVPWM->fSum = 0;
//顺时针
pOutSVPWM->fRefU1 = pInVect2->fBate;
pOutSVPWM->fRefU2 = pInVect2->fAlpha * (0.866025f) - pInVect2->fBate * 0.5f;
pOutSVPWM->fRefU3 = pInVect2->fAlpha * (-0.866025f) - pInVect2->fBate * 0.5f;
pOutSVPWM->bySectorSelect1 = (pOutSVPWM->fRefU1) > 0 ? (1) : (0);
pOutSVPWM->bySectorSelect2 = (pOutSVPWM->fRefU2) > 0 ? (1) : (0);
pOutSVPWM->bySectorSelect3 = (pOutSVPWM->fRefU3) > 0 ? (1) : (0);
byTemp1=pOutSVPWM->bySectorSelect1 | (pOutSVPWM->bySectorSelect2) << 1 | (pOutSVPWM->bySectorSelect3) << 2;
switch(byTemp1)
{
case 1:
pOutSVPWM->bySector=2;
break;
case 2:
pOutSVPWM->bySector=6;
break;
case 3:
pOutSVPWM->bySector=1;
break;
case 4:
pOutSVPWM->bySector=4;
break;
case 5:
pOutSVPWM->bySector=3;
break;
case 6:
pOutSVPWM->bySector=5;
break;
}
switch (pOutSVPWM->bySector)
{
case 1:
pOutSVPWM->fTx = pOutSVPWM->fRefU2 * pOutSVPWM->fK;
pOutSVPWM->fTy = pOutSVPWM->fRefU1 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
case 2:
pOutSVPWM->fTx = -pOutSVPWM->fRefU2 * pOutSVPWM->fK;
pOutSVPWM->fTy = -pOutSVPWM->fRefU3 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
case 3:
pOutSVPWM->fTx = pOutSVPWM->fRefU1 * pOutSVPWM->fK;
pOutSVPWM->fTy = pOutSVPWM->fRefU3 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
case 4:
pOutSVPWM->fTx = -pOutSVPWM->fRefU1 * pOutSVPWM->fK;
pOutSVPWM->fTy = -pOutSVPWM->fRefU2 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
case 5:
pOutSVPWM->fTx = pOutSVPWM->fRefU3 * pOutSVPWM->fK;
pOutSVPWM->fTy = pOutSVPWM->fRefU2 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
case 6:
pOutSVPWM->fTx = -pOutSVPWM->fRefU3 * pOutSVPWM->fK;
pOutSVPWM->fTy = -pOutSVPWM->fRefU1 * pOutSVPWM->fK;
pOutSVPWM->fTz = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.5f;
break;
default:
break;
}
if (pOutSVPWM->fTx + pOutSVPWM->fTy > _TIM1_ARR)
{
pOutSVPWM->fSum = pOutSVPWM->fTx + pOutSVPWM->fTy;
pOutSVPWM->fTx = pOutSVPWM->fTx / pOutSVPWM->fSum * _TIM1_ARR;
pOutSVPWM->fTy = pOutSVPWM->fTy / pOutSVPWM->fSum * _TIM1_ARR;
pOutSVPWM->fTz = 0;
}
if (1 == pOutSVPWM->byPWMMode)
{
pOutSVPWM->fTa = (_TIM1_ARR - pOutSVPWM->fTx - pOutSVPWM->fTy) * 0.25f;
pOutSVPWM->fTb = pOutSVPWM->fTa + 0.5f * pOutSVPWM->fTx;
pOutSVPWM->fTc = pOutSVPWM->fTb + pOutSVPWM->fTy * 0.5f;
}
else if (2 == pOutSVPWM->byPWMMode)
{
pOutSVPWM->fTa = (_TIM1_ARR + pOutSVPWM->fTx + pOutSVPWM->fTy) * 0.25f;
pOutSVPWM->fTb = pOutSVPWM->fTa - 0.5f * pOutSVPWM->fTx;
pOutSVPWM->fTc = pOutSVPWM->fTb - pOutSVPWM->fTy * 0.5f;
}
fTemp1=pOutSVPWM->fTa;
fTemp2=pOutSVPWM->fTb;
fTemp3=pOutSVPWM->fTc;
switch(pOutSVPWM->bySector)
{
case 1:
pOutSVPWM->fTa = fTemp1;
pOutSVPWM->fTb = fTemp2;
pOutSVPWM->fTc = fTemp3;
break;
case 2:
pOutSVPWM->fTa = fTemp2;
pOutSVPWM->fTb = fTemp1;
pOutSVPWM->fTc = fTemp3;
break;
case 3:
pOutSVPWM->fTa = fTemp3;
pOutSVPWM->fTb = fTemp1;
pOutSVPWM->fTc = fTemp2;
break;
case 4:
pOutSVPWM->fTa = fTemp3;
pOutSVPWM->fTb = fTemp2;
pOutSVPWM->fTc = fTemp1;
break;
case 5:
pOutSVPWM->fTa = fTemp2;
pOutSVPWM->fTb = fTemp3;
pOutSVPWM->fTc = fTemp1;
break;
case 6:
pOutSVPWM->fTa = fTemp1;
pOutSVPWM->fTb = fTemp3;
pOutSVPWM->fTc = fTemp2;
break;
default:
break;
}
// TIM1Chan3NPDuty((Uint16)pOutSVPWM->fTa, (Uint16)pOutSVPWM->fTb, (Uint16)pOutSVPWM->fTc);
}