This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Measure Speed in 28335

Other Parts Discussed in Thread: CONTROLSUITE

hello I'm have to make a control speed with a PMSM... so I need to calculate the speed from the eQEP.

 

I have configured the eQEP registers but not work the calculated of speed... I think that i haven't configurated all registers... this is my code:

 

//###########################################################################
//                  Programa de Lectura de Encoder-Siemens
//###########################################################################
#include "DSP2833x_Device.h"
#include "math.h"


// Prototype statements for functions found within this file.
void Gpio_select(void);
void InitSystem(void);
void encoder(void);

void delay_loop(long);

//###########################################################################
//                                 programa                                   
//###########################################################################

//Declaración de variables

unsigned int k,i,sentido;
float x_actual,x_anterior,delta,T, vel,pos,rpm;

void main(void)
{
   
    InitSystem();         // inicializacion del DSP
    DINT;                // desabilita interrupciones
    Gpio_select();        // selecciona las entradas para encoder
    encoder();            // configura el modulo del encoder
 
    x_actual =0;
    x_anterior=0;
   
    while(1){
               
        if(EQep2Regs.QFLG.bit.UTO==1)
            {
               
            x_actual= (float)EQep2Regs.QPOSCNT;
            sentido= (float)EQep2Regs.QEPSTS.bit.QDF;
            T= (float)EQep2Regs.QUPRD;
                       
                if (sentido==0)                      // POSCNT is counting down
                       {
                    delta= (float)x_actual-x_anterior;    // x2-x1 should be negative
                       }
                   else if (sentido==1)                  // POSCNT is counting up
                       {
                    delta= (float)x_anterior-x_actual;
                      }
               
                pos=(float)delta;///10000;           
                vel= (float)pos / T;                      // Cálculo de la velocidad
                rpm= (float)vel*60;
                x_anterior = x_actual;               //  (k)=(k-1)
               
        EQep2Regs.QCLR.bit.UTO=1;       
        }
    EALLOW;
    SysCtrlRegs.WDKEY = 0x55;
    SysCtrlRegs.WDKEY = 0xAA;
    EDIS;
}
}   

 

//_____________________________________Rutinas____________________________________________


   
void InitSystem(void)
{
    EALLOW;
   
    SysCtrlRegs.WDCR = 0x0028;
    SysCtrlRegs.SCSR = 0x0;
    SysCtrlRegs.PLLSTS.bit.DIVSEL = 0x2;
    SysCtrlRegs.PLLCR.bit.DIV = 0xA;
    SysCtrlRegs.HISPCP.all = 0x1;
       SysCtrlRegs.LOSPCP.all = 0x2;
   
    SysCtrlRegs.PCLKCR0.all = 0x0;
    SysCtrlRegs.PCLKCR1.all = 0x0;
    SysCtrlRegs.PCLKCR3.all = 0x0;
   
    SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK = 1;  //Habilita Clock pama modulo de encoder
   
    EDIS;
}   

void Gpio_select(void)
{
    EALLOW;
   
    GpioCtrlRegs.GPAMUX1.all = 0x0;    // GPIO15 ... GPIO0 = General Puropse I/O
    GpioCtrlRegs.GPAMUX2.all = 0x0;    // GPIO31 ... GPIO16 = General Purpose I/O
    GpioCtrlRegs.GPBMUX1.all = 0x0;    // GPIO47 ... GPIO32 = General Purpose I/O
    GpioCtrlRegs.GPBMUX2.all = 0x0;    // GPIO63 ... GPIO48 = General Purpose I/O
    GpioCtrlRegs.GPCMUX1.all = 0x0;    // GPIO79 ... GPIO64 = General Purpose I/O
    GpioCtrlRegs.GPCMUX2.all = 0x0;    // GPIO87 ... GPIO80 = General Purpose I/O
    GpioCtrlRegs.GPADIR.all = 0;
    GpioCtrlRegs.GPBDIR.all = 0;
    GpioCtrlRegs.GPCDIR.all = 0;       

    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 2;  // GPIO24 se configura como EQEP2A  (CAP1=1)
    GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 2;  // GPIO25 se configura como EQEP2B  (CAP2=1)
    GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 2;  // GPIO26 se configura como EQEP2I  (CAP3=1)

    EDIS;
}  

void encoder(void)
{
                EQep2Regs.QDECCTL.bit.QSRC=00;  // El modulo cuenta en cuadratura
                EQep2Regs.QEPCTL.bit.FREE_SOFT=2; //unaffected by emulation suspend
                EQep2Regs.QEPCTL.bit.PCRM=00; // QPOSCNT se reseta con cada cero (Un0)
                EQep2Regs.QEPCTL.bit.UTE=1;  // Habilita la unidad de Timeout
                EQep2Regs.QEPCTL.bit.QCLM=1;  // Latch on unit time out
                EQep2Regs.QEPCTL.bit.IEL = 1; // IEL_RISING
                EQep2Regs.QEPCTL.bit.IEI = 2; // IEL_RISING
                EQep2Regs.QPOSMAX=4*2500 - 1; //  valor maximo del encoder
                EQep2Regs.QEPCTL.bit.QPEN=1;  // Habilita QEP

                EQep2Regs.QUPRD=1500000;  // unidad de tiempo en 100Hz si SYSCLKOTT=150MHz
}               
//====================================================================