Hello, I am using a DRV8312 Kit, TMS320F28035 chip and am running the PM_Sensorless project.
In this sensorless project i modified build level 4 to test an encoder as i require to go pretty slow and the smo/se macro works iffy below 120 rpm.
The code was modified as follows:
// ------------------------------------------------------------------------------
// Call the QEP calculation module
// ------------------------------------------------------------------------------
// QEP_MACRO(qep1);
// ------------------------------------------------------------------------------
// Detect calibration angle and call the QEP module
// ------------------------------------------------------------------------------
if (lsw==0) {EQep1Regs.QPOSCNT=0; EQep1Regs.QCLR.bit.IEL = 1;} // Reset position cnt.
if ((EQep1Regs.QFLG.bit.IEL==1) && Init_IFlag==0) // Check the index occurrence
{qep1.CalibratedAngle = EQep1Regs.QPOSILAT; Init_IFlag++;} // Keep the latched pos. at the first index
if (lsw!=0) QEP_MACRO(qep1);
==================================================================
The following code excerpt is from the qep driver file f2803xqep.h
#define QEP_MACRO(v) \
\
/* Check the rotational direction */ \
v.DirectionQep = EQep1Regs.QEPSTS.bit.QDF; \
\
/* Check the position counter for EQEP1 */ \
v.RawTheta = EQep1Regs.QPOSCNT + v.CalibratedAngle; \
\
if (v.RawTheta < 0) \
v.RawTheta = v.RawTheta + EQep1Regs.QPOSMAX; \
else if (v.RawTheta > EQep1Regs.QPOSMAX) \
v.RawTheta = v.RawTheta - EQep1Regs.QPOSMAX; \
\
If i understand everything correctly then qep1.ElecTheta which is a function of mechTheta and rawTheta is what I would use to connect to the park and ipark macro of the next build level (build level5), in build level 4 we use the ramp control and ramp generator macros to generate an electrical theta.
rawTheta is related to mechTheta by the mechScalar which is a function of my encoder properties etc.., this is clear, and mechTheta relates to ElecTheta by the following relationship: elecTheta = PolePairs*mechTheta. (this is also clear)
Thus the transformation from rawtheta to electheta makes perfect sense, it is however the calculation of rawtheta that i do have one question about.
For this example lets just assume electheta = mechtheta thus there are 2 magnetic rotor poles or 1 pole pair.
Isn't the ElecTheta that eventually comes from RawTheta supposed to be aligned with Phase A, thus @ Phase A RawTheta should be equal to 0 thus ElecTheta would also be equal to 0?
Isn't the value that the park and ipark macro expects to have (rotor flux position measured in electrical degrees ie qep1.ElecTheta) supposed to be aligned with Phase A?
lets call rawtheta r0
and CalibratedAngle c0 ("qep1.CalibratedAngle")
and i0("EQep1Regs.QPOSCNT")
then
Please correct if i am wrong about the following points:
- i0 ("EQep1Regs.QPOSCNT") is the angular difference between the index pulse and the current rotor flux position in mechanical degrees at the time of the interrupt.
- c0 ("qep1.CalibratedAngle") is defined as // Parameter Raw angular offset between encoder index and phase a (Q0), thus the angular difference between phase A and the Index pulse in mechanical degrees.
- ElecTheta is aligned with Phase A thus if we lock the rotor on a motor with 2 magnetic poles on the rotor (ie 1 pole pair) we must be at rotor flux position of 0 degrees , 0 mechTheta and 0 elecTheta.
If all of those points are true should then should we set rawtheta in f2803xqep.h driver file as follows:
equal to
/* Check the position counter for EQEP1 */ \
v.RawTheta = EQep1Regs.QPOSCNT - v.CalibratedAngle;
instead of
/* Check the position counter for EQEP1 */ \
v.RawTheta = EQep1Regs.QPOSCNT + v.CalibratedAngle;
As that would give us the distance in mechanical degrees from Phase A to the current rotor flux position. Conceptually adding them does not make very much sense to me, if anybody can help clear this up it would be of greatly appreciated, Thank you in advance.
Regards
Ari