Not really sure what all is going on in your program fratello.
So let me just show what I would do.
First ... It takes 750mS from the time you start a conversion till you can read the results.
You can just put a pause after the Convert command [$CC, $44], to wait till it's done.
Or you can Poll the DS18B20's busy bit.
Once you have the reading from the DS18B20, it can be converted like this...That gives you a Signed Word with 2 decimal places.Code:Sign = TempC.15 TempC = ABS(TempC) TempC = ((TempC >> 4)*100) + ((TempC & $F)*100 >> 4) IF Sign THEN TempC = -TempC
25.00 °C would have the value 2500.
-10.00 °C would be -1000.
It will work with the full temperature range of the sensor -55°C to +125°C.
You can display it on an LCD with this ...To compare the Temp with your hysteresis range, you just subtract the values.Code:DisplayTemp: IF TempC.15 THEN LCDOUT "-" LCDOUT DEC ABS TempC/100,".", DEC2 ABS TempC,13,10 RETURN
If the value being subtracted is larger than the other one, the result will be negative.
So, just testing for the sign bit tells you if it's above or below the setpoints.
Over and Under are BIT vars, so you can test them later in the program to activate alarms or whatever.Code:Compare: Diff = (tref + Hyst) - TempC Over = Diff.15 Diff = TempC - (tref - Hyst) Under = Diff.15 RETURN
Keep in mind that with 12-bit resolution, each step of the DS18B20's reading is 0.0625°C.
So incrementing the hyst. 0.05°C won't always give the expected Hyst. range.
It'll be close, but not perfect.
Test program attached.




Bookmarks