Jump to content
Sign in to follow this  
neyre

[Energia Library] TI Launchpad TM4C129 QEI (Quadrature Encoder Interface) Energia Code

Recommended Posts

#include <stdint.h>
#include "driverlib/sysctl.h"
#include "driverlib/qei.h"
 
int pos;
 
// On TM4C129, connect phase A to PL_1 and phase B to PL_2
 
void setup() {
  Serial.begin(9600);
 
  // Setup QEI Module
  SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
  GPIOPinConfigure(0x000A0406); //GPIO_PL1_PHA0
  GPIOPinConfigure(0x000A0806); //GPIO_PL2_PHB0
  GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 |  GPIO_PIN_2);
 
  // Configure and Enable QEI
  QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 20000);
  QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet()); // Divide by clock speed to get counts/sec
  QEIEnable(QEI0_BASE);
  QEIVelocityEnable(QEI0_BASE);
}
 
void loop() {
  // Report Position & Velocity of Encoder to Serial Terminal
  Serial.print(QEIPositionGet(QEI0_BASE));
  Serial.print(',');
  Serial.println(QEIVelocityGet(QEI0_BASE));
}

Working code using the hardware QEI interface on the TM4C129. Hopefully useful for somebody else.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×