Tool/software: Code Composer Studio
Hi
Hoping to get some help on how to correctly configure the QEI module in TM4C to obtain the speed reading in meters/min .
I have the below initialzation and run-time function which will periodically refresh the variable for the RPM.
The correct RPM measured using a Tachometer is 668rpm but my computed result is 120rpm .
Seems the correct result is 5.6x higher than the computation.
void RunTime(){
volatile uint32_t qeiVelocity,rpm;
uint16_t cyclePerRevolution = 1024;
uint32_t numerator,denominator,loadValue,systemClk,capMode,edges;
qeiVelocity=QEIVelocityGet(QEI0_BASE);
loadValue=(HWREG(QEI0_BASE + QEI_O_LOAD))+1;
capMode=(HWREG(QEI0_BASE + QEI_O_CTL) & QEI_CTL_CAPMODE);
edges = (capMode == 0x00000000) ? 2 : 4 ;
systemClk = MAP_SysCtlClockGet();
systemClk = systemClk/100; //scale down to prevent 32bit overflow
loadValue = loadValue/100; //scale down to prevent 32bit overflow
numerator=(systemClk*qeiVelocity*60);
denominator=(loadValue*cyclePerRevolution*edges);
rpm = numerator/denominator;
}
static void ConveyorInverterCtrl_initQEI(void)
{
// Enable QEI Peripherals
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
//Unlock GPIOD7 - Like PF0 its used for NMI - Without this step it doesn't work
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;
//Set Pins to be PHA0 and PHB0
GPIOPinConfigure(GPIO_PL1_PHA0);
GPIOPinConfigure(GPIO_PL2_PHB0);
//Set GPIO pins for QEI. PhA0 -> PD6, PhB0 ->PD7. I believe this sets the pull up and makes them inputs
GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 | GPIO_PIN_2);
//DISable peripheral and int before configuration
QEIDisable(QEI0_BASE);
QEIIntDisable(QEI0_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);
// Configure quadrature encoder, use an arbitrary top limit of 1000
QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1000);
QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 200e3);
QEIVelocityEnable(QEI0_BASE);
// Enable the quadrature encoder.
QEIEnable(QEI0_BASE);
//Set position to a middle value so we can see if things are working
QEIPositionSet(QEI0_BASE, 500);
}