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.

AM4379的qep功能



以下是我的代码 一个初始化函数和一个计算函数,但是计算的到的direction总是不对。

寄存器配置写入数据成功,就是方向DirectionQep一直在0和1之间变化

void POSSPEED_Init(void)
{
    // Unit Timer for 100Hz at 200 MHz SYSCLKOUT
*(volatile uint32_t *) PWMSS_EQEP_QUPRD = 2000000;

//正交计数模式选择 14 15位置00 正交编码模式 QSRC
*(volatile uint16_t *) PWMSS_EQEP_QDECCTL &= (uint16_t)0x3fff;

// //位置计数器不受仿真挂起的影响
*(volatile uint16_t *) PWMSS_EQEP_QEPCTL &= (uint16_t)0x3fff;//
*(volatile uint16_t *) PWMSS_EQEP_QEPCTL |= (uint16_t)0x8000; //14 15 位 写10

//位置计数器在索引位置上复位 pcrm=00 QPOSCNT reset on index event
*(volatile uint16_t *)PWMSS_EQEP_QEPCTL &= (uint16_t)0xcfff;//12-13位清零 00

//使能单元定时器
*(volatile uint16_t *)PWMSS_EQEP_QEPCTL |= (uint16_t)0x0002;//1位填充1

//QEP捕捉锁存模式 单元超时时候锁存,单元超时的时候位置计数器 等被锁存
*(volatile uint16_t *) PWMSS_EQEP_QEPCTL |= (uint16_t)0x0004;//第2位置1

//最大位置计数器
*(volatile uint32_t *)PWMSS_EQEP_QPOSMAX = (uint32_t)0xffffffff;//写数据

//位置计数器使能
*(volatile uint16_t *)PWMSS_EQEP_QEPCTL |= (uint16_t)0x0008;//第3位置1

//单元位置事件预分频器 32分频 5
*(volatile uint16_t *)PWMSS_EQEP_QCAPCTL &= (uint16_t)0xfff0;//先清零0-3位
*(volatile uint16_t *)PWMSS_EQEP_QCAPCTL |= (uint16_t)0x000A;//写数据


//qep捕获时那个时期时钟预分配 128
*(volatile uint16_t *)PWMSS_EQEP_QCAPCTL &= (uint16_t)0xff0f;//4-6位
*(volatile uint16_t *)PWMSS_EQEP_QCAPCTL |= (uint16_t)0x0070;

//使能qep捕获
*(volatile uint16_t *)PWMSS_EQEP_QCAPCTL |= (uint16_t)0x8000;

}


//position speed 位置速度计算函数
void POSSPEED_Calc(void)
{
long tmp;
int pos16bval;

//方向寄存器 1顺时针 正转
UART_printf("\n %x \n",*(volatile uint16_t *)PWMSS_EQEP_QEPSTS );
int DirectionQep = (*(volatile uint16_t *)PWMSS_EQEP_QEPSTS & (uint16_t)0x0020)>>5;

//pos16bval是脉冲的个数
pos16bval=*(volatile int32_t *)PWMSS_EQEP_QPOSCNT;

UART_printf("\n count number is %d \n",pos16bval );

}

我是在定时器中断中不断调用第二个函数的,请问我的代码这样配置有问题吗?