Code of TMS320F28335 CCS4v120DSP2833x_exampleseqep_pos_speedExample_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为什么要这样进行位操作,请解释一下,多谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>