⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f281xqep_no_index.c

📁 TI公司28系列DSP控制无刷直流电机
💻 C
字号:
/* ==================================================================================
File name:       F281XQEP_NO_INDEX.C
                    
Originator:	Digital Control Systems Group
			Texas Instruments

Description:   This file contains source for the QEP drivers without index signal for the F281X

Target: TMS320F281x family
       
=====================================================================================
History:
-------------------------------------------------------------------------------------
 04-15-2005	Version 3.20: Using DSP281x v. 1.00 or higher 
----------------------------------------------------------------------------------*/

#include "DSP281x_Device.h"
#include "f281xqep_no_index.h"

void  F281X_EV1_QEP_NO_INDEX_Init(QEP *p)
{
 
    EvaRegs.CAPCONA.all = QEP_CAP_INIT_STATE;    // Set up capture units
    EvaRegs.T2CON.all = QEP_TIMER_INIT_STATE;    // Set up capture timer
    p->QepCountIndex = 4*p->LineEncoder;
    EvaRegs.T2PR = p->QepCountIndex;

    EALLOW;                       // Enable EALLOW 
    GpioMuxRegs.GPAMUX.all |= 0x0300;     // Set up the capture pins to primary functions
    EDIS;                         // Disable EALLOW 

}    


void F281X_EV1_QEP_NO_INDEX_Calc(QEP *p)
{

     int32 Tmp;
     Uint32 MechScalerTmp;

// Check the rotational direction
     p->DirectionQep = 0x4000&EvaRegs.GPTCONA.all;
     p->DirectionQep = p->DirectionQep>>14;

// Check the timer 2 counter for QEP
     p->RawTheta = EvaRegs.T2CNT;

// Compute the mechanical angle in Q15
     Tmp = __qmpy32by16(p->MechScaler,p->RawTheta,31);   // Q15 = Q30*Q0 
     p->MechTheta = (int16)(Tmp);                        // Q15 -> Q15
     p->MechTheta &= 0x7FFF;                             // Wrap around 0x07FFF

// Compute the mechanical output angle in Q0
     p->OutputRawTheta = (int32)p->Counter*(int32)p->QepCountIndex + (int32)p->RawTheta;

// Re-scaling the mechanical scaler output angle (Q30)
     MechScalerTmp = p->OutputMechScaler<<16;

// Compute the mechanical output angle in Q15
     Tmp = __qmpy32(MechScalerTmp,p->OutputRawTheta,31);   // Q15 = Q30*Q0 
     p->OutputTheta = (int16)(Tmp);                        // Q15 -> Q15
     p->OutputTheta &= 0x7FFF;                             // Wrap around 0x07FFF

   
}


void F281X_EV1_QEP_NO_INDEX_Isr(QEP *p)
{

// Wrap around counter in both directions.
     if (p->DirectionQep==1) {
     	if (p->Counter++ == p->PreScaler)
        	p->Counter = 0;
     }
     else {
     	if (p->Counter-- <= 0)
        	p->Counter = p->PreScaler;
     }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -