Serial Comms and Crystals


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    looks like the dht11 only has a 8 bit range for rh an t so the display needs to be
    LCDOut $FE,$94,"rh ",#hum/100
    or
    LCDOut $FE,$94,"rh ",#dht[4]

    my fault I stopped reading the dht11 data sheet when I saw the 40 bit timings were the same as a dht22 , I have no dht11 to test with

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    just an observation but the fineoffset wh1081 weather station that I have uses a dht11 and its readings vary greatly from those of the dht22 right next to it . somehow I think the dht11 is not very accurate

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Guys thanks for your continued input.

    using the #hum/100 gives 87% as the value, which to me seems rather humid, especially when the indoor humidity according to my maplins weather station says it's 51%. As a comparison I tried the following code which uses the pause and pulsein statements to read the chip

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H  
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    
    '*******************************************************************************
    ' LCD (20 x 4) set up
    '*******************************************************************************
    
    DEFINE LCD_DREG  PORTB                  ' LCD Data port
    DEFINE LCD_DBIT  0                      ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB                  ' LCD Enable port
    DEFINE LCD_EBIT  5                      '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB                  ' LCD Register Select port
    DEFINE LCD_RSBIT 4                      '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4                      ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4                      ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000               ' Command delay time in us 
    DEFINE LCD_DATAUS 50                    ' Data delay time in us 
    
    '*******************************************************************************
    ' Defines Statements
    '*******************************************************************************
    
    DEFINE  OSC 20                          ' 18F4520 / 18F2520, 20mhz crystal
    ADCON1 = $0F
    clear    
    
    '*******************************************************************************
    'Analog and Comparator settings
    '*******************************************************************************
    
    ADCON0 = %00000000                      'AD converter module disabled
    ADCON1 = %00001111                      'All Digital
    ADCON2 = %00000000
    CMCON = 7                               'Disable Comparators
    
    '*******************************************************************************
    'Port and Register settings  (interrupts)
    '*******************************************************************************
        
    TRISA  = %00010111              
    TRISB  = %00000011               
    T0CON  = %11000111
    
    T1CON = %00000001                               ; free-running, 1:1 prescaler
    TMR1H = %11111111
    TMR1L = %11111011
    
    
    '*******************************************************************************
    
    LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
    
    '*******************************************************************************
    
    dht var byte[32]
    humidite var byte
    haut var byte
    bas var byte
    temp var byte
    x var byte
    dht11 var portA.1
    
    '*******************************************************************************
    start:
    TRISA.1 = 0 '
    high dht11
    pause 2000 ' wait 2 sec
    low dht11 : pause 18' send 20ms low
    high dht11 : pauseus 30 ' send 40us hi
    TRISA.1 = 0
    PulsIn PORTA.1, 1, haut
    if haut < 15 then goto start
    for x = 31 to 0 step-1
    PulsIn PORTA.1, 1, dht[x] ' 1
    next x
    For x = 31 to 0 step-1
    if dht(x)>=9 and dht(x)<=21 then dht(x)=0 'if pulsewidth between 20 and 40uS then read as '0'
    if dht(x)>=29 and dht(x)<=41 then dht(x)=1 'if pulsewidth between 60 and 80uS then read as '1'
    next x
    humidite=dht[31]*128+dht[30]*64+dht[29]*32+dht[28]*16+dht[27]*8+dht[26]*4+dht[25]*2+dht[24]*1
    temp=dht[15]*128+ dht[14]*64+dht[13]*32+dht[12]*16+dht[11]*8+dht[10]*4+dht[9]*2+dht[8]*1
    lcdout  $FE,1 
    lcdout  $FE,$C0,"Humidite = ",#humidite,"% "
    lcdout  $FE,$80,"Temperature = ",#temp,$DF,"C"
    goto start
    This gives 174c in our living room, with the humidity fluctuating between three values of 24%, 144% and 152%. Clearly there is something wrong with the hardware. I'm using a new solderless breadboard so I'll look at hard wiring the sensor and see if that helps, even though the connections between the Easypic board and sensor are next to each other

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Hummm

    Well I've now soldered the wires direct to the sensor, and plugged the wires directly into the header on the EasyPIC5 board.

    Dht(0) - 4 now reads 38 00 19 00 1F with a hum/256 value of 34.

    whilst this seems to of resolved the issues with the breadboard, 34% humidity seems rather low, and quite a gap from the 50% shown on the weatherstation

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Richard,

    I don't think #hum/100 will give the correct result.
    Since I. This example hum=8704 ($2200), 8704/100=87 ($57).

    The correct result should be 34 ($22).
    He just needs to use dht[4]
    Or
    To use a division calculation with hum it should be #hum/256.
    This will right shift 8704 ($2200) 8 bits resulting in 34 ($22).
    Regards,
    TABSoft

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Quote Originally Posted by Tabsoft View Post
    Richard,

    I don't think #hum/100 will give the correct result.
    Since I. This example hum=8704 ($2200), 8704/100=87 ($57).

    The correct result should be 34 ($22).
    He just needs to use dht[4]
    Or
    To use a division calculation with hum it should be #hum/256.
    This will right shift 8704 ($2200) 8 bits resulting in 34 ($22).
    Dividing hum by 256 gives a reading of 35 on the LCD. The values for dht(1) to (5) are 39 00 16 00 23

    I'm still not satisfied the sensor is working right, and this is the second one I've tried

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    brain fade due to lack of coffee divide 256 is of course correct

    attached the blue is a dht11 the red a dht22 in the same room
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    As Richard has stated, the DHT11 doesn't seem to be too accurate in his experience.

    As far as your readings go 39 00 16 23

    This is 35% RH and 22c Temp.

    Just use dht[4] for RH and dht[2] for Temp.
    Regards,
    TABSoft

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Thanks guys - I'll look at getting a DH22 as I need something more precise given that this will be monitoring the humidity in my snakes enclosure.

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Hi Richard,

    I was wondering if you could help me understand your use of Timer2 in this project during the read loop for the 40 bits from the DHT11.

    In this section of code.....
    " t2con=6
    while ( dht_data)
    wend
    t2con=0
    if ((tmr2>12)&&(tmr2<50)) then ' noise ?
    if (tmr2 >31 ) then
    dht.0[bits] = 1
    endif
    else
    goto badread ' noise ?
    endif"

    I see that Timer2 is turned on with the Prescaler set to 16.
    Then after the data line drops to 0, Timer2 is stopped.

    Then the TMR2 register is tested for its count value.
    If the count is less than 12 or greater than 50, then it's a bad read.
    Otherwise if the count is greater than 31 and less than 50 the bit is a 1.
    Is this correct?

    If the Fosc is 40Mhz and Timer2 counts at Fosc/4 and the Timer2 Prescaler is 16.
    Then
    Would the test "((tmr2>12)&&(tmr2<50))" equate to
    If count is greater than 19.2us and less than 80us?

    And then would the test "(tmr2 >31 )" equate to
    If count is greater than 49.6us?

    Which I think the test logic would translate to...
    If the count is less than 19.2us or greater than 80us then it's a bad read.
    Otherwise if the count is greater than 49.6us and less than 80us the bit is a 1.

    I think this is right, but please let me know if not.
    Just trying to understand how it is implemented.

    Thanks
    Regards,
    TABSoft

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Which I think the test logic would translate to...
    If the count is less than 19.2us or greater than 80us then it's a bad read.
    Otherwise if the count is greater than 49.6us and less than 80us the bit is a 1.
    that's it although a '0' is 26-28uS and a 1 is 70us according to the data sheet I have added some tolerance (this helps if interrupts are involved) if the count is outside this range then its not right and the process is abandoned , this test is not strictly necessary and could be omitted

    the 1/0 test is basically centered in between the 1 and the 0 times ie 50 is halfway between 30 and 70 once again to add some tolerance . if less than halfway its a 0 otherwise a 1


    there is some risk in this method in that hangs are possible if the dht responds in an unforseen manner . in my production version the tmrx int is enabled and if it is triggered then the process is also aborted to recover from such a sensor hang .

Similar Threads

  1. PC Serial comms
    By Bill Legge in forum Serial
    Replies: 7
    Last Post: - 13th December 2009, 23:37
  2. Simple Serial Comms.
    By koossa in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd November 2007, 08:12
  3. Some comments on serial comms please.
    By muddy0409 in forum Schematics
    Replies: 1
    Last Post: - 15th June 2007, 09:53
  4. Serial Comms Buffer?
    By koossa in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd December 2005, 01:29
  5. Serial comms / Bootloader
    By koossa in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 30th October 2005, 18:48

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