SPRUHJ1I January 2013 – October 2021 TMS320F2802-Q1 , TMS320F28026-Q1 , TMS320F28026F , TMS320F28027-Q1 , TMS320F28027F , TMS320F28027F-Q1 , TMS320F28052-Q1 , TMS320F28052F , TMS320F28052F-Q1 , TMS320F28052M , TMS320F28052M-Q1 , TMS320F28054-Q1 , TMS320F28054F , TMS320F28054F-Q1 , TMS320F28054M , TMS320F28054M-Q1 , TMS320F2806-Q1 , TMS320F28062-Q1 , TMS320F28062F , TMS320F28062F-Q1 , TMS320F28068F , TMS320F28068M , TMS320F28069-Q1 , TMS320F28069F , TMS320F28069F-Q1 , TMS320F28069M , TMS320F28069M-Q1
The function softwareUpdate1p6() is a work-around for a bug in InstaSPIN-FOC v1.6 to correct how inductance is converted from Henries to per unit value when using the inductance from user.h. This function needs to be called whenever motor parameters are loaded from user.h when using InstaSPIN-FOC v1.6.
The following fixes are in this patch:
Following is the source code to the patch, it is used in every InstaSPIN-FOC v1.6 and InstaSPIN-MOTION lab example.
void softwareUpdate1p6(CTRL_Handle handle)
{
CTRL_Obj *obj = (CTRL_Obj *)handle;
float_t fullScaleInductance = EST_getFullScaleInductance(obj->estHandle);
float_t Ls_coarse_max = _IQ30toF(EST_getLs_coarse_max_pu(obj->estHandle));
int_least8_t lShift = ceil(log(obj->motorParams.Ls_d/(Ls_coarse_max*fullScaleInductance))/log(2.0));
uint_least8_t Ls_qFmt = 30 - lShift;
float_t L_max = fullScaleInductance * pow(2.0,lShift);
_iq Ls_d_pu = _IQ30(obj->motorParams.Ls_d / L_max);
_iq Ls_q_pu = _IQ30(obj->motorParams.Ls_q / L_max);
float_t RoverL = obj->motorParams.Rs/obj->motorParams.Ls_d;
float_t fullScaleCurrent = EST_getFullScaleCurrent(obj->estHandle);
float_t fullScaleVoltage = EST_getFullScaleVoltage(obj->estHandle);
float_t ctrlPeriod_sec = CTRL_getCtrlPeriod_sec(ctrlHandle);
_iq Kp = _IQ((0.25*obj->motorParams.Ls_d*fullScaleCurrent)/(ctrlPeriod_sec*fullScaleVoltage));
_iq Ki = _IQ(RoverL*ctrlPeriod_sec);
_iq Kd = _IQ(0.0);
// store the results
EST_setLs_d_pu(obj->estHandle,Ls_d_pu);
EST_setLs_q_pu(obj->estHandle,Ls_q_pu);
EST_setLs_qFmt(obj->estHandle,Ls_qFmt);
// set the Id controller gains
PID_setKi(obj->pidHandle_Id,Ki);
CTRL_setGains(ctrlHandle,CTRL_Type_PID_Id,Kp,Ki,Kd);
// set the Iq controller gains
PID_setKi(obj->pidHandle_Iq,Ki);
CTRL_setGains(ctrlHandle,CTRL_Type_PID_Iq,Kp,Ki,Kd);
return;
} // end of softwareUpdate1p6() function