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.

TMS320F28379D: Determination of Speed

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



  • Hi, 

    This is because in one cycle, position counter is incremented on both rising and falling edges as resolution is 2x.

  • Hi Divesh,

    With the Above Suggestion,  I tried the changing the resolution to 1x, calculation as well as Results attached Below.

    Multiplier derivation :

    UPPS - 128

    SYSClk - 100000000

    Cp - 8

    CPR - 2048

    Multiplier : (UPPS*(SYSClk/Cp))/(CPR)))       => Should be 781250, but when I place 1562500(781250*2), as Multiplier I was able to find the Exact Speed 


    Results:

    Motor Rotation Speed Maximum Pos Count Multiplier  Speed Read
    1x (Count Raising Edge Only)
    150 2048 1562500 150
    1000 2048 1562500 1000
    500 2047 1562500 500
    150 2048 781250 75
    1000 2048 781250 500
    500 2048 781250 250
    2x(Count Raising Edge & Failing Egde Only)
    150 2048 1562500 150
    1000 2048 1562500 1000
    500 2047 1562500 500
    150 2048 781250 75
    1000 2048 781250 500
    500 2048 781250 250


    Thanks for the Response,
    Soumitri Kumar.

  • Hi,

    Are you using both QEPA and QEPB inputs?

    Thanks,

    Divesh

  • Hi

    Also, have you changed sysclk to 100 MHz? Because it is 200 MHz for TMS320F28379D.

  • Hi, 

    Given: 512 pulses per revolution.

    Capture clock frequency=sysclk/8 ( as per your code)= 100 MHz/8.

    If we are connecting both A and B signals to eQEP module and counting rising edges, 1024 pulses would be generated in one revolution of motor. The period register (QCPRD) gives time taken between consecutive unit position events(here 128 counts). 

    Time taken to capture 128 pulses=( FullCountTicks*8)/10^8

    Time taken by one pulse=( (FullCountTicks*8)/10^8)/128.

    In one complete revolution of motor, 1024 pulses would be generated.

    Time taken to complete one revolution =(1024*( FullCountTicks*8)/10^8)/128.

    Frequency=1/Time= 1562500/FullCountsTicks.

    In your code, 2048 is used in place of 1024. Hence, the speed measured is incorrect.

  • Hi Divesh,

    When EQEP_getCapturePeriod(), used I got 2047 period starting from after Index reset - to support this Here is the Related Video




    Thanks,
    Soumitri

  • Hi,

    This is true in case of 2x resolution. Then also the multiplier would remain same.

  • Hi,

    Yes, with Multiplier set to 781250, speed read to Half with & without 2x Resolution, for Testing purpose I Multiplied the Multiplier with 2, to get 1562500,to match the Motor Speed.

    Thanks,
    Soumitri

  • Hi ,

    Refer explanation above, the multiplier would remain the same. If resolution is 2x , the number of pulses, if pos count is 128, is 64. If resolution is 2x, the pos count would be 2048 instead of 1024. The multiplier would remain same for both 1x and 2x resolution . The multiplier would be 1562500 instead of 781250 irrespective of the resolution. Hope this solves your query.

  • Hi Divesh,

    let us consider No.of Pulses "1000", read through per every revolution 150RPM, when Only raising Edge is Considered 1X resolution be (1000),  when Both Edges are Considered then 2x (2000).

    In this Case, 512 PPR
    In 2x Resolution - (512*2)  - 1024
    In 1x Resolution - (512*1)  - 512

    If that the case the above test done to verify that.
    But I didn't get the reduced ticks.

    Thanks,
    Soumitri.