Author Topic: Is anyone know about this source code?  (Read 3635 times)

0 Members and 1 Guest are viewing this topic.

Offline orchidTopic starter

  • Full Member
  • ***
  • Posts: 54
  • Helpful? 0
Is anyone know about this source code?
« on: April 27, 2008, 09:07:07 PM »
Is there anyone recognize this source code?
Code: [Select]
#include "DSP281x_Device.h"
#include "f281xqep.h"

void  F281X_EV1_QEP_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
          EvaRegs.T2PR = 4*p->LineEncoder;             // Init Timer 1 period Register
          EvaRegs.EVAIFRC.bit.CAP3INT = 1;     // Clear CAP3 flag
          EvaRegs.EVAIMRC.bit.CAP3INT = 1;     // Enable CAP3 Interrupt

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

void F281X_EV1_QEP_Calc(QEP *p)
{

     int32 Tmp;

// 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 + p->CalibratedAngle;

// 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 electrical angle in Q15
     p->ElecTheta = p->PolePairs*p->MechTheta;            // Q0*Q15 = Q15
     p->ElecTheta &= 0x7FFF;                              // Wrap around 0x07FFF
}

void F281X_EV1_QEP_Isr(QEP *p)
{

     p->QepCountIndex = EvaRegs.T2CNT;    // Get the timer 2 counter for one mechanical revolution
     EvaRegs.T2CNT = 0;                   // Reset the timer 2 counter
     p->IndexSyncFlag = 0x00F0;           // Set the index flag

}

What is the function of 'p'? and do i have to define it? all the source code have this 'p' but i still can't figure out what the function.

Offline AndrewM

  • Robot Overlord
  • ****
  • Posts: 255
  • Helpful? 0
Re: Is anyone know about this source code?
« Reply #1 on: April 27, 2008, 09:29:14 PM »
It looks like c++.  p appears to be a pointer reference passed to each of the functions listed.  It is of type QEP, but what QEP is I don't know from the given code.
blog: www.iamwhen.com
Saving the world from humanity one robot at a time.

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: Is anyone know about this source code?
« Reply #2 on: April 27, 2008, 11:49:15 PM »
This could be just regular C. In which case p would just be a pointer to a structure of type QEP.
You should be able to find out what QEP is in one of the headers that is included, e.g. DSP281x Device.h or f281xqep.h (probably this one since it has QEP in the file name....)

Off hand I would say it's some kind thing for calculating RPM from an encoder or something like that.

As a side note, This is why you should use long descriptive names in your code. I'm sure QEP means something to someone but it's pretty unintelligible to every one else. I'm guessing the QE has something to do with Quadrature Encoder or some such but it's all guess work...

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: Is anyone know about this source code?
« Reply #3 on: April 29, 2008, 03:04:14 PM »
That is horribly ilegible code . . . totally useless to anyone but the programmer himself . . .

Yea I'll agree with Jesse, it looks like code for an encoder.

 


Get Your Ad Here