PID thermostat Issue


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PID thermostat Issue

    Yes, both programs work independently. The second section of code just proves the DHT sensor works, the code above it is the main program that uses a DS18B20 sensor. I would like to use the DHT sensor in place of the 18B20 so that it's temperature data can be used to work with the PID routine. The problem is that the two sensors use different one wire protocol as far as I can tell, and that's what I am asking for help with.

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: PID thermostat Issue

    Okay.
    It looks like the routines you want to use the data in are in the Include files..

    Do you want to provide the whole thing so we can see if we can help?
    Regards,
    TABSoft

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: PID thermostat Issue

    Hi,
    I've never used the DS18B20 or the DHT11.
    Looking at the datasheet for the DS18B20 it seems like it returns the temperature in units of 0.1 degrees. Ie, if the returned value is 325 the actual temperature is 32.5C.
    The DHT11 claims a resoultion of 8 bits and 1 degree but it still seems to send 16 bits of temperature data where the low byte is the decimal part (which I guess will always be 0).

    Anyway, if you want to use the DHT11 instead of the DS18B20 what you want to do is make sure to scale the raw value so that they both give you the same value at a certain temperature. They might already DO that but you need to verify it. In the DS18B20 code your raw value seems to be the TempC variable while in the DHT11 code it's the temp variable.

    At a known temperature (roughly) run the 18B20 code and output the TempC variable on the LCD. What does it say? Something like 225 for 22.5 degrees?
    At the same temperarure (roughly) run the DHT11 code and output the Temp variable on the LCD. What does it say? Something like 220 for 22.5 degrees? Or something else?

    If they are the same (roughly) then you're good to go as is. Otherwise you need to scale the DHT11 value so it gives the same result as the DS18B20 code for any given temperature (or you need to retune the PID filter).

    With that said that DHT11 code looks REALLY convoluted, especially the highlighted part.

    I wrote the following, not saying it'll work, have no sensor here to verify with.
    Code:
    PulsWidth VAR BYTE
    BitValue VAR BIT
    
    Humidity VAR WORD
    Temperature VAR WORD
    Checksum VAR BYTE
    
    
    Main:
      GOSUB ReadDHT11
      LCDOUT $FE, 1, "RH: ", DEC Humidity, "%"
      LCDOUT $FE, $C0, "Temp: ", DEC Temperature, "c"
      PAUSE 1000
    Goto Main
    
    
    ReadDHT11:
      ' DHT11 reference: http://www.micropik.com/PDF/dht11.pdf
      ' Datasheet says resolution is 8 bits yet it sends 16 bits
      ' of data. This might be legacy from the higher resolution
      ' DHT22 sensor and the lower byte (the decimal part) is
      ' probably 0 all the time. No sensor here to verify with
      ' and datasheet is typical Chinese cut'n'paste stuff....
    
      ' Add the starbit stuff here !
    
      ' Read 16 bits of humidity data
      FOR x = 15 to 0 step - 1
        GOSUB GetBit
        Humidity.0[x] = BitValue
      NEXT x
    
      ' Read 16 bits of temperature data
      FOR x = 15 to 0 step - 1
        GOSUB GetBit
        Temperature.0[x] = BitValue
      NEXT x
    
      ' Read 8 bits of checksum data
      FOR x = 7 to 0 step - 1
        GOSUB GetBit
        Checksum.0[x] = BitValue
      NEXT x
    
      ' Checksum is the 8 bit sum of the 4 databytes
      ' this could be calculated and verified against
      ' the recieved checksum here.
    RETURN
    
    GetBit:
      PulsIn PORTA.5, 1, PulsWidth
      IF PulsWidth >=  9 AND PulsWidth <= 21 THEN BitValue = 0   ' if pulsewidth between 20 and 40uS then read as '0'
      IF PulsWidth >= 29 AND PulsWidth <= 21 THEN BitValue = 1   ' if pulsewidth between 60 and 80uS then read as '1'
    RETURN
    /Henrik.

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PID thermostat Issue

    Quote Originally Posted by HenrikOlsson View Post

    Anyway, if you want to use the DHT11 instead of the DS18B20 what you want to do is make sure to scale the raw value so that they both give you the same value at a certain temperature. They might already DO that but you need to verify it. In the DS18B20 code your raw value seems to be the TempC variable while in the DHT11 code it's the temp variable.

    At a known temperature (roughly) run the 18B20 code and output the TempC variable on the LCD. What does it say? Something like 225 for 22.5 degrees?
    At the same temperature (roughly) run the DHT11 code and output the Temp variable on the LCD. What does it say? Something like 220 for 22.5 degrees? Or something else?

    /Henrik.
    Hi Henrik,

    I've merged the two sections of code for some crude testing (I'll try you refined version for the DTH sensor later). Yes you are correct in that the DS18B20 results are stored in the variable TempC and the result is a three digit value as you summarized - ie 234 would be 23.4 degreed C. The DHT does the same, but the value for the result is in double figures - I've changed the variable for the result of reading the DHT to TempB.

    Reading the values from the LCD using
    Code:
    lcdout  $FE,$C0,#tempb,"  ",#tempc
    I'm getting 19 for tempb (DTH sensor) and 205 (18B20 sensor) for tempc. I'm guessing that the DS18B20 is more accurate given the two sensors are side by side. I'm guessing if I multiply tempb by ten this should then in theory work - which it did.

    I'll play about with the code, but at least I've now got something to work with

Similar Threads

  1. DS18B20 thermostat
    By snuff28 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th April 2013, 14:19
  2. 4 Channel Thermostat using PID loops
    By malc-c in forum Code Examples
    Replies: 36
    Last Post: - 18th March 2013, 10:17
  3. Thermostat for refrigerator
    By fratello in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th August 2012, 22:58
  4. Thermostat
    By koossa in forum Off Topic
    Replies: 15
    Last Post: - 16th November 2010, 10:06
  5. Pulse proportional thermostat
    By malc-c in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th December 2009, 02:00

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