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.

TM4C123GH6PM: Typecasting in rotary enoder

Part Number: TM4C123GH6PM

Hi working with interfacing rotary encoder with tm4c123gh6pm..

I have successfully captured the encoder  pulse  and stored in a variable whose data type is unsigned.( i am getting only positive values)

Now can i do typecasting ..and store the data in another signed variable. so that i can get the negative values as well....if i do typecasting i am aware that the range will reduce by half as compare to unsigned

MY concern is will i miss the pulses when i do type casting .

  • Hi,

    Now can i do typecasting ..and store the data in another signed variable. so that i can get the negative values as well....if i do typecasting i am aware that the range will reduce by half as compare to unsigned

    MY concern is will i miss the pulses when i do type casting .

    The QEI module does not know how you process the data by typecasting or not. However, the QEICOUNT register which stores the pulses is a 32bit register. If you typecast to another signed variable then you will lose the value stored in MSB. If you capture  a larger count value that sets  bit 31 high then you will lose it after you typecast. However, I doubt you will ever capture a value that is large enough to set bit 31 high. You need to find out if your application will ever capture such a large value. If not, you are fine to typecast. If yes, you should not typecast.