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.

TMS320F28379D: C2000™︎ 微控制器论坛 C2000motorcontrol

Part Number: TMS320F28379D


static inline void SPDCALC_run(SPDCALC_Handle handle, float32_t theta)
{
    SPDCALC_Obj *obj = (SPDCALC_Obj *)handle;

    obj->ref  = theta;

    // error cal
    obj->err = obj->ref - obj->fbk;

    // roll in the error
    if(obj->err >= MATH_PI)
    {
        obj->err = obj->err - MATH_TWO_PI;
    }
    else if(obj->err <= -MATH_PI)
    {
        obj->err = obj->err + MATH_TWO_PI;
    }

    // P and I control
    obj->Up  = obj->Kp * obj->err;              // P control
    obj->Ui += obj->Ki * obj->err;              // I control
    obj->Ui  = __fsat(obj->Ui, obj->Umax, obj->Umin);

    // control output
    obj->out = obj->Up + obj->Ui;
    obj->out = __fsat(obj->out, obj->Umax, obj->Umin);      // rad/s

    obj->speed_Hz = obj->out * MATH_ONE_OVER_TWO_PI;        //?????? --add by jiaolu

    // Latest angle feedback estimation --> ( Fbk = integral of speed )
    obj->fbk = obj->fbk + obj->out * obj->thetaDelta;

    // roll "Fbk" within -pi to pi
    if(obj->fbk >= MATH_PI)
    {
        obj->fbk = obj->fbk - MATH_TWO_PI;
    }
    else if(obj->fbk <= -MATH_PI)
    {
        obj->fbk = obj->fbk + MATH_TWO_PI;
    }

    return;
}
大家好,上面是C2000motorcontrol中ti提供的计算编码器的速度的代码,我对此代码怎样计算出比编码器速度不是很明白。请大家解答一下 谢谢