Serial Comms and Crystals


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Hi,
    The fact that you're using a 12MHz x-tal and DEFINE OSC 48 tells me that you're using the PLL in the chip to increase the frequency from 12 to 48MHz. This by itself seems a bit strange since the maximum operating frequency of the 18F4580 is 40MHz so if you really ARE running at 48MHz you're operating the chip outside of it specifications.

    Dropping in a 20MHz x-tal instead of the 12MHz means the PIC is trying to run at 80MHz - twice as fast as it's maximum rated speed.

    If it really does use a 12MHz x-tal with the PLL enabled - thus running at 48MHz - and it's doing it reliably then that is as fast as you're going to get.

    If it's actually running at 12MHz then what you want is to drop in a 10MHz x-tal and enable the PLL. Then you DEFINE OSC 40.

    Please remember that DEFINE OSC never ever changes the speed which the PIC runs at. It only informs the compiler what speed YOU intend to run the PIC at.

    /Henrik.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Cheers Henrik,

    10Mhz xtal, OSC set to 40 with HS PPL in the config and it works fine. I thought I was possibly on the right track, but didn't realise that I was in effect overclocking the PIC using the 12 and 20 Mhz crystals.

    Now to look for a cheap I2C humidity sensor. The DTH11 that I was playing with uses pause statements which slow the rest of the code down.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals

    Quote Originally Posted by Scampy View Post
    ...

    Now to look for a cheap I2C humidity sensor. The DTH11 that I was playing with uses pause statements which slow the rest of the code down.
    Don't you mean "you" use PAUSE in your code? (I'm not familiar with that sensor)

    You could use DT INT instead to generate an interval.

    Robert

  4. #4
    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

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


    Did you find this post helpful? Yes | No

    Default Re: Serial Comms and Crystals


  6. #6
    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.

  7. #7
    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 ?

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    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 11:47. Reason: and added

Similar Threads

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

Members who have read this thread : 1

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