主题中讨论的其他器件:DRV8305
我使用 Launchpad 28069M + EVM DRV8305 通过 InstaSPIN FOC 控制外转子 PMSM。 现在、我添加了一个3600P/R 增量编码器、 以根据 lab11a 示例读取速度和位置信息。 enc.c、 enc.h、 QEP.c 和 qep.h 的文档是从实验12b 获取的、未 做任何修改。
为了读取速度、我遵循前面的答案。
在 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 的值 仍会随机变化。
我的方法有什么问题?