This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BOOSTXL-POSMGR: T-format encoder functions

Part Number: BOOSTXL-POSMGR

Hi experts,

When I was doing the experiment about the encoder, I couldn't understand the meaning of some TI codes, mainly including PM_tformat_receiveData () function and tformat_getBits () function.

The main questions are as follows:

1.What is the role of bitIndex and wordNo in these functions;

2. How to interpret 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);
}            

  • 1.What is the role of bitIndex and wordNo in these functions;

    2. How to interpret tformat_getBits ()

    Hello,

    tformat_getBits is a helper function that extracts bits out of the received data array (tformatData.rdata).  You can find the source for this function in the library source file: pm_tformat_source.c

    • wordNo indicates which word of the array
    • bitIndex indicates which bit to start with in that word
    • len is the number of bits to extract

    Best regards

    Lori

  • Hello,

    If I want to change TI's 17 bit example to my own 23 bit encoder code, how should I change?Besides the two functions mentioned above, what else needs to be changed?

    In addition, why wordNo=1 and bitIndex=13 in some DFS (DF0 DF1 DF2 DF3 DF7 DF8 DFC), but in DD and D6 there is a difference.

    Best regards

    Johnson Alanl

  • Hello,

    If I want to change TI's 17 bit example to my own 23 bit encoder code, how should I change?Besides the two functions mentioned above, what else needs to be changed?

    It should work as expected without change to either function.  Looking at the code that extracts the position and turns none of it is dependent on the number of resolution bits. 

    In addition, why wordNo=1 and bitIndex=13 in some DFS (DF0 DF1 DF2 DF3 DF7 DF8 DFC), but in DD and D6 there is a difference

    The answer would be in the specification for the encoder.  I'll have to review the code and spec and get back to you.  I will respond back by end of Thursday US time. 

    Best Regards,

    Lori

  • Lori,

    Thank you very much for your patient guidance.

    I think it is necessary to modify the code, because I found that when I used the 17-bit encoder, the position information of the rotor of my motor kept changing as I rotated the motor shaft. After I stopped rotating the motor shaft, the data in the display bar would stop (such experimental results are normal in my opinion).But when I use the 23 bit encoder, the position information displayed keeps changing even if I stop turning the motor shaft.

  • Thank you for the additional information.  Normally we would have such information in (1) the design guide instructions for running the example and (2) In the library header file a #define related to the number of bits.  I don't see either in this case. 

    I did note in the test report table in the design guide, the engineer did test with a 24 bit encoder TS5702N40.  (note the table has the bit resolution swapped for the two encoders - I will report this to be corrected).  

    I will keep investigating, but don't see anything obvious to change at this point.  I will check and see if we have an encoder in our lab with a different resolution and respond back. 

    Regards

    Lori 

  • Hello, 

    I compared the specification for a 17-bit t-format encoder against a 24 bit t-format encoder.  In the specification the data fields are the same (total of 24 bits).  It is only which bits are always zero and which bits are valid.  This matches with the code, in the t-format example, that extracts the position/turns as it masks off all but 24 bits.   

      

  • Lori,

    Thank you for your reply again.In fact, I don't see library header file a #define related to the number of bits in this case,and that's where I'm confused.

    I did note in the test report table in the design guide, the engineer did test with a 24 bit encoder TS5702N40.  (note the table has the bit resolution swapped for the two encoders - I will report this to be corrected).  

    Since both the 17-bit encoder and the 24-bit encoder can be used smoothly, my 23-bit encoder should also pass the experiment smoothly.But unfortunately, the results of the current experiment are not ideal.Maybe I'm still looking for something else.

    In addition, does the 24bit encoder test mentioned above also use 17bit code? Please help confirm it here, thank you!

    Regards

    Johnson Alanl

  • In addition, does the 24bit encoder test mentioned above also use 17bit code? Please help confirm it here, thank you!

    The test mentioned in the design guide are done following the instructions in the design guide.  If there was a change for bit resolution it should have been mentioned in those instructions. 

  • Thank you for your reply.Maybe something's wrong somewhere else.

    Regards

    Johnson Alanl

  • Lori,

    Thank you very much for your patient guidance.I'd like to share my findings with you.

    I think it is necessary to modify the code, because I found that when I used the 17-bit encoder, the position information of the rotor of my motor kept changing as I rotated the motor shaft. After I stopped rotating the motor shaft, the data in the display bar would stop (such experimental results are normal in my opinion).But when I use the 23 bit encoder, the position information displayed keeps changing even if I stop turning the motor shaft.

    The reason why the data on the display bar is still changing when the motor shaft stops rotating has been found.The main reason is that the technical parameters of the encoder, although marked as 23-bit resolution, are actually lower than 23-bit resolution (maybe the actual resolution is only 21-bit or even lower), resulting in small changes in data.

    in addition,I also have some questions to ask in another post, if you have spare time, please help to guide again.Thank you!

    e2e.ti.com/.../3821219

    Regards

    Johnson Alanl

  • Thank you for the feedback. 

    The reason why the data on the display bar is still changing when the motor shaft stops rotating has been found.

    If I understand, no changes to the t-format library were required.

    It sounds like the issue is resolved.  I will go ahead and close this thread.  If that is not the case, please respond back with details and the thread will re-open.  

    Best Regards

    Lori