How to use 24Bit data (variable)

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

How to use 24Bit data (variable)

Post by stefan.erni »

Hi Ben

I read from a Ad-Converter a 24bit Value with a SPI Bus in a Byte Array.
I suspect I can not process this in 24 bits so I have to reduce it to a 16 bit value (signed int).

Are there commands similar to make16 () in FC too?


from the data_pdf
********************************************************************

The device provides 24 bits of data in binary twos complement format. The size of one code (LSB) is calculated
using Equation 8.
1 LSB = (2 × VREF / Gain) / 224 = +FS / 223 (8)
A positive full-scale input produces an output code of 7FFFFFh and the negative full-scale input produces an
output code of 800000h. The output clips at these codes for signals exceeding full-scale. Table 9 summarizes the
ideal output codes for different input signals. All 24 bits toggle when the analog input is at positive or negative
full-scale.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: How to use 24Bit data (variable)

Post by LeighM »

You can get the 16 bit signed value by reading the two most significant bytes from the byte array (MSB,NSB,LSB)

Code: Select all

SINT16 = MSB << 8
SINT16 = SINT16 | NSB

Post Reply