主题中讨论的其他器件:HALCOGEN
SIR 现在我需要找到速度 ,在正交脉冲发生器提供 输入 到 引脚 epeqA 和 epeqB ,如何 找到速度 什么 配置应该在 halcoGen 中 , 输入是 时间周期 20毫秒,频率是50赫兹 ,我附加我的代码, 对于这种 配置,我们应该怎样配置,你会帮我吗?
#include "HL_sys_common.h"
/*用户代码开始(1)*/
#include "HL_sys_core.h"
#include "math.h"
#include "HL_sci.h"
#include "HL_eQEP.h"
#define UART sciREG1
#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);
/*在索引事件之前读取位置计数器值*/
posCountValBe =(uint16) eqepReadPosnCompare (eqepREG2);
/*状态标志被设定以表示一个新值被锁存在 QCPRD 寄存器中。 */
if (((eqepREG2->QEPSTS & 0x80U)!= 0U)
{
周期= eqepREG2->QCPRDLAT;
deltaT = eqepREG2->QCPRD;
posCountValft =(uint16) eqepReadStatus (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;
}
谢谢!
耶瓦
















