请问哪位大佬能不能解释一下这个函数,我硬件双电阻采集的B、C相电流,这个函数要改吗
stru_CurrPhaseUV SVPWM_2ShuntGetPhaseCurrent(stru_FOC_CurrLoopDef *this)
{
stru_Array_Def mADC_Result;
stru_CurrPhaseUV Local_Stator_Currents;
s32 wAux;
s16 hCurrA = 0, hCurrB = 0, hCurrC = 0;
u8 bCurrASamp = 0, bCurrBSamp = 0;
GET_ADC0_DATA(mADC_Result);//这读的不只是某一项电流吗?
/* First sampling point */
switch (this->bSampCur1)
{
case SAMP_IA://这是静止坐标下的扇区吗?
wAux = (s32)(this->nPhaseAOffset) - mADC_Result.nData0;
hCurrA = sat(wAux, S16_MIN, S16_MAX);
bCurrASamp = 1;
break;
case SAMP_IB:
wAux = (s32)(this->nPhaseBOffset) - mADC_Result.nData0;
hCurrB = sat(wAux, S16_MIN, S16_MAX);
bCurrBSamp = 1;
break;
case SAMP_IC:
wAux = (s32)(this->nPhaseCOffset) - mADC_Result.nData0;
hCurrC = sat(wAux, S16_MIN, S16_MAX);
bCurrBSamp = 1;
break;
case SAMP_NIA:
hCurrA = this->mStatCurrUVW.nPhaseU;
bCurrASamp = 1;
break;
case SAMP_NIB:
hCurrB = this->mStatCurrUVW.nPhaseV;
bCurrBSamp = 1;
break;
case SAMP_NIC:
hCurrC = 0 - this->mStatCurrUVW.nPhaseU - this->mStatCurrUVW.nPhaseV;
break;
default:
wAux = 0;
break;
}
GET_ADC1_DATA(mADC_Result);
/* Second sampling point */
switch (this->bSampCur2)
{
case SAMP_IA:
wAux = (s32)(this->nPhaseAOffset) - mADC_Result.nData0;
hCurrA = sat(wAux, S16_MIN, S16_MAX);
bCurrASamp = 1;
break;
case SAMP_IB:
wAux = (s32)(this->nPhaseBOffset) - mADC_Result.nData0;
hCurrB = sat(wAux, S16_MIN, S16_MAX);
bCurrBSamp = 1;
break;
case SAMP_IC:
wAux = (s32)(this->nPhaseCOffset) - mADC_Result.nData0;
hCurrC = sat(wAux, S16_MIN, S16_MAX);
break;
case SAMP_NIA:
hCurrA = this->mStatCurrUVW.nPhaseU;
bCurrASamp = 1;
break;
case SAMP_NIB:
hCurrB = this->mStatCurrUVW.nPhaseV;
bCurrBSamp = 1;
break;
case SAMP_NIC:
hCurrC = 0 - this->mStatCurrUVW.nPhaseU - this->mStatCurrUVW.nPhaseV;
break;
default:
wAux = 0;
break;
}
if (bCurrASamp == 0)
{ /* 饱和处理 hd */
wAux = -hCurrB - hCurrC;
hCurrA = sat(wAux, S16_MIN, S16_MAX);
}
if (bCurrBSamp == 0)
{
wAux = -hCurrA - hCurrC;
hCurrB = sat(wAux, S16_MIN, S16_MAX);
}
#if (CHIP_PART_NUMBER == LKS32MC057D_V0)
Local_Stator_Currents.nPhaseU = -hCurrA;
#else
Local_Stator_Currents.nPhaseU = hCurrA;
#endif
Local_Stator_Currents.nPhaseV = hCurrB;
return (Local_Stator_Currents);
}
|