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.

TM4的QEI0驱动编码器无法正常获取数据,得到的数据一直为负数



使用QEI1模块得到的数据是正常的,但是改用QEI0得到的数据一直为负数,不管正转或者反转。初始化代码和数据获取代码如下:

void QEI_Init(void)
{
            SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
            SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
   
        GPIOPinTypeQEI(GPIO_PORTD_BASE,GPIO_PIN_7);
        GPIOPinTypeQEI(GPIO_PORTD_BASE,GPIO_PIN_6);
  


    GPIOPinConfigure(GPIO_PD6_PHA0);
    GPIOPinConfigure(GPIO_PD7_PHB0);

    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP), 1999);
    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet() / 100);

    QEIVelocityEnable(QEI0_BASE);
    QEIEnable(QEI0_BASE);
        

}

void get_data()

{

code = QEIDirectionGet(QEI0_BASE);
        code = -(QEIVelocityGet(QEI0_BASE) * code);

}