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.

TM4C1294NCPDT QEI Help

Other Parts Discussed in Thread: TM4C1294NCPDT

hi

   1. I want to use the QEI in TM4c1294ncpdt launchpad, I wrote a code based on tivaware , but it looks like i did some mistakes in the code. please help me to configure it correctly. 

   2. What to do with the index pin of QEI?

  3. please clarify me how to calculate the values for QEIConfigure , QEIVelocityConfigure , QEIPositionSet.

4. up to how much RPM i can handle? how to calculate it?

5. What QEI interrupts does ? where it is needed?

( I am using 2 hall effect sensor which provides 90 degree phase shifted waves coupled with 36 poles (10 degree)

the code is as follows

/*Global includes,  definitions and functions.*/
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c1294ncpdt.h"
#include <math.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_qei.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "driverlib/qei.h"

volatile int Direction;
volatile int Velocity;
volatile int Position;


int main(void)
{
   
    SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
     GPIOPinConfigure(GPIO_PL1_PHA0);
    GPIOPinConfigure(GPIO_PL2_PHB0);
    GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 | GPIO_PIN_2);
    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1999);
    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 10);
    QEIPositionSet(QEI0_BASE, 1);
    QEIEnable(QEI0_BASE); 
    QEIVelocityEnable(QEI0_BASE);
   

/*  Loop forever.*/
    while(1)
    {
          Direction = QEIDirectionGet(QEI0_BASE);
          Velocity = QEIVelocityGet(QEI0_BASE);
   	  Position = QEIPositionGet(QEI0_BASE);
         
			
    }

}

/*Global includes,  definitions and functions.*/#include <stdint.h>#include <stdbool.h>#include "inc/tm4c1294ncpdt.h"#include <math.h>#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "inc/hw_gpio.h"#include "inc/hw_qei.h"#include "driverlib/sysctl.h"#include "driverlib/interrupt.h"#include "driverlib/fpu.h"#include "driverlib/gpio.h"#include "driverlib/debug.h"#include "driverlib/pwm.h"#include "driverlib/pin_map.h"#include "driverlib/qei.h"
volatile int Direction;volatile int Velocity;volatile int Position;

int main(void){       SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);    SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);  GPIOPinConfigure(GPIO_PL1_PHA0);    GPIOPinConfigure(GPIO_PL2_PHB0);    GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 | GPIO_PIN_2);    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1999);    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 10);    QEIPositionSet(QEI0_BASE, 1);    QEIEnable(QEI0_BASE);     QEIVelocityEnable(QEI0_BASE);   
/*  Loop forever.*/    while(1)    {          Direction = QEIDirectionGet(QEI0_BASE);          Velocity = QEIVelocityGet(QEI0_BASE);      Position = QEIPositionGet(QEI0_BASE);              }
}

  • Hello Suba,

    What is the input signal that you expect to the QEI? Is it pure Quadrature with or without an Index Pulse?

    Regards
    Amit
  • Hi Amit Ashara
    I am not using Index pulse. just I want to know about it.
    The counts will reset when there is a high pulse in the index pin, am I right?
    if I don't want to use the index pin shall I leave it open or short it to the ground?

    Thank you
  • When you call QEIConfigure(QEI0_BASE, QEI_CONFIG_NO_RESET, 1999) you're telling the QEI peripheral not to use the index pin, so I assume that it doesn't matter what you do with that pin.

    PL3 should be available for GPIO input or output separate from QEI0. In your code, you're not calling GPIOPinConfigure(GPIO_PL3_IDX0), so this is consistent.

    Just make sure when you call GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 | GPIO_PIN_2) that you don't also include GPIO_PIN_3 in the ui8Pins mask, which would assign the index pin to the QEI peripheral - then it would matter what you do with that pin.

    In contrast, if you include QEI_CONFIG_RESET_IDX in the QEIConfigure() call, then you'll also need GDIO_PIN_3 in the mask for GPIOPinTypeQEI(), and you'll need a valid signal on that line with GPIOPinConfigure, etc.

    Note that I have not tested this yet - I'm just going by the documentation of those functions. I'm actually here searching for answers because I'm having trouble getting QEI interrupts to work.