1656 views|0 replies

3836

Posts

19

Resources
The OP
 

MSP432E401Y Motor Encoder QEI Module [Copy link]

/* DriverLib Includes */
#include <ti/devices/msp432e4/driverlib/driverlib.h>

/* Standard Includes */
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>

unsigned long COUNT = 0;
unsigned long POS = 0;
int s;
int d;

//************************************************************************
//QEI0 initialization

int
QEIInit (void)
{
QEIConfigure(QEI0_BASE,(QEI_CONFIG_CAPTURE_A_B |QEI_CONFIG_NO_RESET|
QEI_CONFIG_QUADRATURE|QEI_CONFIG_NO_SWAP),10000000); //Use A and B channels to calculate the position with 4 edges

/* GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_1,
GPIO_STRENGTH_4MA,
GPIO_PIN_TYPE_STD);

GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_2,
GPIO_STRENGTH_4MA,
GPIO_PIN_TYPE_STD);

GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_3,
GPIO_STRENGTH_4MA,
GPIO_PIN_TYPE_STD);
*/
GPIOPinTypeQEI(GPIO_PORTL_BASE,GPIO_PIN_1|GPIO_PIN_2);//配置PL1,PL2为PhA1,PhB1
QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 120000000/100);//10ms

//Enable speed calculation, enable QEI
QEIVelocityEnable(QEI0_BASE);
QEIEnable(QEI0_BASE);

//Trigger interrupt when speed timer is finished
QEIIntEnable(QEI0_BASE,QEI_INTTIMER);
IntEnable(INT_QEI0);


return(0);
}

void QEI0_IRQHandler(void)
{


QEIIntClear(QEI0_BASE, QEI_INTTIMER);
POS = QEIPositionGet(QEI0_BASE);
d = QEIDirectionGet(QEI0_BASE);

COUNT = QEIVelocityGet(QEI0_BASE);
s = (COUNT*6000)/2024;
printf("The Speed is %d .Velocity is %d.Direction is %d.\n",s,COUNT /4,d);
COUNT = 0;


}

int main(void)
{

/* Configure the system clock for 120 MHz */
MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
120000000);

MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);//使能QEI0外设
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);/*enable L port*/
MAP_IntEnable(INT_GPIOL);

GPIOPinConfigure(GPIO_PL1_PHA0);
GPIOPinConfigure(GPIO_PL2_PHB0);

QEIEnable(QEI0_BASE); //Enable quadrature encoder QEI0

QEIInit();
while(1)
{

}
}

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list