Part Number: TMS320F28379D
Hello Forms,
Test Case: Using Absolute Encoder(AS5147 - A, B, I& PWM) with 512 PPR, When Rotating a Motor at Different RPM as Follows.1
Issue : Set is Speed and Calcultaed Speed are exactly Half of the Set Speed.
Info:
Related to Encoder Reading Peripherial & Calculation of Speed as Follows.
==================================
Initalization of Encoder
==================================
void EQEP_1_init(){
//
// Sets the polarity of the eQEP module's input signals.
//
EQEP_setInputPolarity(EQEP_1_BASE,false,false,false,false);
//
// Configures eQEP module's quadrature decoder unit.
//
EQEP_setDecoderConfig(EQEP_1_BASE, (EQEP_CONFIG_QUADRATURE | EQEP_CONFIG_2X_RESOLUTION | EQEP_CONFIG_NO_SWAP | EQEP_CONFIG_IGATE_DISABLE));
//
// Set the emulation mode of the eQEP module.
//
EQEP_setEmulationMode(EQEP_1_BASE,EQEP_EMULATIONMODE_RUNFREE);
//
// Configures eQEP module position counter unit.
//
EQEP_setPositionCounterConfig(EQEP_1_BASE,EQEP_POSITION_RESET_MAX_POS,2047U);
//
// Sets the current encoder position.
//
EQEP_setPosition(EQEP_1_BASE,0U);
//
// Disables the eQEP module unit timer.
//
EQEP_disableUnitTimer(EQEP_1_BASE);
//
// Disables the eQEP module watchdog timer.
//
EQEP_disableWatchdog(EQEP_1_BASE);
//
// Configures the quadrature modes in which the position count can be latched.
//
EQEP_setLatchMode(EQEP_1_BASE,(EQEP_LATCH_UNIT_TIME_OUT|EQEP_LATCH_RISING_STROBE|EQEP_LATCH_RISING_INDEX));
//
// Configures the mode in which the position counter is initialized.
//
EQEP_setPositionInitMode(EQEP_1_BASE,(EQEP_INIT_RISING_STROBE));
//
// Sets the software initialization of the encoder position counter.
//
EQEP_setSWPositionInit(EQEP_1_BASE,false);
//
// Sets the init value for the encoder position counter.
//
EQEP_setInitialPosition(EQEP_1_BASE,0U);
//
// Enables the eQEP module.
//
EQEP_enableModule(EQEP_1_BASE);
//
// Configures eQEP module edge-capture unit.
//
EQEP_setCaptureConfig(EQEP_1_BASE,EQEP_CAPTURE_CLK_DIV_8,EQEP_UNIT_POS_EVNT_DIV_128);
//
// Enables the eQEP module edge-capture unit.
//
EQEP_enableCapture(EQEP_1_BASE);
//
// Configures eQEP module position-compare unit.
//
EQEP_setCompareConfig(EQEP_1_BASE,(EQEP_COMPARE_NO_SYNC_OUT | EQEP_COMPARE_NO_SHADOW), 0U, 0U);
//
// Enables the eQEP module position-compare unit.
//
EQEP_enableCompare(EQEP_1_BASE);
}
==================================
Calculation of Speed Using Below Function
==================================
void SpeedFinder(void)
{
uint16_t OverFlow_Flag = (EQEP_getStatus(EQEP_1_BASE));
if((OverFlow_Flag & EQEP_STS_CAP_OVRFLW_ERROR) !=0)
{
TotalTicks += 65535;
EQEP_clearStatus(EQEP_1_BASE, EQEP_STS_CAP_OVRFLW_ERROR);
}
if((OverFlow_Flag & EQEP_STS_UNIT_POS_EVNT) !=0)
{
EQEP_clearStatus(EQEP_1_BASE, EQEP_STS_UNIT_POS_EVNT);
uint16_t QCPRD = EQEP_getCapturePeriod(EQEP_1_BASE);
FullCountTicks = TotalTicks + QCPRD;
if(FullCountTicks >0L)
{
RPS = (float)781250/FullCountTicks;(781250 = (((UPPS[128]*(SYSClk[100.000,000]/Cp[8]))/(CPR[2048])))
mech_rpm = (float)RPS*60;
TotalTicks = 0;
FullCountTicks = 0;
}
else
{
RPS = 0;
}
}
}
Thanks in Advance,
Soumitri Kumar
