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?