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.

TMS320F28069M: torque controll lab11e

Part Number: TMS320F28069M

Hello TI,

I tried to use the torque mode in lab11e, I changed these two variables:

 

bool gHall_Flag_CurrentCtrl = true;
gIdq_ref_pu.value[1]= Iq_Ref_pu;

 

But when I increased gIdq_ref_pu.value[1] nothing happened.
I recognized that gHall_PwmDuty was always at zero.

 

I found this in the code:

if(gHall_Flag_CurrentCtrl == true)                  // Torque Control Mode
{
gHall_BLDC_Is_fdb_pu = gAdcData.I.value[gHall_BLDC_Flag_Is_fdb];
gHall_BLDC_Is_ref_pu = speed_pid_out;

 // BLDC current loop
PID_run(pidHandle[3],gHall_BLDC_Is_ref_pu,gHall_BLDC_Is_fdb_pu,&gHall_PwmDuty);

HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
}
else                                                                                                                                      // Speed Control Mode
{
gHall_PwmDuty = speed_pid_out;
HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
}

 

Then I put the gHall_PwmDuty in the torque control like this:

if(gHall_Flag_CurrentCtrl == true)                  // Torque Control Mode
{
gHall_BLDC_Is_fdb_pu = gAdcData.I.value[gHall_BLDC_Flag_Is_fdb];
gHall_BLDC_Is_ref_pu = speed_pid_out;

// BLDC current loop
PID_run(pidHandle[3],gHall_BLDC_Is_ref_pu,gHall_BLDC_Is_fdb_pu,&gHall_PwmDuty);

gHall_PwmDuty = Iq_Ref_pu;

HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
}
else                                                                                                                                      // Speed Control Mode
{
gHall_PwmDuty = speed_pid_out;
HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
}


After this change the motor started moving, but it only runs smoothly at very low speeds, at higher speeds it begins to oscillate and sound badly and I’m thinking it’s not changing to FAST.
I think I did something wrong in the code, because the current control works in the other labs and speed mode of lab11e works as well.
I’m not sure what I have to change to use the torque mode. Please Help.

 

And only out of curiosity if I want to add the hall start-up in lab5a or 10a would this be easy?
Because I saw some differences in the mainISR and I don’t know how to handle that.

