I've been looking at the code in the CTRL_runPiOnly function that runs during the mainISR in projectlab20. When speed control mode is enabled, I can't seem to find the function or line of code that sets the Iq current in the current pid controller. My goal here is to let the speed controller pid control loop run, but during certain times control the Iq current directly instead of letting the speed controller set it. I'm currently using the updateIqRef function to set the Iq current when the speed controller is off, but when it is on and directly controlling the Iq current, I can't seem to find the code in the speed controller that updates the Iq current. Any help would be greatly appreciated.
inline void CTRL_runPiOnly(CTRL_Handle handle) //,const HAL_AdcData_t *pAdcData,HAL_PwmData_t *pPwmData)
{
CTRL_Obj *obj = (CTRL_Obj *)handle;
// when appropriate, run the PID speed controller
if(CTRL_getFlag_enableSpeedCtrl(handle))
{
if(CTRL_doSpeedCtrl(handle))
{
_iq refValue = CTRL_getRefValue_spd_pu(handle);
_iq fbackValue = CTRL_getFbackValue_spd_pu(handle);
_iq outMax = CTRL_getSpeed_outMax_pu(handle);
_iq outMin = -outMax;
// reset the speed count
CTRL_resetCounter_speed(handle);
PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
PID_run_spd(obj->pidHandle_spd,refValue,fbackValue,CTRL_getIq_ref_pu_addr(handle));
}
}
else
{
// zero the speed command
// CTRL_setIq_ref_pu(handle,_IQ(0.0));
// reset the integrator
// PID_setUi(obj->pidHandle_spd,_IQ(0.0));
}
// when appropriate, run the PID Id and Iq controllers
if(CTRL_doCurrentCtrl(handle))
{
_iq Kp_Id = CTRL_getKp(handle,CTRL_Type_PID_Id);
_iq Kp_Iq = CTRL_getKp(handle,CTRL_Type_PID_Iq);
_iq refValue;
_iq fbackValue;
_iq outMin,outMax;
_iq maxVsMag = CTRL_getMaxVsMag_pu(handle);
// reset the current count
CTRL_resetCounter_current(handle);
// ***********************************
// configure and run the Id controller
// compute the Kp gain
// Scale Kp instead of output to prevent saturation issues
if(CTRL_getFlag_enableDcBusComp(handle))
{
Kp_Id = _IQmpy(Kp_Id,EST_getOneOverDcBus_pu(obj->estHandle));
}
PID_setKp(obj->pidHandle_Id,Kp_Id);
// compute the reference value
refValue = CTRL_getRefValue_Id_pu(handle);
// update the Id reference value
EST_updateId_ref_pu(obj->estHandle,&refValue);
// get the feedback value
fbackValue = CTRL_getId_in_pu(handle);
// compute the Id output limits
CTRL_computeOutputLimits_Id(handle,maxVsMag,&outMin,&outMax);
// set the minimum and maximum values
PID_setMinMax(obj->pidHandle_Id,outMin,outMax);
// run the Id PID controller
PID_run(obj->pidHandle_Id,refValue,fbackValue,CTRL_getVd_out_addr(handle));
// set the Id reference value in the estimator
EST_setId_ref_pu(obj->estHandle,refValue);
// ***********************************
// configure and run the Iq controller
// compute the Kp gain
// Scale Kp instead of output to prevent saturation issues
if(CTRL_getFlag_enableDcBusComp(handle))
{
Kp_Iq = _IQmpy(Kp_Iq,EST_getOneOverDcBus_pu(obj->estHandle));
}
PID_setKp(obj->pidHandle_Iq,Kp_Iq);
// get the Iq reference value
refValue = CTRL_getRefValue_Iq_pu(handle); //CTRL_getIq_ref_pu(handle);
// get the feedback value
fbackValue = CTRL_getIq_in_pu(handle);
// compute the Iq output limits
CTRL_computeOutputLimits_Iq(handle,maxVsMag,CTRL_getVd_out_pu(handle),&outMin,&outMax);
// set the minimum and maximum values
PID_setMinMax(obj->pidHandle_Iq,outMin,outMax);
// run the Iq PID controller
PID_run(obj->pidHandle_Iq,refValue,fbackValue,CTRL_getVq_out_addr(handle));
// set the Iq reference value in the estimator
EST_setIq_ref_pu(obj->estHandle,refValue);
// add voltage offsets
CTRL_addVdq_offset(handle);
}
return;
} // end of CTRL_runPiOnly() function
Thanks,