This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Speed Controller vs Torque Controller in CTRL_runPiOnly

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,

  • Drew,
    This may take me some time to loo through, I haven't looked at that project in awhile. This lab20 was created some time ago when the IPD_HFI project was being used to simplify the control system. However, we eventually took it another step further and introduced the format in proj_lab11, 11a, etc. I would first suggest using that format vs. 20 if at all possible.
  • drew,
    it is updating from the line:

    // get the Iq reference value
    refValue = CTRL_getRefValue_Iq_pu(handle); //CTRL_getIq_ref_pu(handle);

    which is inside the CTRL which is in the closed library.
     
    if you use proj_lab11 you will see it's more clear, that the output of the Speed controller updates the gIdq_ref_pu.value[1] for Iq

    PID_run_spd(pidHandle[0],gMotorVars.SpeedRef_pu,speed_pu,
    &(gIdq_ref_pu.value[1]));

    and then used by the Iq controller
    // get the Iq reference value
    refValue = gIdq_ref_pu.value[1];

  • Chris,

    Thanks for the clarification on this. I will look at the projlab11 for future projects, but unfortunately this client's project is already based on proj20. Sounds like I can still just modify that variable before the Id and Iq PID controllers run for the same effect.

    Regards,