//=========================================
//eQEP.件
//=========================================
#ifndef EQEP_POS_SPEED_GET_H
#define EQEP_POS_SPEED_GET_H
#include "F2833x_FPU_FastRTS.h"
//-----------------------------------------
//定义eQEP用到的结构体对象类型
//-----------------------------------------\
typedef struct{float ElecTheta;
float MechTheta;
int DirectionQep;
int PolePairs;
int LineEncoder;
int Encoder_N;
int Calibrateangle;
float Mech_Scaler;
float RawTheta;
int Index_sync_flag;
float BaseRpm;
float Speed_Mr_Rpm_Scaler;
float speed_Mr_Prm;
float Position_k_1;
float Position_k;
float Speed_Tr_Rpm_Scaler;
float Speed_Tr_Rpm;
float Speed_Tr;
void (*init)();
void (*calc)();
}
EQEP_POS_SPEED_GET;
//---------------------------------------------------------
//声明EQEP_POS_SPEED_GET_handle为EQEP_POS_SPEED_GET指针类型
//---------------------------------------------------------
//typedef EQEP_POS_SPEED_GET *EQEP_POS_SPEED_GET_handle;
//---------------------------------------------------------
//定义eQPE转速,位置测量用到的初始值
//---------------------------------------------------------
#defin EQEP_POS_SPEED_GET_DEFAULTS{0,0,0,\2,1000,4000,0,1.0/4000,0,0\6000.0,\
1.5,0,0,0,0,\562500,0,0,\(void(*)(long))eQEP_pos_speed_get_Init,\
(void(*)(long))eQEP_pos_speed_get_Calc}
//------------------------------------------------------------------
//函数声明
//--------------------------------------------------------------------
voide QEP_pos_speed_get_Init(EQEP_POS_SPEED_GET_handle);
voide QEP_pos_speed_get_Calc(EQEP_POS_SPEED_GET_handle);
timeout on t2 timer#endif
//====================================================================
//END of file
//====================================================================
//eQEP.c 文件
//====================================================================
#include "DSPF2833x_Project.h"
#include "F2833x_FPU_FastRTS.h"
#include <math.h>
#include "eQEP.h"
//==============函数定义===============================================
//*********************************************************************
/*@Description:eQEP.h模块的初始化*/
//*********************************************************************
voide QEP_pos_speed_get_Init(EQEP_POS_SPEED_GET*p)
{
#if (CPU_FRQ_150MHZ)
EQep1regs.QUPRD=1500000;
#endif
#if (CPU_FRQ_100MHZ)
EQep1regs.QUPRD=1000000;
#endif
EQep1Regs.QDECCTL.bit.QSRC=00;
EQep1Regs.QEPCTL.bit.FREE_SOFT=2;
EQep1Regs.QEPCTL.bit.PCRM=00;
EQep1Regs.QEPCTL.bit.UTE=1;
EQep1Regs.QEPCTL.bit.QCLM=1;
EQep1Regs.QEPCTL.bit.QPEN=1;
EQep1Regs.QCAPCTL.bit.UPPS=1;
EQep1Regs.QCAPCTL.bit.CCPS=7;
EQep1Regs.QCAPCTL.bit.CEN=1;
EQep1Regs.QPOSMAX=P->Encoder_N;
EQep1Regs.QEPCTL.bit.SWI=1;
InitEQep1Gpio();
}
//*******************************************************************
/* @Description:角度、速度计算函数*/
//**************************************************************************
voide QEP_pos_speed_get_Calc(EQEP_POS_SPEED_GET*P)
{
float tmpl;
unsigned long t2_t1;
//检测转动方向
p->DirectionQep=EQep1Regs.QEPSTS.bit.QDF;
//检测位置计数器的值、并进行补偿
p->RawTheta=EQep1Regs.QPOSCNT+P>CalibrateAngle;
if(p->RawTheta<0)
{ p->RawTheta=p->RawTheta+EQep1Regs.QPOSMAX:}
elseif(p->RawTheta>EQep1Regs.QPOSMAX;)
{p->RawTheta=p->Mech_Scaler*p->RawThera-EQep1Regs.QPOSMAX;}
//计算机械角
p->MechThera=p->Mech_Scaler*p->RawThera;
//计算电角度
p-ElecTheta=(p-PolePairs*p->MechTheta)-floor(p->PolePairs*p->MechThera);
//检测索引信号
if(EQep1Regs.QFLG.bit.IEL==1)
{
p->Index_sync_flag=0x00F0;
EQep1Regs.QCLR.bit.IEL=1; //清除中断信号
}
//High Speed Calcultation using QEP Position counter
//Check unit Timeout-event for speed calculation;
//unit Timer is configured for 100 Hzin INIT function
if(EQep1Regs.QFLG.bit.UTO==1)
{
p->Postion_k=1.0*EQep1Regs.QPOSLAT;
if(p->DirectionQep==0)//POSCNT is counting down
{
if (p->Position_>p->Position_k_1)
{tmpl=-(p->ENcoder_N-(P->Position_k-p>Position_k_1));}
else
{tmpl=p->Position_k-p>Position_k_1;}//x2-x1 shoud be negative
elseif
(p->DirectionQep==1) //POSCNT is counting down
{
if(p->Position_k<p->Posiyion_k_1)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论