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: EQEP

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

hi , 
i am using tms320f28379D dsp microcontroller for eQEP (quadrature encoder).
in this Example_279dxEqep_pos_speed.c my qusetions are


tmp = (long)((long)pos16bval*(long)p->mech_scaler); // Q0*Q26 = Q26
tmp &= 0x03FFF000;
tmp = (int)(tmp>>11); // Q26 -> Q15


Ques1. why mech_scalar is taken as 2^26/4000 insted of (1/4000).
Ques2. why the temp is & with 0x03FFF000;
Ques3. why the temp is >>(right shifted) with 11;
Ques4. why the temp is & with 0x7FFF;
Ques5. what is the meaning of newp=_IQ15toIQ(tmp);in that what is _IQ15toIQ(tmp)? if it is equal to tmp/2^9, then why are we dividng tmp by 2^9?


if (p->DirectionQep==0) // POSCNT is counting down
{
if (newp>oldp)
Tmp1 = - (_IQ(1) - newp + oldp); // x2-x1 should be negative
else
Tmp1 = newp -oldp;
}

Ques7. why newp - oldp is subtracted from _IQ(1) =>Tmp1 = - (_IQ(1) - newp + oldp)? why _IQ(1) is used in this statement?

please guide us on above problem as early as possible

  • Hi,

    One of our experts will get back to you on this shortly.

  • Vasanth,

    This is because the example uses IQMath. I would encourage you to look into C2000Ware_3_02_00_00\libraries\math\IQmath\c28\docs

    To answer some of your questions:

    Ques1. why mech_scalar is taken as 2^26/4000 insted of (1/4000).

    This is to convert a floating-point number to IQ26 format.

    Ques3. why the temp is >>(right shifted) with 11;

    This is to convert an IQ26 number to IQ15

    Ques5. what is the meaning of newp=_IQ15toIQ(tmp);in that what is _IQ15toIQ(tmp)? if it is equal to tmp/2^9, then why are we dividng tmp by 2^9?

    It depends on what the global Q is. If the Global Q is 24, then IQ15toIQ will convert the IQ15 number to IQ24, which is by multiplying by 2^9.

    Ques7. why newp - oldp is subtracted from _IQ(1) =>Tmp1 = - (_IQ(1) - newp + oldp)? why _IQ(1) is used in this statement?

    I presume the required operation is 1 - newp + oldp. But since IQMath is being used, you would use _IQ(1) instead of 1.0. I presume newp and oldp are already in IQ format.

    Thanks,

    Sira