LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ADXL345: Convert 16-bit Twos Complement to 10-bit Signed Int

Solved!
Go to solution

Hi All:

I was hoping I could find some sample code on how to convert data from an ADXL345 accelerometer.  I am reading acceleration data from an accelerometer through a PIC MCU into a LabView program on my laptop.  The data from the sensor is formatted in two bytes, say axDataLO and axDataHI, forming a 16-bit twos-complement value.  This value represents the result of a 10-bit ADC that is right justified with sign extension.  If I am clear, the sign exension means that the last 6 bits are padded with either a 1 or 0 depending on the sign of the data.  How do I convert this data into a signed integer?  Any help is greatly appreciated!  Thanks.

Message 1 of 10
(7,763 Views)

Hi,

 

this probably has been asked before, but anyway:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(7,762 Views)
Solution
Accepted by topic author jcalusdi

Hi GerdW,

Thanks for your reply.  Yes, that was what I needed, as well as, fixing a bug in the code of my PIC microcontroller.  I have included a code snippet here in case someone out there is working with the ADXL345. Thanks again for your help.  V/R James C.

 

Picture1.png

Message 3 of 10
(7,735 Views)

Hi jcalusdi,

 

another try:

check.png

The array(U8) should contain your 6 bytes delivered by the ADC...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 10
(7,723 Views)

Thank you, again.  James C

0 Kudos
Message 5 of 10
(7,718 Views)

Awesome code! Just what I was looking for. Thanks!

Edgar Cabrera
Certified LabVIEW Associate Developer
0 Kudos
Message 6 of 10
(7,510 Views)

Hi all. Could I know why the input of "Join Numbers" are crossed? Thanks for the answer.

Regards.

0 Kudos
Message 7 of 10
(6,969 Views)

Hi Corci,

 

read on Wikipedia about big or little endian(ness)...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 10
(6,967 Views)

Thank You for the rapid answer. I've read online documentation about Little and Big Endian. How do I relate the information on the datasheets of the ADXL345 with this concept? Does "Left-Justified" means Big Endian?

Thanks again. Regards.

0 Kudos
Message 9 of 10
(6,958 Views)

Hi Corci,

 

the endianness dictats which of those two bytes contains the MSB and the LSB. You have to connect the correct byte to the high and low input of JoinNumbers...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(6,938 Views)