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.

TMS320F28335: TMS320F28379D: 在eQEP模块的官方示例文件中,电机速度和位置测量例程中的“eqep_ex2_calculation.c”文件的Q格式代码的计算方面的问题

Part Number: TMS320F28335

您好,在学习eQEP模块关于电机位置和转速测量的官方示例文件时,“eqep_ex2_calculation.c”文件中部分代码的不理解,请各位大神帮忙指点一下:

//
temp = (int32_t)p->thetaRaw * (int32_t)p->mechScaler; // Q0 * Q26 = Q26
temp &= 0x03FFF000;

p->thetaMech = (int16_t)(temp >> 11); // Q26 -> Q15
p->thetaMech &= 0x7FFF;

//
// The following lines calculate p->elec_mech
//
p->thetaElec = p->polePairs * p->thetaMech; // Q0 * Q15 = Q15
p->thetaElec &= 0x7FFF;

//

我想询问:

第一个问题    temp = (int32_t)p->thetaRaw * (int32_t)p->mechScaler; // Q0 * Q26 = Q26 完成以后,temp是32位的,转成Q26格式后,应该是还有5位整数位数。“temp &= 0x03FFF000;”完成后,整数5位都被清零了。这个为什么?是运算后temp只有小数,没有整数了?

第二个问题     “p->thetaMech &= 0x7FFF;” 和 “p->thetaElec &= 0x7FFF;” 的作用是不是把符号位变成0,在与运算后只保留小数部分?为什么要这么做,意义何在?