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.

TM4C123GH6PM: QEI velocity counting

Part Number: TM4C123GH6PM

Hello,

I have modified an example of measuring possition with incremental encoder and QEI with TM4C123G to measure speed, somehow it works but I have a problem with counting real RPM from QEI Velocity register.

I have seen a formula in datasheet of microcontroller, but I probably understand wrong.

My init code :

void qei1_init(uint32_t encoder_steps_per_turn, uint32_t initial_position)
{
// set pins to be PHA1 and PHB1
GPIOPinConfigure(GPIO_PC5_PHA1);
GPIOPinConfigure(GPIO_PC6_PHB1);

// set GPIO pins for QEI. PhA1 -> PC5, PhB1 -> PC6
GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);

// disable peripheral and int before configuration
QEIDisable(QEI1_BASE);
QEIIntDisable(QEI1_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);

// setting of QEI_O_CTL register

HWREG(QEI1_BASE + QEI_O_CTL) |= QEI_CTL_FILTEN; // Enable input filter
HWREG(QEI1_BASE + QEI_O_CTL) |= QEI_CTL_VELEN;
HWREG(QEI1_BASE + QEI_O_CTL) |= QEI_CTL_ENABLE;

// configure quadrature encoder, use an arbitrary top limit of 10000
QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), encoder_steps_per_turn);

// configure a velocity measurement
QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1, (SysCtlClockGet()/10)); // measure speed during last 100ms

// enable quadrature encoder
QEIEnable(QEI1_BASE);

// enable velocity measurement
QEIVelocityEnable(QEI1_BASE);

// set default position
QEIPositionSet(QEI1_BASE,initial_position);

}

than I check a value in register with :   QEIVelocityGet(QEI1_BASE)

but how to count a real RPM?

I found formula : rpm = (clock * (2 ^ VELDIV) * SPEED * 60) ÷ (LOAD * ppr * edges)

so do I count well in this way?

rpm = (SysCtlClockGet() * (2*1) * QEIVelocityGet(QEI1_BASE) * 60) / (LOAD * 2500 * EDGES)

But I do not know what to put into LOAD and EDGES.

Please can you help me  what to do?

  • Hello Jonas,

    That is covered in the same section of the datasheet.

    For the load, that is based on your timer load value:

    The period of the timer is configurable by specifying the load value for the timer in the QEI Timer Load (QEILOAD) register. When the timer reaches zero, an interrupt can be triggered, and the hardware reloads the timer with the QEILOAD value and continues to count down. At lower encoder speeds, a longer timer period is required to be able to capture enough edges to have a meaningful result. At higher encoder speeds, both a shorter timer period and/or the velocity predivider can be used.

    The load is set by QEIVelocityConfigure and it would be based on the last input given. So your System Clock/10 in your case.

    And for edges: 

    edges is 2 or 4, based on the capture mode set in the QEICTL register (2 for CAPMODE clear and 4 for CAPMODE set)

    So in your case, since you set CAPMODE with QEI_CONFIG_CAPTURE_A_B you would then use 4.