Society of Robots - Robot Forum
Software => Software => Topic started by: orchid on April 27, 2008, 09:07:07 PM
-
Is there anyone recognize this source code?
#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.
-
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.
-
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...
-
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.