各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
Victor Zheng:
每一句都有注释,您具体是哪个地方不明白。
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
haha haha1:
回复 Victor Zheng:
首先谢谢你的回答。
我的问题如下,我现在在做F28335控制pmsm,其中TI源代码里面是这样做的,让epwm1周期产生中断,然后采样ADC、控制等等。
然后在转子位置检测部分,他是这样做的,先检查CalibratedAngle偏移量,这个我知道是转子和编码器的偏移,但在程序里为什么要加上呢,比如上电电机转起来了,那QEP检测到的脉冲个数在QPOSCNT里面,就是编码器检测到的脉冲啊。干嘛还加啊,加的话脉冲数不就多了嘛。那算出来的机械角不就大了嘛。所以这几句话不懂
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;
2、v.MechTheta= v.MechScaler*v.RawTheta;
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta);这两句怎么没归一化呢,我看TI28035例程是归一化的如下
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*/
3、发生Z脉冲的时候会有个中断,那这个中断为什么不将计数脉冲清零呢?
if ((*eQEP[m]).QFLG.bit.IEL == 1) /*中断标志寄存器*/ \ { \ v.IndexSyncFlag = 0x00F0; \ v.QepCountIndex = (*eQEP[m]).QPOSILAT; /*位置锁存*/ \ (*eQEP[m]).QCLR.bit.IEL = 1; /* Clear interrupt flag 中断清除寄存器*/ \ }
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
Victor Zheng:
回复 haha haha1:
这个代码是哪个例程中的?
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
haha haha1:
回复 Victor Zheng:
HVPM_Sensorless_2833x中的。
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
Victor Zheng:
回复 haha haha1:
我对第一个问题的理解是,*eQEP[m]).QPOSCNT + v.CalibratedAngle;表示转子的绝对机械角度。比如eQEP[m]).QPOSCNT=0的时候转子的绝对位置可能是10度,这就需要加v.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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
haha haha1:
回复 Victor Zheng:
为什么是10°啊?不是跟A相重合了嘛,那就应该是0°啊,因为我选A相为0°参考啊!
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
qiang wang4:
回复 Victor Zheng:
是啊 ,这个的的地方很难理解的,是否可以给解释解释呢?为什么10度呢?
各位帮我看下这个程序,就这段看不懂了!!
#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 */ \
v.MechTheta= v.MechScaler*v.RawTheta; \
/* Compute the electrical angle */ \
v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
\
/* 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 */ \
} \
\
/* Check unit Time out-event for speed calculation: */ \
/* Unit Timer is configured for 100Hz in INIT function*/ \
if((*eQEP[m]).QFLG.bit.UTO == 1) \
{ \
/***** Low Speed Calculation ****/ \
if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
{ /* Capture Counter overflowed, hence do no compute speed*/ \
(*eQEP[m]).QEPSTS.all = 0x000C; \
} \
else if((*eQEP[m]).QCPRDLAT!=0xffff) \
/* Compute lowspeed using capture counter value*/ \
v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
}
Liang Young:
回复 haha haha1:
编码器的安装问题,没能安装到与A相完全重合