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.

How to change the motor parameters when the motor is running



I want change :

USER_MOTOR_Ls_d
USER_MOTOR_Ls_q
USER_MOTOR_Rr
USER_MOTOR_Rs
USER_MOTOR_MAGNETIZING_CURRENT

As far as I know , there are three functions CTRL_setMotorParams() ,CTRL_setIdRated_pu()and ST_setupPosConv() that I should modify , and is there any other functions that I missed? 

  • Do you want to change them on the fly, while motor is running? or once before running the motor?

    If you want to change it once, then you can simply edit user.h with the desired values.

    If you want to change them on the fly, then this gets a bit more complicated. The complications are because the code is implemented using fixed point math, so there is scaling involved. For example, this is how you change the inductance:

    // these are the desired values to be written
    #define USER_MOTOR_Ls_d  (0.012)
    #define USER_MOTOR_Ls_q  (0.016)

    // calculate this once
    float_t fullScaleInductance = USER_IQ_FULL_SCALE_VOLTAGE_V/(USER_IQ_FULL_SCALE_CURRENT_A * USER_VOLTAGE_FILTER_POLE_rps);

    // calculate this code outside of the interrupt since it requires floating point operations
    int16_t lShift = ceil(log(USER_MOTOR_Ls_d/(0.7*fullScaleInductance))/log(2.0));
    uint16_t Ls_qFmt = 30 - lShift;
    float_t L_max = fullScaleInductance * pow(2.0,lShift);
    _iq Ls_d_pu = _IQ30(USER_MOTOR_Ls_d / L_max);
    _iq Ls_q_pu = _IQ30(USER_MOTOR_Ls_q / L_max);

    // call these functions inside of the ISR, so that all variables related to inductance are updated in the same ISR
    EST_setLs_d_pu(handle, Ls_d_pu);
    EST_setLs_q_pu(handle, Ls_q_pu);
    EST_setLs_qFmt(handle, Ls_qFmt);

    This is how you update the rotor resistance:

    // these are the desired values to be written
    #define USER_MOTOR_Rr  (2.0)

    // calculate this once
    float_t fullScaleResistance = USER_IQ_FULL_SCALE_VOLTAGE_V/USER_IQ_FULL_SCALE_CURRENT_A;

    // calculate this code outside of the interrupt since it requires floating point operations
    int16_t lShift = (int16_t)ceil(log(USER_MOTOR_Rr/(0.7*fullScaleResistance))/log(2.0));
    uint16_t Rr_qFmt = 30 - lShift;
    float_t Rr_max = fullScaleResistance * pow(2.0,lShift);
    _iq Rr_pu = _IQ30(USER_MOTOR_Rr / Rr_max);

    // call these functions inside of the ISR, so that all variables are updated in the same ISR
    EST_setRr_pu(handle, Rr_pu);
    EST_setRr_qFmt(handle, Rr_qFmt);

    This is how you update stator resistance:

    // these are the desired values to be written
    #define USER_MOTOR_Rs  (1.0)

    // calculate this once
    float_t fullScaleResistance = USER_IQ_FULL_SCALE_VOLTAGE_V/USER_IQ_FULL_SCALE_CURRENT_A;

    // calculate this code outside of the interrupt since it requires floating point operations
    int16_t lShift = (int16_t)ceil(log(USER_MOTOR_Rs/(0.7*fullScaleResistance))/log(2.0));
    uint16_t Rs_qFmt = 30 - lShift;
    float_t Rs_max = fullScaleResistance * pow(2.0,lShift);
    _iq Rs_pu = _IQ30(USER_MOTOR_Rs / Rs_max);

    // call these functions inside of the ISR, so that all variables are updated in the same ISR
    EST_setRs_pu(handle, Rs_pu);
    EST_setRs_qFmt(handle, Rs_qFmt);

    And this is how to change the magnetizing current on the fly:

    // these are the desired values to be written
    #define USER_MOTOR_MAGNETIZING_CURRENT  (1.5)

    // call these functions inside of the ISR
    CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;

    _iq IdRated_pu = _IQmpy(_IQ(USER_MOTOR_MAGNETIZING_CURRENT),_IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A));

    // these two writes are done so that the default value is stored
    CTRL_setIdRated_pu(ctrlHandle, IdRated_pu);
    EST_setIdRated_pu(handle, IdRated_pu);

    // these three writes are done so that the min and max default value is stored, and it sets the target for the ramp of Id references.
    TRAJ_setMinValue(obj->trajHandle_Id,_IQ30rsmpy(IdRated_pu,_IQ30(0.2)));
    TRAJ_setMaxValue(obj->trajHandle_Id,_IQ29rsmpy(IdRated_pu,_IQ29(1.2)));
    TRAJ_setTargetValue(obj->trajHandle_Id,IdRated_pu);

    -Jorge