max31865
max31865 copied to clipboard
Wrong initialisation of polynom
Version
No response
Describe the bug
Hi there,
First of all, thank you very much for your work and for making the source code available as open source – this is by no means a given and is greatly appreciated.
While using your library, I noticed that the initialization of the polynomial in the function a_max31865_temperature_conversion() may not be based on the normalized resistance value. Specifically, the polynomial is assigned the raw rt value already during declaration (float rpoly = rt;). As a result, for negative temperatures – starting from an rt of approximately 8191 down to 0 – incorrect negative temperature values are calculated.
The current code looks like this:
rt *= 100; /* normalize to 100 ohm */
temp = -242.02f; /* -242.02 */
temp += 2.2228f * rpoly; /* add offset */
From my point of view, rpoly should only be initialized after rt has been normalized, for example:
rt *= 100; /* normalize to 100 ohm */
rpoly = rt; /* use normalized value for polynomial */
temp = -242.02f; /* -242.02 */
temp += 2.2228f * rpoly; /* add offset */
Of course, it's possible that I may have overlooked something – but I still wanted to share this observation in case it’s helpful for further development of the library.
Best regards, Martin
Reproduce
No response
Expected behavior
No response
Additional context
No response
Thank you very much. Your analysis is completely correct. We have fixed this bug. You can pull again or download the v1.0.5 driver. Thank you for your help to make LibDriver do better.