-
Notifications
You must be signed in to change notification settings - Fork 17
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
Bit shifting isn't correct #2
Comments
I believe the unused bits end up as zeros (data sheet shows zeros for CJ, X's for Thermocouple temp), and since I'm scaling based on a known LSB I think our results should come out the same. Your method is more explicit, mine might be quicker (one less operation). I'll look into the data sheet to confirm, and then I'll update the code to your method (since the code is Python and readability will trump speed). I'm traveling this week so it might not be til next that I update the code. Thanks for using the library, and for commenting. It's always good to know that the work gets used! JR |
I finally had a chance to check this, turns out my understanding was wrong. I've got some code below showing the differences between your (correct) suggestion, and my prior understanding. I'm adjusting the code now to have the proper bit shifting, and then will close the issue. Thanks for bringing this to my attention, JR Python interpreter, Thermocouple Demo:
For Cold Junction temperature:
|
The bit shifting does not strip the unused bits from the low byte in the internal or external temp functions.
In readTempC(), this
temp_bytes = ( ((val_high_byte & 0x7F) << 11) + (val_mid_byte << 3) + val_low_byte )
should be
#put the bytes together
temp_bytes = ( ((val_high_byte & 0x7F) << 16) + (val_mid_byte << 8) + val_low_byte)
#Ignore the 5 least significant bits
temp_bytes = temp_bytes >> 5
A similar correction is needed in readInternalTempC() to ignore the 2 least significant bits
BTW, thank you for creating this library. It accelerated my use of the MAX31856 on the Pi.
The text was updated successfully, but these errors were encountered: