Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ranges of values #8

Closed
tcurdt opened this issue Feb 27, 2023 · 2 comments
Closed

ranges of values #8

tcurdt opened this issue Feb 27, 2023 · 2 comments

Comments

@tcurdt
Copy link

tcurdt commented Feb 27, 2023

Thanks for the library!

What would be great for the docs to mention the min and max values.
I guess for ADXL345_RANGE_8G it would be -8G/+8G (for example).

The range of the raw values are not quite so obvious.
From the code it looks like 16bit values.

rawVal.x = (static_cast<int16_t>((rawData[1] << 8) | rawData[0])) * 1.0;
corrRawVal.x = rawVal.x * 1.0 - (offsetVal.x / rangeFactor);
gVal.x = corrVal.x * MILLI_G_PER_LSB * rangeFactor * corrFact.x / 1000.0;

So by default it should be which could be calculated backwards per range factor.

rx = (gx * 1000.0 / (MILLI_G_PER_LSB * rangeFactor * corrFactx) + offsetValx) / rangeFactor

Does that make sense?

@wollewald
Copy link
Owner

Hi @tcurdt ,

the ADXL345 has two different modes, the fixed 10-bit resolution mode and the full resolution mode. In full resolution mode one bit is always 3.9 milli-g (=MILLI_G_PER_LSB). In this mode the range of raw values depends on the range you choose:

2g: 10 bits of the data registers are used, from -2^9 to + 2^9 - 1
4g: 11 bits of the data registers are used, from -2^10 to + 2^10 - 1
8g: 12 bits of the data registers are used, from -2^11 to + 2^11 - 1
16g: 13 bits of the data registers are used, from -2^12 to + 2^12 -1

In the fixed 10-t resolution the range of raw values is 10-bit for all g-ranges. This means that 2^9 -1 in the 2g range equals +2g (1,9929 g, to be exact). In 4g range it is +4g and so on.

With setFullRes(true/false) you can switch between the modes. If true, the rangeFactor is always 1, if false 1, 2, 4 or 8 to consider changing g per bit.

I am not going to write all this into the cpp or h files. I have documented this in the examples of this library and I am explaining this also in my blog posts which are related to this library (see readme).

@tcurdt
Copy link
Author

tcurdt commented Feb 28, 2023

Thanks for the explanation!

@tcurdt tcurdt closed this as completed Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants