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

Temperature calculation is wrong when using a DS18S20 sensor. #5375

Closed
wecl opened this issue Mar 1, 2019 · 3 comments
Closed

Temperature calculation is wrong when using a DS18S20 sensor. #5375

wecl opened this issue Mar 1, 2019 · 3 comments
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended

Comments

@wecl
Copy link

wecl commented Mar 1, 2019

see below

@netpok
Copy link

netpok commented Mar 1, 2019

Please fill out the form above, especially the parts about your problem.

@wecl
Copy link
Author

wecl commented Mar 1, 2019

To Reproduce
connected a DS18S20 sensor to GPIO14 to a yunshan module and record a time series.

Expected behavior
smooth change of temperature over time.

actual faulty behaviour
when temperature is in- or decreasing the calculated temperature is jumping suddenly about 0.5 degrees at some point in time.

what i did
I looked to the sourcecode of the file xsns_05_ds18x20.ino, function Ds18x20Read() and compared the calculation with the spec of the DS18S20 sensor (https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf).
On page 6 they describe as follow:
"Resolutions greater than 9 bits can be calculated using the data from the temperature, COUNT REMAIN and COUNT PER °C registers in the scratchpad. Note that the COUNT PER °C register is hard-wired to 16 (10h). After reading the scratchpad, the TEMP_READ value is obtained by truncating the 0.5°C bit (bit 0) from the temperature data (see Figure 4)..."

On line 332 of xsns_05_ds18x20.ino, the code fragment
if (data[0] & 1) { temp9 = ((data[0] >> 1) + 0.5) * sign; } else { temp9 = (data[0] >> 1) * sign; }
should be replaced by

temp9 = (data[0] >> 1) * sign;
because it is wrong to add 0.5 in case of calculating resolution greater than 9 bit.

I changed the code accordingly and tested it on my module and the output is as expected.
But i didn't test the calculation when the temperature is lower than 0 degrees.

@arendst arendst added the bug Type - Confirmated Bug label Mar 2, 2019
arendst added a commit that referenced this issue Mar 2, 2019
Fix DS18S20 temperature calculation (#5375)
@arendst arendst added the fixed Result - The work on the issue has ended label Mar 2, 2019
@ascillato2
Copy link
Collaborator

Closing this issue as it has been fixed.

Support Information

See Wiki for more information.
See Chat for more user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type - Confirmated Bug fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

4 participants