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.

QCPRDLAT value oscillates when measuring low rotor speed

Hi,

I try to use the T method to measure the motor speed. However the value of EQep1Regs.QCPRDLAT oscillates randomly when the motor is turning smoothly. I am sure the hardware connection is OK and the Qep signal is noiseless as I can get the motor speed correctly using the P method.

My initialization of eQep is as follows: 

EQep1Regs.QUPRD=600000; // Unit Timer for 100Hz at 60 MHz SYSCLKOUT

EQep1Regs.QDECCTL.bit.QSRC=00; // QEP quadrature count mode

EQep1Regs.QEPCTL.bit.FREE_SOFT=2;
EQep1Regs.QEPCTL.bit.PCRM=00; // PCRM=00 mode - QPOSCNT reset on index event
EQep1Regs.QEPCTL.bit.UTE=1; // Unit Timeout Enable
EQep1Regs.QEPCTL.bit.QCLM=1; // Latch on unit time out
EQep1Regs.QPOSMAX=4*2500;
EQep1Regs.QEPCTL.bit.QPEN=1; // QEP enable

EQep1Regs.QCAPCTL.bit.UPPS=5; // 1/32 for unit position
EQep1Regs.QCAPCTL.bit.CCPS=6; // 1/64 for CAP clock
EQep1Regs.QCAPCTL.bit.CEN=1; // QEP Capture Enable

EALLOW; /* Enable EALLOW*/

GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1; // Configure GPIO20 as EQEP1A
GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1; // Configure GPIO21 as EQEP1B
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 1; // Configure GPIO23 as EQEP1I

EDIS; /* Disable EALLOW*/

The T method for calculating the motor speed is as follows: 

if(EQep1Regs.QEPSTS.bit.UPEVNT==1) // Unit position event
{
if(EQep1Regs.QEPSTS.bit.COEF==0) // No Capture overflow
temp1=(unsigned long)EQep1Regs.QCPRDLAT; // temp1 = t2-t1
else // Capture overflow, saturate the result
temp1=0xFFFF;

p->Speed_pr = _IQdiv(p->SpeedScaler,temp1); // p->Speed_pr = p->SpeedScaler/temp1
Tmp1=p->Speed_pr;

if (Tmp1>_IQ(1))
p->Speed_pr = _IQ(1);
else
p->Speed_pr = Tmp1;
if (p->DirectionQep==0)
p->Speed_pr = -p->Speed_pr;

// Convert p->Speed_pr to RPM
p->SpeedRpm_pr = _IQmpy(p->BaseRpm,p->Speed_pr); // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q

EQep1Regs.QEPSTS.all=0x88; // Clear Unit position event flag
// Clear overflow error flag
}

Can anyone help to look into above code and find out what the problem is. Many thanks!

Tao