Part Number: TMS320F28335
Other Parts Discussed in Thread: CONTROLSUITE
Tool/software: Code Composer Studio
I am trying to control a direction and position of encoder-mounted Motor via EQEP. Position control is working good, where as direction reading fluctuates from 0 to 1 and vice versa, though it is keep moving to the same direction. The code is here below:
/* Define for this example */
#define ENCODER_REV 200 /* Pulse/Revolution */
void InitEQep1(Uint32 PositionMax);
interrupt void eqep1_isr(void);
Uint16 BackTicker;
Uint32 PositionCounter;
Uint32 RotateDirection;
float32 RotateAngleUnit;
float32 RotateAngleDegree;
{
Step 1
Disable Global Interrupt & Interrupt Flag Clear
-----------------------------------------------------------------------------*/
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitSysCtrl();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EQEP1_INT= &eqep1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
/* for Qep */
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO20 = 0; /* Enable pull-up on GPIO50 (EQEP1A) */
GpioCtrlRegs.GPAPUD.bit.GPIO21 = 0; /* Enable pull-up on GPIO51 (EQEP1B) */
GpioCtrlRegs.GPAPUD.bit.GPIO22 = 0; /* Enable pull-up on GPIO52 (EQEP1S) */
GpioCtrlRegs.GPAPUD.bit.GPIO23 = 0; /* Enable pull-up on GPIO53 (EQEP1I) */
GpioCtrlRegs.GPAQSEL2.bit.GPIO20 = 2; /* Qualification using 6 samples */
GpioCtrlRegs.GPAQSEL2.bit.GPIO21 = 2; /* Qualification using 6 samples */
GpioCtrlRegs.GPAQSEL2.bit.GPIO22 = 2; /* Qualification using 6 samples */
GpioCtrlRegs.GPAQSEL2.bit.GPIO23 = 2; /* Qualification using 6 samples */
GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1; /* Configure GPIO51 as EQEP1B */
GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 1; /* Configure GPIO52 as EQEP1S */
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 1; /* Configure GPIO53 as EQEP1I */
EDIS;
PositionCounter = 0;
RotateDirection = 0;
RotateAngleUnit = 0;
RotateAngleDegree = 0;
PieCtrlRegs.PIEIER5.bit.INTx1 = 1;
InitEQep1(PositionMax);
EINT; /* Enable Global interrupt INTM */
ERTM; /* Enable Global realtime interrupt DBGM */
for(;;)
{
}
interrupt void eqep1_isr(void)
{
BackTicker++;
PositionCounter = EQep1Regs.QPOSCNT;
RotateDirection = EQep1Regs.QEPSTS.bit.QDF;
RotateAngleUnit = (float32)PositionCounter / PositionMax;
RotateAngleDegree = RotateAngleUnit * 360;
Step 10
10.1 Local Interrupt Service Routines & Functions
-----------------------------------------------------------------------------*/
void InitEQep1(Uint32 PositionMax)
{
EQep1Regs.QEPCTL.bit.PCRM=1; // PCRM=00 mode - QPOSCNT reset on index event
EQep1Regs.QEPCTL.bit.QCLM=1; // Latch on unit time out
EQep1Regs.QPOSMAX = PositionMax - 1; /* 24 x 4 QCLK @ 1 revolution */
EQep1Regs.QEPCTL.bit.QPEN=1; // QEP enable
EQep1Regs.QCAPCTL.bit.CCPS=6; // 1/64 for CAP clock
EQep1Regs.QCAPCTL.bit.CEN=1; // QEP Capture Enable
EQep1Regs.QPOSCTL.bit.PCE = 1 ; // enable position compare unit