Code of TMS320F28335 CCS4\v120\DSP2833x_examples\eqep_pos_speed\Example_posspeed.c文件中有这么一段是计算机械角度的:
pos16bval=(unsigned int)EQep1Regs.QPOSCNT; // capture position once per QA/QB period
p->theta_raw = pos16bval+ p->cal_angle; // raw theta = current pos. + ang. offset from QA
// The following lines calculate p->theta_mech ~= QPOSCNT/mech_scaler [current cnt/(total cnt in 1 rev.)]
// where mech_scaler = 4000 cnts/revolution
1 tmp = (long)((long)p->theta_raw*(long)p->mech_scaler); // Q0*Q26 = Q26
2 tmp &= 0x03FFF000;
3 p->theta_mech = (int)(tmp>>11); // Q26 -> Q15
4 p->theta_mech &= 0x7FFF;
1~4为什么要这样进行位操作,请解释一下,多谢! |