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

adafruit_ads1x15.Analogin - correct ADC scaling to 16-bit range to match analogio.AnalogIn #43 #92

Open
kevinjwalters opened this issue Jul 1, 2023 · 3 comments

Comments

@kevinjwalters
Copy link

kevinjwalters commented Jul 1, 2023

The change in adafruit/circuitpython#4794 (raised by @PaintYourDragon) which appeared in CircuitPython 8 scales values to the full 16 bit range for analogio.AnalogIn.

The current implementation of analog_in.AnalogIn has the old behaviour for the ADS1015 of zero padding to signed 16bit for the 12bit values.

This is part of the same ecosystem, should this be brought into line with the aforementioned full-scaling change? Same issue raised in adafruit/Adafruit_CircuitPython_MCP3xxx#43

@kevinjwalters
Copy link
Author

There's also a question here about the unsigned nature of the values. Users of analogio.AnalogIn are accumstomed to the 16 bit unsigned range between 0-65535. I've only just started reading about the TI ADS in detail but they appear to effectively be 15bit ADCs (ignoring noise) when making single ended measurements? The values align with this and the code does too

volts = self.value * _ADS1X15_PGA_RANGE[self._ads.gain] / 32767

The value property will return -32767 (or -32768??) to 32767. This has a lot of potential to confuse users coming from CircuitPython's analogio.AnalogIn world unless they are using the voltage property.

@kevinjwalters
Copy link
Author

kevinjwalters commented Jul 2, 2023

And for single-ended use there's a question here as to whether a floor of 0 should be applied to the values as the ADS1115 can return negative value when measuring 0V. I've experienced this myself. Unexpected negative values can cause havoc.

I don't know the origins of it but, for comparison, I noticed the nRF52 code has this in AnalogIn

    if (value < 0) {
        value = 0;
    }

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Dec 5, 2024

I think maybe this was resolved in: #98 although it wasn't the primary purpose of that PR.

There is now code here:

# Need to bit shift if value is only 12-bits
value <<= 16 - self._ads.bits

and here:

# Need to bit shift if value is only 12-bits
value_int >>= 16 - self._ads.bits
volts = value_int * lsb

Which seems to handle this if I am understanding correctly.

@kevinjwalters can you confirm whether these bits of code are resolving the original issue documented here?

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