// 计算机械角度: p->theta_mech ~= QPOSCNT/mech_scaler [current cnt/(total cnt in 1 rev.)]
// where mech_scaler = 4000 cnts/revolution
//p->theta_mech ~= QPOSCNT/4000
pos16bval=(unsigned int)EQep1Regs.QPOSCNT;
p->theta_raw = pos16bval+ p->cal_angle;
tmp = (long)((long)p->theta_raw*(long)p->mech_scaler); // Q0*Q26 = Q26
tmp &= 0x03FFF000;
p->theta_mech = (int)(tmp>>11); // Q26 -> Q15
p->theta_mech &= 0x7FFF;
按公式不是除法计算吗,为什么先乘法运算,后又相与,再移位,请高手解释一下,多谢! |