High Speed Oscillator question


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    51

    Default High Speed Oscillator question

    I never went beyond 4MHz before but want to find out about using the 20MHz Oscillator. I have few questions as they way I did it did not produced accurate results while simulating on proteus. I did the following:
    Code:
    DEFINE OSC 20  ' Added this define
    Under Config statement I used
    Code:
    _HS_OSC
    I tried the following code:
    Code:
    Main:
    Toggle LED
    Pause 1000
    Goto Main
    My LED did not blinked @ 1 sec interval but was a bit slower.
    --------------------------------------------------------------

    I also tried the similar settings with 8 MHz oscillator (I used _XT_OSC in Config this time & DEFINE OSC 8) and found out that my LED again was slightly slower than 1 Sec. So my question is-:

    A) Is there something I am missing to get timings right
    B) Just want to confirm that once DEFINE is added correctly, all pause statements and serial commands using baud rates are written as normal as the PIC automatically adjusts the timing.

    Thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: High Speed Oscillator question

    The DEFINE is correct but it doesn't mean that the PIC will RUN at 20MHz. What it does is tell the compiler at what speed you INTEND to run the PIC so that it (the compiler) can calculate the proper delays for things like PAUSE, SEROUT, DEBUG etc.

    It's up to you to make sure that the PIC actually gets a 20MHz clock to run from. In other words fit a 20MHz crystal etc. Now, since you're using a simulator there's probably a way to specify the clock frequency.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: High Speed Oscillator question

    Quote Originally Posted by Tina10 View Post
    I never went beyond 4MHz before but want to find out about using the 20MHz Oscillator. I have few questions as they way I did it did not produced accurate results while simulating on proteus. I did the following:
    Code:
    DEFINE OSC 20  ' Added this define
    Under Config statement I used
    Code:
    _HS_OSC
    I tried the following code:
    Code:
    Main:
    Toggle LED
    Pause 1000
    Goto Main
    My LED did not blinked @ 1 sec interval but was a bit slower.
    --------------------------------------------------------------

    I also tried the similar settings with 8 MHz oscillator (I used _XT_OSC in Config this time & DEFINE OSC 8) and found out that my LED again was slightly slower than 1 Sec. So my question is-:

    A) Is there something I am missing to get timings right
    B) Just want to confirm that once DEFINE is added correctly, all pause statements and serial commands using baud rates are written as normal as the PIC automatically adjusts the timing.

    Thanks
    Everything Heinrick posted is right, your code should be on for 1 second and off for 1 second (2 second cycle).The chip you use may have OSCON or other way to adjust the osc. PS always use HS_OSC if using 3 term resonators at any speed . . .
    Last edited by Archangel; - 9th July 2012 at 10:32.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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