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.

TMS320F28069F: How to set Kp, Ki of speed PID ?

Part Number: TMS320F28069F
Other Parts Discussed in Thread: MOTORWARE

Dear TI members,

I'd like to tune speed PID parameters of my custom code based on motorware.

I have changed Kp and Ki at CTRL_setParams() as follows

  // set the default speed PID controller parameters
//  Kp = _IQ(0.02*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz/pUserParams->iqFullScaleCurrent_A);
//  Ki = _IQ(2.0*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz*pUserParams->ctrlPeriod_sec/pUserParams->iqFullScaleCurrent_A);
  Kp = _IQ(0.035*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz/pUserParams->iqFullScaleCurrent_A);
  Ki = _IQ(2.5*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz*pUserParams->ctrlPeriod_sec/pUserParams->iqFullScaleCurrent_A);
  Kd = _IQ(0.0);
  outMin = _IQ(-1.0);
  outMax = _IQ(1.0);

  PID_setGains(obj->pidHandle_spd,Kp,Ki,Kd);
  PID_setUi(obj->pidHandle_spd,_IQ(0.0));
  PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
  CTRL_setGains(handle,CTRL_Type_PID_spd,Kp,Ki,Kd);

I could see Kp and Ki was updarted as I intended at start as following capture.

After I ran the motor, it was restored as original value.

I could not find which code was update the Kp, Ki value.

so I could not test tunned parameter of speed PID.

Would you please let me know how to update Kp, Ki value of speed PID ?

Thanks in advance

  • I assume your reference project is lab05b or lab10a. The Kp and Ki of speed/current will be updated by calling updateKpKiGains(), so you may only change gMotorVars.Kp_spd and gMotorVars.Ki_spd to tune the speed loop. More detail is as below just for your reference.

    The new Kp and Ki of speed and current loop will be set in CTRL_updateState() which is called in background loop like below code.

    // update the controller state
    bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);

    And you might find below code in CTRL_updateState(), but the CTRL_setupEstOnLineState() is in ROM that update Kp and Ki for both speed and current loop.
    if(EST_isOnLine(obj->estHandle))
    {
    // setup the estimator for online state
    CTRL_setupEstOnLineState(handle);
    }

  • Thanks for your clear answer.

    Let me ask one more question about Kp, Ki parameters updated by ROM
    Does both Kp, Ki parameters updated by ROM are optimal value for the running condition or just calculated value with current motor parameters ?
    I'm wondering whether it is better to use updated value or not.

    I'm expecting your detail response, for reference.

    Thanks in advance gain.
  • Just update and set the setting Kp and Ki to PID object of speed and current in ROM code, But you could calculate and set the Kp and Ki in the background forever loop or ISR loop if you want. The default Kp and Ki are calculated according to motor parameters, the Kp and Ki of current PID are re-calculated in USER_calcPIgains() and to be updated in updateKpKiGains(), both are open source in the project. You might change the Kp and Ki of both speed and current by calling updateKpKiGains(). Above description only supports lab1~lab10.

    If you are designing your project based lab11a or lab11b, the Kp and Ki are calculated and updated in open source project lab file, not in ROM code.