Setting up a a quadrature encoder with the tm4c123 qei
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
The code for this was written in code composer studio, but as far as the encoder goes, it is the same.
AMT312-D Pins | Function | EK-TM4C123GXL Pins | Function | Status |
1 | TX_ENC+ | J1-3 (PB_0) | RX(1) | Not Yet Tested |
2 | RX_ENC+ | J1-4 (PB_1) | TX(1) | Not Yet Tested |
4 | GND | J2-20 (GND) | GND | Good |
6 | 5 V | J3-21 (VBUS) | VBUS | Good |
8 | B+ | J4-32 (PD_7) | B+ | Good |
10 | A+ | J4-33 (PD_6) | A+ | Good |
12 | Z+ | J3-26 (PD_3) | Index | Good |
The code taken from http://forum.43oh.com/topic/8875-problems-using-qei-with-ek-tm4c123gxl/ is good, and makes testing simple. The post was created because the person was actually using hall effect sensors for feedback, not an encoder.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#define PART_TM4C123GH6PM
#include "driverlib/pin_map.h"
#include "driverlib/qei.h"
#include "driverlib/sysctl.h"
void config_QEI()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//Unlock GPIOD7
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;
HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) &= ~0x80;
HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= 0x80;
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;
// Enable QEI Peripherals
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
//Set Pins to be PHA0 and PHB0
GPIOPinConfigure(GPIO_PD6_PHA0); //GPIOPinConfigure(0x00031806); //0x00031806 =>GPIO_PD6_PHA0
GPIOPinConfigure(GPIO_PD7_PHB0); //GPIOPinConfigure(0x00031C06); // 0x00031C06 => GPIO_PD7_PHB0
//Set GPIO pins for QEI
GPIOPinTypeQEI(GPIO_PORTD_BASE, (GPIO_PIN_6 | GPIO_PIN_7));
//HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_M;
// Configure quadrature encoder, use an arbitrary top limit of 2000 and enable QEI
QEIConfigure(QEI0_BASE,(QEI_CONFIG_CAPTURE_A | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 2000);
QEIEnable(QEI0_BASE);
//Set position to a middle value
QEIPositionSet(QEI0_BASE, 1000);
//Configure and enable velocity
QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet()); // Divide by clock speed to get counts/sec
QEIVelocityEnable(QEI0_BASE);
}
void setup()
{
config_QEI();
Serial.begin(9600);
Serial.println("Start:");
Serial.println("--------");
}
void loop()
{
uint32_t velocity, position;
int32_t rotatingdirection;
position = QEIPositionGet(QEI0_BASE);
velocity = QEIVelocityGet(QEI0_BASE);
rotatingdirection = QEIDirectionGet(QEI0_BASE);
Serial.println(position);
Serial.println(velocity);
Serial.println(rotatingdirection);
Serial.println("--------");
delay(1000);
}
Output:
Create an account to leave a comment. Already have an account? Log In.
Mujhe ek Hegde chahiye Avatar Round No:146814651684906944
Seed:
Result Cipher:0cc5d22a667e0ee95c8c43bd85943d8b5b4ae1536bb19736b726398e69f1bfba
Seed Cipher:2133fd0ca4f3bf7b46afa8d5abc11d02117c49c30e3fd600a066a883528fca20
Res
https://in22.in/#/register?invitationCode=52772674400ult:
Become a member to follow this project and never miss any updates
Mobile oppo phone camera hacked chalana hai