thanks in advance

  • Do you want to implement torque control for full speed range, includes BLDC and FAST? If yes, you may follow below steps for torque control mode.

    1. Change the flags setting for BLDC as below.
    bool gHall_Flag_EnableStartup = true; // true->enable hall startup
    //bool gHall_Flag_EnableStartup = false; // false->disable hall startup

    //bool gHall_Flag_CurrentCtrl = false;
    bool gHall_Flag_CurrentCtrl = true;

    2. Add two global variables in project.
    bool FS_flag_enableSpeedCtrl = false;
    //bool FS_flag_enableSpeedCtrl = true;
    _iq FS_Iq_ref_pu = _IQ(0.1);

    3. Modify the code as below in mainISR()
    // when appropriate, run the PID speed controller
    if(FS_flag_enableSpeedCtrl == true)
    {
    if(pidCntSpeed++ >= USER_NUM_CTRL_TICKS_PER_SPEED_TICK)
    {
    // calculate Id reference squared
    _iq Id_ref_squared_pu = _IQmpy(PID_getRefValue(pidHandle[1]),PID_getRefValue(pidHandle[1]));

    // Take into consideration that Iq^2+Id^2 = Is^2
    _iq Iq_Max_pu = _IQsqrt(gIs_Max_squared_pu - Id_ref_squared_pu);

    // clear counter
    pidCntSpeed = 0;

    // Set new min and max for the speed controller output
    PID_setMinMax(pidHandle[0], -Iq_Max_pu, Iq_Max_pu);

    // run speed controller
    PID_run_spd(pidHandle[0],TRAJ_getIntValue(trajHandle_spd),speed_pu, &speed_pid_out);

    gIdq_ref_pu.value[1] = speed_pid_out;
    }
    }
    else
    {
    gIdq_ref_pu.value[1] = FS_Iq_ref_pu;
    }

    4. Modify the HALLBLDC_Ctrl_Run() as below
    void HALLBLDC_Ctrl_Run(void)
    {
    if(gHall_Flag_EnableStartup == true)
    {
    gHall_PwmState = gHall_PwmIndex[gHall_State];

    if(_IQabs(speed_est_pu) < gHall_speed_FastToBldc_low_pu) // FAST to Hall
    {
    if(gHall_Flag_EnableBldc == false)
    {
    if(gHall_Bldc_Cnt > 20)
    {
    gHall_Flag_EnableBldc = true;
    gHall_Bldc_Cnt = 0;

    if(gHall_Flag_CurrentCtrl == true) // Torque Control Mode
    {
    // The following instructions load the parameters for the speed PI
    // controller.
    PID_setGains(pidHandle[0],_IQ(0.1),_IQ(0.005),_IQ(0.0));

    // Set the initial condition value for the integrator output to 0
    PID_setUi(pidHandle[3], _IQmpy(pid[2].Ui, gFast2Hall_Ui_coef));
    }
    else // Speed Control Mode
    {
    // The following instructions load the parameters for the speed PI
    // controller.
    PID_setGains(pidHandle[0],_IQ(0.1),_IQ(0.005),_IQ(0.0));

    gHall_PwmDuty = pid[2].Ui;

    // Set the initial condition value for the integrator output to 0
    PID_setUi(pidHandle[0], _IQmpy(pid[2].Ui, gFast2Hall_Spd_coef));
    }
    }
    else
    gHall_Bldc_Cnt++;
    }
    }
    else if(_IQabs(gHall_speed_fdb_pu) > gHall_speed_BldcToFast_high_pu) // Hall to FAST
    {
    if(gHall_Flag_EnableBldc == true)
    {
    if(gHall_Fast_Cnt > 20)
    {
    gHall_Flag_EnableBldc = false;
    gHall_Fast_Cnt = 0;

    if(gHall_Flag_CurrentCtrl == true) // Torque Control
    {
    // The following instructions load the parameters for the speed PI
    // controller.
    PID_setGains(pidHandle[0],_IQ(2.0),_IQ(0.02),_IQ(0.0));

    // Set the initial condition value for the integrator output to 0, Id
    PID_setUi(pidHandle[1],_IQ(0.0));

    // Set the initial condition value for the integrator output to 0, Iq
    PID_setUi(pidHandle[2], _IQmpy(pid[3].Ui, gHall2Fast_Ui_coef));

    }
    else // speed control
    {
    // The following instructions load the parameters for the speed PI
    // controller.
    PID_setGains(pidHandle[0],_IQ(2.0),_IQ(0.02),_IQ(0.0));

    // Set the initial condition value for the integrator output to 0, speed
    PID_setUi(pidHandle[0], _IQmpy(gHall_PwmDuty, gHall2Fast_Spd_Coef));

    // Set the initial condition value for the integrator output to 0, Iq
    PID_setUi(pidHandle[2], _IQmpy(gHall_PwmDuty, gHall2Fast_Iq_coef));

    // Set the initial condition value for the integrator output to 0, Id
    PID_setUi(pidHandle[1],_IQmpy(gHall_PwmDuty, _IQ(0.0)));
    }

    PWM_setSocAPulseSrc(hal.pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualZero);

    HAL_enablePwm(halHandle);
    }
    else
    gHall_Fast_Cnt++;
    }
    }

    if(gHall_Flag_EnableBldc)
    {
    angle_pu = angle_est_pu;
    speed_pu = gHall_speed_fdb_pu;

    if(gHall_Flag_CurrentCtrl == true) // Torque Control Mode
    {
    gHall_BLDC_Is_fdb_pu = gAdcData.I.value[gHall_BLDC_Flag_Is_fdb];

    if(FS_flag_enableSpeedCtrl == true)
    gHall_BLDC_Is_ref_pu = speed_pid_out;
    else
    gHall_BLDC_Is_ref_pu = FS_Iq_ref_pu;

    // BLDC current loop
    PID_run(pidHandle[3],gHall_BLDC_Is_ref_pu,gHall_BLDC_Is_fdb_pu,&gHall_PwmDuty);

    HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
    }
    else // Speed Control Mode
    {
    gHall_PwmDuty = speed_pid_out;
    HALLBLDC_Ctrl_PwmSet(gHall_PwmState, gHall_PwmDuty);
    }
    }
    else
    {
    angle_pu = angle_est_pu;
    speed_pu = speed_est_pu;
    }
    }
    else //(gHall_Flag_EnableStartup == false)
    {
    angle_pu = angle_est_pu;
    speed_pu = speed_est_pu;
    }

    return;
    }
  • Yes, I want to implement torque control with full speed range, BLDC and FAST.
    Thank you for the code Yanming. Now it’s a bit clearer to me.

    I tried the changes, but it did not work. gHall_PwmDuty is still at zero.

    Here is a picture of the watch window:

    Another thing I found I out, if I set outMin to 0.1 the motor begins to spin and Ui goes from zero to the value of outMin.

    Here is a picture of the watch window where outMin is set to 0.1 .

     

    I think Ui is the cause. Is there something else to change?


    thanks

  • It seems the outMax and outMin of pid[3] is not right. Did you have below code to initialize the PID controller pid[3] as other pid[0/1/2].

    PID_setGains(pidHandle[3],Kp_Iq,Ki_Iq,_IQ(0.0));
    PID_setMinMax(pidHandle[3],-maxVoltage_pu,maxVoltage_pu);
    PID_setUi(pidHandle[3],_IQ(0.0));

  • Thank you, that was it.