Part Number:BOOSTXL-POSMGROther Parts Discussed in Thread:C2000WARE
TI工程师,
您好!TI的例程中有关于多摩川的绝对值编码器的程序,可是是17位的,其路径为D:\ti\c2000\C2000Ware_MotorControl_SDK_3_01_00_00\libraries\position_sensing\tformat。如果我想用在自己的23位编码器(通过对比两者通讯协议发现,与TI例程17位编码器相比,通讯协议是一致的,仅仅是位数存在差异)上面,需要进行修改。所以有以下问题需要咨询:
1.TI例程中的PM_tformat_receiveData () 和tformat_getBits ()函数中的参数bitIndex和 wordNo是什么意思?
2.tformat_getBits ()函数该怎么去理解?
uint16_t PM_tformat_receiveData(uint16_t tformatDataID) {uint32_t len, bitIndex, wordNo;uint16_t word1;word1 = 1;switch(tformatDataID){case (PM_TFORMAT_DATAID2):len = 8;bitIndex = 13;wordNo = 1;tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;tformatData.crc = tformat_getBits (len, wordNo, bitIndex); } uint32_t tformat_getBits (uint16_t len, uint16_t wordNo, uint16_t bitIndex) {uint32_t shift0, shift1, shift2, mask0, mask1, mask2;uint32_t temp32;shift2 = (len > (16 + bitIndex) ) ? (32 - len + bitIndex): 32;shift1 = (len > (16 + bitIndex) ) ? (16 - shift2) : (len > bitIndex ) ?(16 - len + bitIndex): 32;shift0 = (len > (16 + bitIndex) ) ? (16 + shift1) : (len > bitIndex ) ?(16 - shift1): (bitIndex - len);mask2 = (len > (16 + bitIndex) ) ? 0xFFFFFFFF : 0;mask1 = (len > bitIndex ) ? 0xFFFFFFFF : 0;mask0 = (len > bitIndex )? ((1 << bitIndex) - 1): ((1 << len) - 1) ;temp32 = (len > (16 + bitIndex) ) ? (((tformatData.rdata[wordNo + 2] &mask2) >> shift2) | ((tformatData.rdata[wordNo + 1] & mask1)<< shift1) | ((tformatData.rdata[wordNo] & mask0) << shift0)): (len > bitIndex ) ? (((tformatData.rdata[wordNo + 1] & mask1)>> shift1) | ((tformatData.rdata[wordNo] & mask0) << shift0)): ((tformatData.rdata[wordNo] >> shift0) & mask0) ;return(temp32); }
3.假如我想把TI 17位的例程改为自己23位编码器的程序,除了上述所涉及到两个函数,还需要修改哪些地方?
以上,请TI工程师帮忙回答一下,谢谢!
Green Deng:
你好,问题1可以参考一下这个帖子:e2e.ti.com/…/boostxl-posmgr-t-format-encoder-functions
至于更改为23位编码器,程序需要做哪些修改,我会在这两天确认一下之后回复你
,
futian jishu:
好的,感谢您的耐心指导。期待您的回复
,
Green Deng:
客气了,会需要点时间,还请耐心等待哈
,
Green Deng:
你好,上面那个E2E帖子是你发的吗?好像他问的问题跟你问的一样啊,你可以去帖子里面看一下。
,
futian jishu:
好的,我再看看。谢谢!