在HVPM_Sensored中有下面的一段程序,计算CalibratedAngle(校准角)程序如下:检测到第一个index脉冲,QPOSILAT记录下QPOSCNT值,把这个值当做CalibratedAngle的脉冲,不知道为什么? 可是我现在的电机index脉冲与a相绕组的反电势从正到负过零点对齐,那么我的CalibratedAngle脉冲应该是5000(假设编码器线数为2500,4倍频)
if ((EQep1Regs.QFLG.bit.IEL==1) && Init_IFlag==0) // Check the first index occurrence
[
qep1.CalibratedAngle= EQep1Regs.QPOSILAT;
Init_IFlag++;
] // Keep the latched posi
tion
在 QEP_MACRO中使用到了这个角度CalibratedAngle,程序如下:
#define QEP_MACRO(m,v)
/* Check the rotational direction */
v.DirectionQep = (*eQEP[m]).QEPSTS.bit.QDF;
/* Check the position counter for EQEP1 */
v.RawTheta = (*eQEP[m]).QPOSCNT + v.CalibratedAngle;
if (v.RawTheta < 0)
v.RawTheta = v.RawTheta + (*eQEP[m]).QPOSMAX;
else if (v.RawTheta > (*eQEP[m]).QPOSMAX)
v.RawTheta = v.RawTheta - (*eQEP[m]).QPOSMAX;
/* Compute the mechanical angle in Q24 */
v.MechTheta = __qmpy32by16(v.MechScaler,(int16)v.RawTheta,31); /* Q15 = Q30*Q0 */
v.MechTheta &= 0x7FFF; /* Wrap around 0x07FFF*/
v.MechTheta <<= 9; /* Q15 -> Q24 */
/* Compute the electrical angle in Q24 */
v.ElecTheta = v.PolePairs*v.MechTheta; /* Q24 = Q0*Q24 */
v.ElecTheta &= 0x00FFFFFF; /* Wrap around 0x00FFFFFF*/
/* Check an index occurrence*/
if ((*eQEP[m]).QFLG.bit.IEL == 1)
[
v.IndexSyncFlag = 0x00F0;
v.QepCountIndex = (*eQEP[m]).QPOSILAT;
(*eQEP[m]).QCLR.bit.IEL = 1; /* Clear interrupt flag */
]
还有一个问题是检测到Index脉冲,为什么v.IndexSyncFlag = 0x00F0;?谢谢
0