小弟最近在用ST的2.0电机库 ,发现它的3电阻采样部分的程序代码好乱。尤其是它的ADC的设定和使用。贴出2.0库中的SVPWM算法。他的算法到底是用了ABC三路的电流采样还是用了两路的电流采样计算出第三路。其中的计算每一路电流采样为什么是 0电压误差值减去采样值。不应该是采样值减去0电压误差吗。还有他的算法流程很不解。代码如下:
Curr_Components SVPWM_3ShuntGetPhaseCurrentValues(void)
{
Curr_Components Local_Stator_Currents;
s32 wAux;
switch (bSector)
{
case 4: //È¡µÃÔÚÄǸöÉÈÇøµÄʱºòÔÚ¶ÁÈ¡AD ÒòΪADCÊý¾ÝÑ¡ÔñÁË×ó¶ÔÆ룬ÔÚ×¢ÈëͨµÀÀïÓзûºÅλËùÒÔ²ÅÓÐÊý¾ÝֵΪÎÞ·ûºÅ65535£¨ÓзûºÅÔò32767£©
case 5: //Current on Phase C not accessible
// Ia = (hPhaseAOffset)-(ADC Channel 11 value)
wAux = (s32)(hPhaseAOffset)- ((ADC1->JDR1)<<1);
//Saturation of Ia
if (wAux < S16_MIN)
{
Local_Stator_Currents.qI_Component1= S16_MIN;
}
else if (wAux > S16_MAX)
{
Local_Stator_Currents.qI_Component1= S16_MAX;
}
else
{
Local_Stator_Currents.qI_Component1= wAux;
}
// Ib = (hPhaseBOffset)-(ADC Channel 12 value)
wAux = (s32)(hPhaseBOffset)-((ADC2->JDR1)<<1);
// Saturation of Ib
if (wAux < S16_MIN)
{
Local_Stator_Currents.qI_Component2= S16_MIN;
}
else if (wAux > S16_MAX)
{
Local_Stator_Currents.qI_Component2= S16_MAX;
}
else
{
Local_Stator_Currents.qI_Component2= wAux;
}
break;
case 6:
case 1: //Current on Phase A not accessible
// Ib = (hPhaseBOffset)-(ADC Channel 12 value)
wAux = (s32)(hPhaseBOffset)-((ADC1->JDR1)<<1);
//Saturation of Ib
if (wAux < S16_MIN)
{
Local_Stator_Currents.qI_Component2= S16_MIN;
}
else if (wAux > S16_MAX)
{
Local_Stator_Currents.qI_Component2= S16_MAX;
}
else
{
Local_Stator_Currents.qI_Component2= wAux;
}
// Ia = -Ic -Ib
wAux = ((ADC2->JDR1)<<1)-hPhaseCOffset-
Local_Stator_Currents.qI_Component2;
//Saturation of Ia
if (wAux> S16_MAX)
{
Local_Stator_Currents.qI_Component1 = S16_MAX;
}
else if (wAux <S16_MIN)
{
Local_Stator_Currents.qI_Component1 = S16_MIN;
}
else
{
Local_Stator_Currents.qI_Component1 = wAux;
}
break;
case 2:
case 3: // Current on Phase B not accessible
// Ia = (hPhaseAOffset)-(ADC Channel 11 value)
wAux = (s32)(hPhaseAOffset)-((ADC1->JDR1)<<1);
//Saturation of Ia
if (wAux < S16_MIN)
{
Local_Stator_Currents.qI_Component1= S16_MIN;
}
else if (wAux > S16_MAX)
{
Local_Stator_Currents.qI_Component1= S16_MAX;
}
else
{
Local_Stator_Currents.qI_Component1= wAux;
}
// Ib = -Ic-Ia;
wAux = ((ADC2->JDR1)<<1) - hPhaseCOffset -
Local_Stator_Currents.qI_Component1;
// Saturation of Ib
if (wAux> S16_MAX)
{
Local_Stator_Currents.qI_Component2=S16_MAX;
}
else if (wAux <S16_MIN)
{
Local_Stator_Currents.qI_Component2 = S16_MIN;
}
else
{
Local_Stator_Currents.qI_Component2 = wAux;
}
break;
default:
break;
}
return(Local_Stator_Currents);
}
|