Hi Folks,
I develop a brushed DC motion application, where I want to get the speed with direction from the QEI0. My problem is, that (for me, it seems) arbitrary number of times, discarding any periodicity, the direction flag in the QEI_O_STAT register toggles, however, it seems, that the motor rotates smoothly (without direction change).
The encoder that I have to use doesn't have index signal, so it is not connected to the CPU. The QEI configuration looks like:
MAP_QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 23); MAP_QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, MAP_SysCtlClockGet() / 50 /*Hz*/); MAP_QEIVelocityEnable(QEI0_BASE); MAP_QEIIntEnable(QEI0_BASE, QEI_INTTIMER); MAP_IntEnable(INT_QEI0 : INT_QEI1); MAP_QEIEnable(QEI0_BASE);
And the interrupt handler, where I want to calculate the current RPM:
void HandleInterrupt() { MAP_QEIIntClear(QEI0_BASE, QEI_INTTIMER); // Direction compensated velocity float velocity = MAP_QEIDirectionGet(QEI0_BASE) * MAP_QEIVelocityGet(QEI0_BASE); _rpm = (velocity * 50 /*Hz*/ * 60) / 23 /*PulsePerCycle*/; }
I checked it by print the value of _rpm via serial port or even if I place a break point into the HandleInterrupt() and check the appropriate HW register, I see, that the direction flag changes.
Can anybody help me? What could be the reason? What did I wrong?
Regards,
Norbert