I am using ADXL345 to calculate the various g values. I was not able to clearly find any idea for calculating the G values.
I am planning to use +-16 G range in 10 bit mode. the data is right justified.
here i was not able to figure out the sign extension option.
The code used to calculate the value from the ADXl registers is
x0 = read_i2c_reg(0x32); //x0 read
x1 = read_i2c_reg(0x33); //x1 read
xx = (x0 + ((xx | x1)<<8)); // add to form a 16 bit value
xx = (~(xx-1)) & 0x3ff ;// 2's complement and get 10 bit value
now the above calculated value xx is used to get the g value as explained below.
I suppose for max resolution 10 bits, the maximum value is 1023.
now for -16g to +16g.
at 0g the value should be 1023/2 = 511
if value is greater then 511 then (value - 511)/31.2 = g
if value is less then 511 then value/31.2 = g
Please confirm the above calculations and let me know if i am doing it the right way.
Thanks and Regards.