尊敬的 SIR ,在配置增强型正交编码器(eqep2) 时基元 时间事件选项的十六进制十进制 值,我应该给什么值 ,得到正确的时间段值 ,然后时基元时间事件 ,其中 SI 单位将是微,毫微,毫, Cape Period 寄存器中存在的值太高、 未得到正确的值
#include "HL_sys_common.h"
/*用户代码开始(1)*/
#include "HL_sys_core.h"
#include "math.h"
#include "HL_sci.h"
#include"HL_etpwm.h"
#include "HL_eQEP.h"
#define UART sciREG1
void pulse_width (void);
#define clkfreq 75000000
#define PPR 30U
uint16 data_buffer [10];
void sciDisplayText (scibase_t * sci、uint16 *文本、uint32长度);
Uint16 eqepReadCapturePeriodLatch (eqepBASE-_t * eQEP);
uint32_t posCountValBef;
uint32_t posCountValAft;
uint16 deltaT = 0u;
Uint8 PI = 3;
UINT8 D=1;
uint8周长;
UINT8速度= 0;
uint16频率;
uint16 RPM = 0;
UINT16距离= 0;
UINT16速度= 0;
uint16周期;
UINT8方向;
UINT16状态;
uint16 time_period;
空等待(UINT32时间);
#定义索引10
/*用户代码结束*/
/**@fn void main (void)
*@简介应用程序主要功能
*@注意此功能默认为空。
*
*此函数在启动后调用。
*用户可以使用此函数来实施应用程序。
*/
/*用户代码开始(2)*/
/*用户代码结束*/
int main (空)
{
/*用户代码开始(3)*/
QEPInit ();
sciInit();
_enable_interrupt_();
/*启用位置计数器*/
eqepEnableCounter (eqepREG2);
/*启用单元定时器。 */
eqepEnableUnitTimer (eqepREG2);
/*启用捕获计时器和捕获周期锁存。 */
eqepEnableCapture (eqepREG2);
deltaT = eqepREG2->QCPRD;
Status = eqepREG2->QUPRD;
time_period = eqepREG2->QCPRDLAT;
/*在索引事件之前读取位置计数器值*/
posCountValBe =(uint16) eqepReadPosnCompare (eqepREG2);
/*状态标志被设定以表示一个新值被锁存在 QCPRD 寄存器中。 */
if (((eqepREG2->QEPSTS & 0x80U)!= 0U)
{
// eqepSetCapturePeriod (eqREG210000U);
deltaT = eqepREG2->QCPRD;
Status = eqepREG2->QUPRD;
time_period = eqepREG2->QCPRDLAT;
posCountValAft =(uint16) eqepReadPosnCompare (eqepREG2);
速度=(ppr / deltaT);
/*将周期寄存器中的值分配到周期变量中*/
圆周=(双)(D * pi );/*圆轮,将直径转换为计量表,然后使用*/
频率=(uint16)((1000000U)/(uint16)(time_period));/*将微秒转换为秒*/
RPM =(uint16)((频率* 60)/ PPR);/*乘以60可将秒转换为最小值*/
distance =(uint16)((周长* RPM)/60);/*除以60将 Min 转换为 Sec */
速度=(uint16)((RPM *周长*60)/1000);/*乘以60将最小值转换为小时、将1000除以 m 转换为 km */
/*在发生索引事件后读取位置计数器值*/
if (posCountValft > posCountValBef){
DIRECTION = 1;/*方向是向电*/
}其他{
Direction = 2;/*方向是反向*/
}
/*清除状态标志。 */
eqepREG2->QEPSTS |= 0x80U;
} 此代码先生 , 尽快回复
谢谢!
耶瓦