📄 f280xqep_no_index.c
字号:
/* ==================================================================================
File name: F280XQEP_NO_INDEX.C
Originator: Digital Control Systems Group
Texas Instruments
Description: This file contains source for the QEP drivers without index signal for the F280X
Target: TMS320F280x family
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20: Using DSP280x v. 1.10 or higher
------------------------------------------------------------------------------------*/
#include "DSP280x_Device.h"
#include "f280xqep_no_index.h"
void F280X_QEP_NO_INDEX_Init(QEP *p)
{
EQep1Regs.QDECCTL.all = QDECCTL_INIT_STATE;
EQep1Regs.QEPCTL.all = QEPCTL_INIT_STATE;
EQep1Regs.QPOSCTL.all = QPOSCTL_INIT_STATE;
EQep1Regs.QUPRD = 1000000; // Unit Timer for 100Hz
EQep1Regs.QCAPCTL.all = QCAPCTL_INIT_STATE;
p->QepCountIndex = 4*p->LineEncoder;
EQep1Regs.QPOSMAX = 4*(Uint32)p->LineEncoder*(Uint32)p->PreScaler;
EALLOW; // Enable EALLOW
// Set up the EQEP1A/B pins to primary functions
GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1; // GPIO20 is EQEP1A
GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1; // GPIO21 is EQEP1B
EDIS; // Disable EALLOW
}
void F280X_QEP_NO_INDEX_Calc(QEP *p)
{
Uint32 MechScalerTmp, RawThetaTmp;
// Check the rotational direction
p->DirectionQep = EQep1Regs.QEPSTS.bit.QDF;
// Check the output position counter for EQEP1
if (EQep1Regs.QPOSCNT >= EQep1Regs.QPOSMAX)
EQep1Regs.QPOSCNT = 0;
p->OutputRawTheta = EQep1Regs.QPOSCNT;
// Compute the mechanical output angle in Q24
MechScalerTmp = p->OutputMechScaler<<15; // OutputMechScaler in Q30
RawThetaTmp = p->OutputRawTheta<<10; // OutputRawTheta in Q0
p->OutputTheta = __qmpy32(MechScalerTmp,RawThetaTmp,31); // Q24 = Q30*Q0
p->OutputTheta &= 0x00FFFFFF; // Wrap around 0x00FFFFFF
// Compute the mechanical motor angle in Q0
p->Counter = p->OutputRawTheta/p->QepCountIndex; // Division quotient
p->RawTheta = p->OutputRawTheta - (Uint32)p->Counter*(Uint32)p->QepCountIndex; // Division reminder
// Compute the mechanical angle in Q24
MechScalerTmp = p->MechScaler<<10; // MechScaler in Q30
RawThetaTmp = p->RawTheta<<15; // RawTheta in Q0
p->MechTheta = __qmpy32(MechScalerTmp,RawThetaTmp,31); // Q24 = Q30*Q0
p->MechTheta &= 0x00FFFFFF; // Wrap around 0x00FFFFFF
// Check unit Time out-event for speed calculation:
// Unit Timer is configured for 100Hz in INIT function
if(EQep1Regs.QFLG.bit.UTO == 1)
{
//**** Low Speed Calculation ****//
if((EQep1Regs.QEPSTS.bit.COEF || EQep1Regs.QEPSTS.bit.CDEF))
{ // Capture Counter overflowed, hence do no compute speed
EQep1Regs.QEPSTS.all = 0x000C;
}
else
// Compute lowspeed using capture counter value
p->QepPeriod = EQep1Regs.QCPRDLAT;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -