bigjoepops Posted September 3, 2014 Report Share Posted September 3, 2014 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. Quote Link to comment
ShaunR Posted September 3, 2014 Report Share Posted September 3, 2014 (edited) 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 September 4, 2014 by ShaunR Quote Link to comment
ned Posted September 4, 2014 Report Share Posted September 4, 2014 Shaun's probably right, but in case you do need to sign-extend, one approach is this: http://forums.ni.com/t5/LabVIEW/24bit-hex-to-2-s-complement/m-p/1686050#M599007 1 Quote Link to comment
bigjoepops Posted September 4, 2014 Author Report Share Posted September 4, 2014 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.