使用CCS读取位置&;使用编码器的电机速度。请解释以下语法
请用C语言解释以下语法 语法-变量名称&=0xFFF(十六进制值) 代码如下所示使用CCS读取位置&;使用编码器的电机速度。请解释以下语法,c,pointers,syntax,encoder,C,Pointers,Syntax,Encoder,请用C语言解释以下语法 语法-变量名称&=0xFFF(十六进制值) 代码如下所示 // The following lines calculate // // p->thetaMech ~= QPOSCNT / mechScaler [current cnt/(total cnt in 1 rev)] // // where mechScaler = 4000 cnts/revolution // temp = (int32_t)p->thetaRaw * (int32_t)p-&g
// The following lines calculate
//
// p->thetaMech ~= QPOSCNT / mechScaler [current cnt/(total cnt in 1 rev)]
//
// where mechScaler = 4000 cnts/revolution
//
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;
@TomKarzes完全正确。作为补充资料。
和
是按位和
运算符。简单地说,在二进制形式中添加2个值
,两个都有位1的位置保持为1,在所有其他情况下,它变为0。例如:
Bitwise AND &
11001000 // decimal: 200 hexadecimal: 0xC8
& 10111000 // decimal: 184 hexadecimal: 0xB8
--------
= 10001000 // result decimal: 136 hexadecimal: 0x88
C中的
op=
运算符使用左侧作为赋值目标和相应操作的第一个操作数。例如,a+=2代码>相当于a=a+2代码>。在您的例子中,a&=b代码>相当于a=a&b代码>