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
In order to enable Rs Online, a couple of parameters need to be setup. One of the most important parameters is how much current will be injected into the D-axis current (Id) in order to perform Rs Online recalibration. Usually, what is recommended is to have a minimum of 5% of the rated current in order to have measurable current to get a good recalibration of the resistance while the motor is running.
_iq RsOnLineCurrent_A = _IQ(USER_MOTOR_MAX_CURRENT * 0.05);
Note that the multiplication is done by the pre-compiler, using a floating point for the USER_MOTOR_MAX_CURRENT define, times 0.05, representing the 5%, and then converting the floating point results into a global IQ value. For more information about the IQmath library, see the C28x IQMath Library – A Virtual Floating Point Engine – Module User's Guide.
Also, before enabling Rs Online, user must set:
Both Id_mag_pu and Id_pu values need to be set to zero in order to prevent the estimator to keep any residual current references when it is disabled. In future releases of InstaSPIN, this will not be needed, and only the Id_mag_pu will be required to be reset to zero, but for the 2806xF devices, both require a value of zero to be written before Rs Online is enabled, or right before Rs Online is disabled.
The two flags perform different tasks inside the estimator. The enableRsOnLine flag allows the entire Rs Online feature to run, updating an internal variable holding the most recent resistance value, and injecting current into Id. The second flag, updateRs, allows the resistance value to be used by the motor model. If the updateRs flag is never set, but the enableRsOnLine flag is set, the resistance can still be used to monitor how the resistance changes, but the internal motor model will not use this varying resistance. If the motor temperature increases drastically, and the resistance is not updated in the motor model (by setting the updateRs flag to TRUE), the performance of InstaSPIN will be affected, and the low speed performance will not be as desired. Also, the motor might not startup under full load.
The following code example shows how to set the initial values as well as how to check the condition to make sure the initial values are set when the state machine is in the proper state. This is done prior to enabling Rs Online recalibration:
CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
// get the controller state
gMotorVars.CtrlState = CTRL_getState(ctrlHandle);
// get the estimator state
gMotorVars.EstState = EST_getState(obj->estHandle);
if((gMotorVars.CtrlState <= CTRL_State_OffLine) ||
((gMotorVars.CtrlState == CTRL_State_OnLine)&&
(gMotorVars.EstState == EST_State_Rs)))
{
EST_setRsOnLine_qFmt(obj->estHandle,EST_getRs_qFmt(obj->estHandle));
EST_setRsOnLineId_mag_pu(obj->estHandle,_IQ(0.0));
EST_setRsOnLineId_pu(obj->estHandle,_IQ(0.0));
EST_setFlag_enableRsOnLine(obj->estHandle,FALSE);
EST_setFlag_updateRs(obj->estHandle,FALSE);
}
This code example can be executed outside of the interrupt, in the main forever loop, since it only involves global variables and no time critical code execution. Keep in mind that the code inside the "if" condition is executed before the Rs Online is enabled.
One of the conditions to reset all the parameters of Rs Online as shown in the previous code example is when CtrlState is less than or equal to CTRL_State_OffLine. This condition means that the Rs Online should be disable and reset when the state machine is either Idle (motor not being energized), or when doing the offsets recalibration. The other state where these initial values have to be done is when the control state is Online (CTRL_State_OnLine), and the estimator state is EST_State_Rs, in other words, when the Rs Offline recalibration is being done. All these conditions represent a motor at stand still. In order to relate these states to the entire state machine within InstaSPIN, see Section 7. The CTRL_State_OffLine state is shown as Offline in the CTRL state machine diagram, the CTRL_State_OnLine state is shown as Online in the CTRL state machine diagram and the EST_State_Rs state is shown as Rs in the EST state machine diagram
When the motor is running, we need to make sure that the resistance given by the Rs Online recalibration feature is close enough to the initial resistance, given by the Rs Offline feature. This is done to ensure a smooth transition between both resistance values causing no disturbances to the closed loop system. This can be done with the following code example, which includes the "else" condition from the previous code example. The following condition will be executed whenever the motor is not at standstill, in other words, when the motor is spinning. This condition will be used to enable Rs Online as shown.
else
{
// Scale factor to convert Amps to per units.
// USER_IQ_FULL_SCALE_CURRENT_A is defined in user.h
_iq sf = _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A);
Rs_pu = EST_getRs_pu(obj->estHandle);
RsOnLine_pu = EST_getRsOnLine_pu(obj->estHandle);
Rs_error_pu = RsOnLine_pu -Rs_pu;
EST_setFlag_enableRsOnLine(obj->estHandle,TRUE);
EST_setRsOnLineId_mag_pu(obj->estHandle,_IQmpy(RsOnLineCurrent_A,sf));
// Enable updates when Rs Online is only 5% different fromRs Offline
if(_IQabs(Rs_error_pu) <_IQmpy(Rs_pu,_IQ(0.05)))
{
EST_setFlag_updateRs(obj->estHandle,TRUE);
}
}
Notice that in this example we are enabling the Rs Online recalibration by calling:
EST_setFlag_enableRsOnLine(obj->estHandle,TRUE)
However, the Rs Online value will not be updated until the update flag is set to TRUE. The update flag is set to TRUE when the Rs Online value is within a desired proximity to the initial value provided by Rs Offline, in this case 5% of that value. For applications that require full torque at start up, it is recommended to have a smaller percentage of difference between Rs Online and Rs Offline, that is, 3% or so instead of 5%. As soon as the Rs Online value and Rs Offline value are within 5% difference, the Rs Online update flag is set by calling:
EST_setFlag_updateRs(obj->estHandle,TRUE)
Once both flags are enabled, Rs Online recalculates the resistance in real time, and the estimator will update its internal motor model according to that new resistance.
Also, as noted in the code example, the magnitude of the current to be injected in order to estimate the resistance Online is set by calling the following function:
EST_setRsOnLineId_mag_pu(obj->estHandle,_IQmpy(RsOnLineCurrent_A,sf));