Skip to content

Handling of negative pixel temperature values is incorrect #15

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

Closed
peterhinch opened this issue May 20, 2019 · 3 comments
Closed

Handling of negative pixel temperature values is incorrect #15

peterhinch opened this issue May 20, 2019 · 3 comments

Comments

@peterhinch
Copy link
Contributor

The _signed_12bit_to_float function is correct for thermistor temperature readings which are in sign bit/absolute data format (datasheet page 13).

However datasheet page 14 indicates that pixel values are in two's complement format. This requires different handling.

I have no hardware (yet) so am not in a position to offer a tested PR.

@peterhinch
Copy link
Contributor Author

On further review there is also an error in _signed_12bit_to_float which will fail to handle negative thermistor temperatures. It should read

def _signed_12bit_to_float(val):
    #take first 11 bits as absolute val
    abs_val = (val & 0x7FF)
    if val & 0x800:
        return 0 - float(abs_val)
    return float(abs_val)

i.e. the test for negative should be 0x800 not 0x8000.

@peterhinch
Copy link
Contributor Author

A further bug - which won't have effect because sleep mode is currently unused - is

_SLEEP_MODE = const(0x01)

The value should be 0x10 (datasheet page 9).

ladyada added a commit that referenced this issue May 22, 2019
Fixes for temperature conversion bugs issue #15.
@ladyada
Copy link
Member

ladyada commented May 22, 2019

huzzah! thank you @peterhinch :)

@ladyada ladyada closed this as completed May 22, 2019
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