Serial Comms and Crystals


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    The code does include DT's INT file.

    I've found an indepth data sheet which states that each two way communication process should take 4ms, so why it seems that the code runs slow might of been down to the use of the wrong crystals ??

    Basically connection is via a single pin. This pin is kept high by pull up resistor. To get data, the PIC needs to make the pin go low for a minimum of 18ms then hight again and waits 20-40us for the response. The sensor then sends a response by taking the pin low for 80us and then back up high for a further 80us and then sends the data, which is a 40bit stream of high pulses with a duration of 20-28us to represent a 0 or 70us for a 1. Each pulse is preceded by a low pulse of 50us, with a final 50us low at the end of the data stream.

    I've seen examples using pulseIN command, with pause xxUS to trick the sensor into sending data, but don't know if interrupts could be used here ?

    here's the data sheet http://www.micropik.com/PDF/dht11.pdf

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals


  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    You could use an HIH 4030. It outputs a voltage that you read with the ADC - as fast as you like.

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Quote Originally Posted by richard View Post
    Thanks for the link. It states that it was for a 64mhz clock speed. Any idea what I need to change to make it run at 40 mhz ?

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,636


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    this should be close

    Code:
    if ((tmr6 <75)||(tmr6>85))then goto badread
    would become
    Code:
    if ((tmr6 <45)||(tmr6>55))then goto badread
    and
    Code:
    if ((tmr6>20)&&(tmr6<80)) then     ' noise ?
               if (tmr6 >50 ) then
    would become

    Code:
     if ((tmr6>12)&&(tmr6<50 then     ' noise ?
               if (tmr6 >31 ) then
    Last edited by richard; - 24th March 2015 at 10:47. Reason: and added

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Richard, thanks for the suggestions.

    I'm in the process of editing the code (to reflect the pins I'm using and that I don't have a serial LCD), and came up with an error, presumably as I'm using 2.60 version rather than PBP 3 related to tmr6 and t6con statements. Any ideas

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    pic 18F4580 has no timer6 try using tmr2 or rework the timer counts for timer3 with a 8:1 prescale

  8. #8
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Richard,

    need some additional help. The following code compiled, but displayed RH 0.0 and tmr 0 on the LCD. I changed the values for badread and noise as suggested, but still have the same result. As mentioned I'm using a 10 mhz crystal with HS_ppl enabled to run the pic at 40 Mhz. Could you point me in the right direction as to what I'm doing wrong ?

    Code:
    ; config settings 18F4580, 10mhz crystal HSPPL
    
    ASM  
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    DEFINE  OSC 40
    ADCON1 = $0F
    clear
    INCLUDE "alldigital.pbp"
    CMCON = 7 
    TRISA = %11001111
    
    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 
    
    ASM       
    hum          = _dht+3    
    tempa         = _dht+1
    ENDASM 
    
    T1CON = %00000001                               ; free-running, 1:1 prescaler
    
    dht_data var PORTA.1
    dht_dir var TRISA.1
    dht var byte[5]
    
    tempa var word EXT
    bits var byte
    crc   var byte
    hum  var word EXT 
    
    main:
    gosub read_dht
    LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10
    pause 4000
    goto main
        
    read_dht:
         for bits=4 to 0 step-1 
           dht[bits]=0 
         next
        
         tmr2=0
         dht_dir=0
         dht_data=0
         pauseus 1000                   'start it up
         dht_data=1
         pauseus 30
         dht_dir=1
         pauseus 40                    'wait till middle of response pulse window
         if ( dht_data)then goto badread   'no response then  give up
         while (!dht_data)
         wend 
         t2con=6
         while ( dht_data) 
         wend 
         t2con=0
         if ((tmr2 <75)||(tmr2>85))then goto badread      ' confirm presence ?
         for  bits =39 to 0  step -1
             tmr2=0
             while (!dht_data) 
             wend 
             t2con=6
             while ( dht_data) 
             wend 
             t2con=0
             if ((tmr2>20)&&(tmr2<80)) then     ' noise ?
               if (tmr2 >50 ) then
                  dht.0[bits] =  1 
               endif   
               
             else
              goto badread          ' noise ?
             endif
         next 
         crc=0 
         for bits=1 to 4         
           crc=crc+ dht[bits]
           
         next
         if crc !=  dht[0] then goto badcrc    'crc
    
    return
      
    badread:
    LCDOut $FE,$94 +8,"tmr6 ",#tmr2
        for bits=4 to 0 step-1 
           dht[bits]=0 
        next
    return
    badcrc:
        for bits=4 to 0 step-1 
    LCDOut $FE,$94 +16,hex dht[bits],"," 
        next  
    return

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