Math for dunce...


Results 1 to 6 of 6

Threaded View

  1. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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...
    Code:
        Sign = TempC.15
        TempC = ABS(TempC)
        TempC = ((TempC >> 4)*100) + ((TempC & $F)*100 >> 4)
        IF Sign THEN TempC = -TempC
    That gives you a Signed Word with 2 decimal places.
    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 ...
    Code:
    DisplayTemp:
        IF TempC.15 THEN LCDOUT "-"
        LCDOUT DEC ABS TempC/100,".", DEC2 ABS TempC,13,10
    RETURN
    To compare the Temp with your hysteresis range, you just subtract the values.
    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.
    Code:
    Compare:
        Diff = (tref + Hyst) - TempC
        Over = Diff.15
    
        Diff = TempC - (tref - Hyst)
        Under = Diff.15
    RETURN
    Over and Under are BIT vars, so you can test them later in the program to activate alarms or whatever.

    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.
    Attached Files Attached Files
    DT

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts