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:如何使用 ENC +QEP 获取速度和位置信息?

Guru**** 2535750 points
Other Parts Discussed in Thread: DRV8305

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1041133/tms320f28069m-how-to-use-enc-qep-to-get-the-speed-and-position-information

器件型号:TMS320F28069M
主题中讨论的其他器件:DRV8305

我使用 Launchpad 28069M + EVM DRV8305 通过 InstaSPIN FOC 控制外转子 PMSM。 现在、我添加了一个3600P/R 增量编码器、  以根据 lab11a 示例读取速度和位置信息。  enc.c、 enc.h、 QEP.c 和 qep.h 的文档是从实验12b 获取的、未  做任何修改。

为了读取速度、我遵循前面的答案。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/501438/how-to-use-enc-qep-modules-to-measure-motor-speed-by-an-incremental-encoder/2054164?tisearch=e2e-sitesearch&keymatch=QEP%2525252520module#2054164

在 main void 中、ENC 被初始化和设置;

 // initialize the ENC module
  encHandle = ENC_init(&enc, sizeof(enc));

  // setup the ENC module
  ENC_setup(encHandle, USER_ENC_SAMPLE_PERIOD, USER_MOTOR_NUM_POLE_PAIRS, USER_MOTOR_ENCODER_LINES, 0, USER_IQ_FULL_SCALE_FREQ_Hz, USER_ISR_FREQ_Hz, 8000.0);

在 hal.h 中 、添加了两个函数。

//! \brief      Return the index info from the QEP module
//! \param[in] encHandle                        Handle to the ENC object
//! \return     The flag that indicate the index of encoder (true or false)
static inline uint16_t HAL_getQepIndex(HAL_Handle handle)
{
    HAL_Obj *obj = (HAL_Obj *)handle;

    return (uint16_t)((QEP_QEPSTS_FIMF & QEP_read_status(obj->qepHandle[0]))>>1);
}

//! \brief      Return the direction info from the QEP module
//! \param[in] encHandle                        Handle to the ENC object
//! \return     The flag that indicate the direction of rotation (true for negative direction or false for positive direction)
static inline uint16_t HAL_getQepDirection(HAL_Handle handle)
{
    HAL_Obj *obj = (HAL_Obj *)handle;

    return (uint16_t)((QEP_QEPSTS_QDF&QEP_read_status(obj->qepHandle[0]))>>5);
}

 ENC_getSpeedRPM 的结果具有 与 快速速度 反馈相同的数字、但始终为正。 因此 、我在 MainISR 中添加了这些内容

 // run the ENC module
  ENC_run(encHandle, HAL_getQepPosnCounts(halHandle), HAL_getQepIndex(halHandle), HAL_getQepDirection(halHandle), true);


//get speed from ENC
dirFlag = HAL_getQepDirection(halHandle);
if(dirFlag==1) ENCSPEEDRPM = - ENC_getSpeedRPM(encHandle);
if(dirFlag==0) ENCSPEEDRPM = ENC_getSpeedRPM(encHandle);

解决问题的正确方法是什么?

其次、我还想获取位置。  因此 、在 MainISR 中、我 读取  位置计数器(QPOSCNT)寄存器并尝试找出已完成的分辨率。

//write at the beginning of proj_lab11a.c
 _iq MechPosCount;
float MechanicalPos = 0;




//in MainISR 
 uint16_t dirFlag;
  _iq PosCount_delta = 0;

  _iq MechPosCount_z1 = 0;
 
 MechPosCount = HAL_getQepPosnCounts(halHandle);

  //calculate position in revolution
  MechanicalPos= MechPosCount/(USER_MOTOR_ENCODER_LINES*4);
  PosCount_delta =  MechPosCount - MechPosCount_z1;

      if ((dirFlag == 0) && (PosCount_delta < 0))
      {
          MechanicalPos = MechanicalPos + 1;
      }
      else if ((dirFlag == 1) && (PosCount_delta > 0))
      {
          MechanicalPos = MechanicalPos - 1;
      }
      MechPosCount_z1 = MechPosCount;

但是 ,MechanicalPos 的价值是随机的。  即使电机 速度基准 设置为0、 即电机不 旋转、    MechanicalPos 的值 仍会随机变化。

  我的方法有什么问题?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您可以按照实验用户指南的 lab12a 部分将电机和编码器连接到硬件套件、并在 user.h 中设置正确的编码器行

    并且必须在每次启动时对编码器进行偏移校准。 您可以尝试运行 lab12a 以检查编码器的配置是否正确。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我无法成功运行 lab12a、因此我要在11a 中应用编码器

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您是否尝试运行 lab02a/b/c 来识别 lab11a 和 lab12a 的电机参数?

    如果电机无法很好地使用 lab12a、这意味着编码器或电机线路未正确连接、或者编码器配置不正确、如上所述。 请按照实验指南检查这些设置。