/* 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)
{
}
}
|