Hello, me again.
Once more, I have a question, but this time about eQEP periphery and I hope you can help me out with this one.
I got an encoder and wired it up to TI Hercules controller. Specifically, I took 5V, GND EQEP1A and EQEP1B and wired them up. I completely ignored the INDEX channel of the encoder.
I have problem with eQEP and I do not understand how to use it, so I hope you can help me.
I've enabled EQEP DRIVER.
In PINMUX I've enabled EQEP1A and EQEP1B.
In EQEP1 I've set all according to the provided example: QUADRATURE COUNT, RESOLUTION 2X, ENABLED SW INITIALISATION, SET INIT TO 0 AND MAX TO 0xFFFF_FFFF.
CAPTURE TIME POS MOD - ON UNIT TIMEOUT EVENT (enabled Unit Timeout Interrupt as well).
This is the Code Composer Studio code I have:
int main(void)
{
/* USER CODE BEGIN (3) */
uint16 deltaT = 0U;
float velocity = 0U;
/* EQEP initialization based on GUI Configuration. */
QEPInit();
/* Enable Position Counter */
eqepEnableCounter(eqepREG1);
/* Enable Unit Timer. */
eqepEnableUnitTimer(eqepREG1);
/* Enable capture timer and capture period latch. */
eqepEnableCapture(eqepREG1);
while(1)
{
/* Status flag is set to indicate that a new value is latched in the QCPRD register. */
if((eqepREG1->QEPSTS & 0x80U) !=0U)
{
/* Elapsed time between unit position events */
deltaT = eqepREG1->QCPRD;
/* Calculate Velocity from deltaT and the value of the unit position. */
/* The value of Unit Position is a sample value and should be changed by the
* User as per the actual value in the UNIT_POSITION_X macro above. */
velocity = (float)(UNIT_POSITION_X/deltaT);
/* Clear the Status flag. */
eqepREG1->QEPSTS |= 0x80U;
printf ("VELOCITY >> %f \n", velocity);
printf ("COUNTER >> %u \n", eqepREG1->QPOSLAT);
}
}
I've added to print velocity and position counter.
When I try to move encoder these are the results I get:
Move 1:
VELOCITY >> 0.000000
COUNTER >> 1
VELOCITY >> 0.000000
COUNTER >> 1
Move 2:
VELOCITY >> 0.000000
COUNTER >> 0
VELOCITY >> 0.000000
COUNTER >> 0
Move 3:
VELOCITY >> 0.000000
COUNTER >> 0
VELOCITY >> 0.000000
COUNTER >> 0
Move 4:
VELOCITY >> 0.000000
COUNTER >> 1
VELOCITY >> 0.000000
COUNTER >> 2
Move 5:
VELOCITY >> 0.000000
COUNTER >> 2
VELOCITY >> 0.000000
COUNTER >> 2
VELOCITY >> 0.000000
COUNTER >> 3
If I move encoder once, it will get into if not once, but usually two times (last case, it entered into IF three times).
If I turn it for 5deg it is the same as if I turned it for 100deg. Value in QPOSLAT register barely changes. It changes for one or non increment. I cannot understand why...
Also, velocity is always 0.000000. This never changes. Why?
I've tried incrementing Unit Init Period from 0x0000_0001 up to 0xFFFF_FFFF but haven't had any success.
I would like to use encoders with 300 rpms.
So, from them I need two sets of information:
(1) Time between previous and current position change -> to determine velocity
(2) Incremented values so I have knowledge about position.
Can you help me out?
Thanks,
Marc :)