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.

EQEP setup

Other Parts Discussed in Thread: CONTROLSUITE

Hi all,

I have a really short question. I'm trying to set the EQEP ports of a F283x device, but it's not clear for me how to select the proper value for the following parameter:

   int mech_scaler;        // Parameter: 0.9999/total count, total count = 4000 (Q26) 

In the example it is set at 16776 and I was looking at the application notes, but it is not clear yet . It says:

"Since the maximum number of clock pulses in one revolution is 4000, i.e., maximum
count value is 4000, then a coefficient, MechScaler, can be defined as,

MechScaler x 4000=360 mechanical = 1per unit(pu)mechanicaldisplacement

MechScaler= (1/4000) pu mech displacement /count
= 16777pu mech displacement/count(in Q30)

 I have 5000 pulses per revolution sensor so I need to change that value, but I don't know how could I work out that 16777. Does anybody can help me with that? I will be more than grateful if you can.

Thanks in advance

  • Danilo,

    // these are the number of slots in the QEP encoder, take this from the spec of the encoder

    qep1.LineEncoder = 2500; 

    // QEP module internally multiplies this by 4 because of the quadrature signals the counts are 4 times hence 
    qep1.MechScaler = _IQ30(0.25/qep1.LineEncoder);

    //specify the number of pole pairs of the motor, this is used to scale the electrical angle from the mechanical angle the QEP provides
    qep1.PolePairs = POLES/2;

    // you must calibrate your QEP
    qep1.CalibratedAngle = 0;

    // if you look inside this macro then you will see how these values are being used
    QEP_INIT_MACRO(1,qep1)

    What example are you referring to?? I will recommend using the latest motor lib from controlsuite

    controlSUITE\libs\app_libs\motor_control\drivers\f2833x_v2.0

  • Dear Manish,

    I'm using the following example

    controlSUITE\device_support\F2837xD\v100\F2837xD_examples_Cpu1\eqep_pos_speed

    I was trying to understand the code and parameter setup but I couldn't follow the line mentioned in my previous post. However, I just found another post which answers my question.

    16777=(1/4000)*2^26 and I think 2^26 comes from the IQ library configuration. Sorry this was a  silly question, but it's my first time working with TI devices. But many thanks for your reply.

  • Hi Manish,

    I have TMS320F28335 Experimenter Kit (TMDSDOCK28335). I have PMSM 400 W, 160 V, 1.85 A , 3000 Rpm parameter values and encoder parameters (8P-2500 P/R). 8 refers to pole number. i can not read speed and position with sensorless PMSM program in controlsuit. Integrated encoder with PMSM has (A,A',B,B',Z,Z',U,U',V,V',W,W', +5V, GND) terminals. I connect A,B,I and +5V, GND. I saw changing of QEP register values in wach window while the system works real time. I think i need to change ancoder program. How can i make to change in following code.

    Thanks a lot.

    /* =================================================================================
    File name: F2833XQEP.H
    Target : F2833x family
    ==================================================================================*/

    #ifndef __F2833X_QEP_H__
    #define __F2833X_QEP_H__

    #include "f2833xbmsk.h"
    #include "f2833xdrvlib.h"


    /*-----------------------------------------------------------------------------
    Initialization states for EQEP Decode Control Register
    ------------------------------------------------------------------------------*/
    #define QDECCTL_INIT_STATE ( XCR_X2 + QSRC_QUAD_MODE )

    /*-----------------------------------------------------------------------------
    Initialization states for EQEP Control Register
    ------------------------------------------------------------------------------*/
    #define QEPCTL_INIT_STATE ( QEP_EMULATION_FREE + \
    PCRM_INDEX + \
    IEI_RISING + \
    IEL_RISING + \
    QPEN_ENABLE + \
    QCLM_TIME_OUT + \
    UTE_ENABLE )

    /*-----------------------------------------------------------------------------
    Initialization states for EQEP Position-Compare Control Register
    ------------------------------------------------------------------------------*/
    #define QPOSCTL_INIT_STATE PCE_DISABLE

    /*-----------------------------------------------------------------------------
    Initialization states for EQEP Capture Control Register
    ------------------------------------------------------------------------------*/
    #define QCAPCTL_INIT_STATE ( UPPS_X32 + \
    CCPS_X128 + \
    CEN_ENABLE )

    /*-----------------------------------------------------------------------------
    Define the structure of the QEP (Quadrature Encoder) Driver Object
    -----------------------------------------------------------------------------*/
    typedef struct {_iq ElecTheta; // Output: Motor Electrical angle (Q24)
    _iq MechTheta; // Output: Motor Mechanical Angle (Q24)
    Uint16 DirectionQep; // Output: Motor rotation direction (Q0)
    Uint16 QepPeriod; // Output: Capture period of QEP signal in number of EQEP capture timer (QCTMR) period (Q0)
    Uint32 QepCountIndex; // Variable: Encoder counter index (Q0)
    int32 RawTheta; // Variable: Raw angle from EQEP Postiion counter (Q0)
    _iq MechScaler; // Parameter: 0.9999/total count (Q30)
    Uint16 LineEncoder; // Parameter: Number of line encoder (Q0)
    Uint16 PolePairs; // Parameter: Number of pole pairs (Q0)
    int32 CalibratedAngle; // Parameter: Raw angular offset between encoder index and phase a (Q0)
    Uint16 IndexSyncFlag; // Output: Index sync status (Q0)
    } QEP;

    /*-----------------------------------------------------------------------------
    Default initializer for the QEP Object.
    -----------------------------------------------------------------------------*/

    #define QEP_DEFAULTS { 0x0,0x0,0x0,0x0,0x0,0x0,0x00020000,0x0,2,0,0x0}

    /*-----------------------------------------------------------------------------
    QEP Init and QEP Update Macro Definitions
    -----------------------------------------------------------------------------*/


    #define QEP_INIT_MACRO(m,v) \
    \
    (*eQEP[m]).QDECCTL.all = QDECCTL_INIT_STATE; \
    (*eQEP[m]).QEPCTL.all = QEPCTL_INIT_STATE; \
    (*eQEP[m]).QPOSCTL.all = QPOSCTL_INIT_STATE; \
    (*eQEP[m]).QUPRD = 1500000; /* Unit Timer for 150Hz*/ \
    (*eQEP[m]).QCAPCTL.all = QCAPCTL_INIT_STATE; \
    (*eQEP[m]).QPOSMAX = 4*v.LineEncoder; \
    \

    //Make sure that the pin configuration is properly done in ...-DevInit_F2803x.c file like below \
    EALLOW; /* Enable EALLOW*/ \
    GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1; /* GPIO20 is EQEP1A */ \
    GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1; /* GPIO21 is EQEP1B */ \
    GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 1; /* GPIO23 is EQEP1I */ \
    EDIS; /* Disable EALLOW*/


    #define QEP_MACRO(m,v) \
    \
    /* Check the rotational direction */ \
    v.DirectionQep = (*eQEP[m]).QEPSTS.bit.QDF; \
    \
    /* Check the position counter for EQEP1 */ \
    v.RawTheta = (*eQEP[m]).QPOSCNT + v.CalibratedAngle; \
    \
    if (v.RawTheta < 0) \
    v.RawTheta = v.RawTheta + (*eQEP[m]).QPOSMAX; \
    else if (v.RawTheta > (*eQEP[m]).QPOSMAX) \
    v.RawTheta = v.RawTheta - (*eQEP[m]).QPOSMAX; \
    \
    /* Compute the mechanical angle */ \
    v.MechTheta= v.MechScaler*v.RawTheta; \
    /* Compute the electrical angle */ \
    v.ElecTheta = (v.PolePairs*v.MechTheta) -floor(v.PolePairs*v.MechTheta); /* Q24 = Q0*Q24 */ \
    \
    /* Check an index occurrence*/ \
    if ((*eQEP[m]).QFLG.bit.IEL == 1) \
    { \
    v.IndexSyncFlag = 0x00F0; \
    v.QepCountIndex = (*eQEP[m]).QPOSILAT; \
    (*eQEP[m]).QCLR.bit.IEL = 1; /* Clear interrupt flag */ \
    } \
    \
    /* Check unit Time out-event for speed calculation: */ \
    /* Unit Timer is configured for 100Hz in INIT function*/ \
    if((*eQEP[m]).QFLG.bit.UTO == 1) \
    { \
    /***** Low Speed Calculation ****/ \
    if(((*eQEP[m]).QEPSTS.bit.COEF || (*eQEP[m]).QEPSTS.bit.CDEF)) \
    { /* Capture Counter overflowed, hence do no compute speed*/ \
    (*eQEP[m]).QEPSTS.all = 0x000C; \
    } \
    else if((*eQEP[m]).QCPRDLAT!=0xffff) \
    /* Compute lowspeed using capture counter value*/ \
    v.QepPeriod = (*eQEP[m]).QCPRDLAT; \
    }

    #endif // __F2833X_QEP_H__

  • Yeah I found those in project called HVPM_Sensored but there is an error in DMC2833x_DRV.pdf. Because it said that code composer is converting MechScaler in I2Q30 format, but the numbers are wrong because (1/4000)*2^30 its not 16777 rather 268435.456.
  • Hello user4800014,

    I see that you are posting to a thread which has been inactive since 2014. If you have an issue for which you require support, please post a new thread.

    Best Regards,
    Adam Dunhoft