Jump to content

Sign Extension for 13 bit to 16 bit number


bigjoepops

Recommended Posts

I am reading a 13 bit signed number out of an ADXL345.  It is contained in a high byte and a low byte.  I joined the two bytes into a UINT16, but for some reason I can't seem to find a way to get this number converted properly into a INT16.

 

I was trying the logical shift but that doesn't take care of it.  After I shift the number to the left by 3 bits, is there something else I need to use to shift it back but fill in the sign bit?  I searched this forum and the internet, but I couldn't seem to find a definite solution that worked.

 

Thanks for your help.

Link to comment

I am reading a 13 bit signed number out of an ADXL345.  It is contained in a high byte and a low byte.  I joined the two bytes into a UINT16, but for some reason I can't seem to find a way to get this number converted properly into a INT16.

 

I was trying the logical shift but that doesn't take care of it.  After I shift the number to the left by 3 bits, is there something else I need to use to shift it back but fill in the sign bit?  I searched this forum and the internet, but I couldn't seem to find a definite solution that worked.

 

Thanks for your help.

 

According to the spec

 

 

(13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement

 

13 bit is the resolution, not the data format.

 

If you want to get sense out of the raw 13 bit register, I think you will need to calculate it via the following formula if its not already done for you.

 

g = (register_value-4096) * 0.00390625

 

where the "register_value" is the UINT16 provided by your high and low bytes.

 

That should map the 13 bit register onto the +16 to -16 g range..

Edited by ShaunR
Link to comment

I was expecting the sign extension to work on the part but for some reason it isn't.  I have a call into Analog Devices to try to figure out why this isn't working right.  I was hoping to find a work around while I wait to see if Analog Devices comes up with a reason why it isn't working.  Ned thanks for your post.  It worked.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.