A question on defining the external oscillator


Closed Thread
Results 1 to 4 of 4
  1. #1

    Question A question on defining the external oscillator

    Hi all:

    I have a question regarding how I define a HS oscillator. The first three lines of code are as follows

    @ DEVICE PIC16F870, HS_OSC
    INCLUDE "alldigital.INC"

    DEFINE OSC 20


    Now - - The program works exactly as I wish, unless I add the DEFINE OSC 20 line -then it seems to revert back to 4 MHZ....
    If I omit the DEFINE statement, it works perfectly at the higher speed.

    I am using a 20MHZ Resonator, since accuracy is not important in this application.

    I guess I don't care, since it works as I hope without the DEFINE, I just am confused why the DEFINE OSC 20 statement would cause it to run slower.

    Ken

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    All the DEFINE HS_OSC does is instruct the PIC to drive the Xtal or Resonator harder. As the frequency goes above 4MHz the xtals/resonators require increased drive. This doesn't mean that you HAVE to use XT_OSC at 4MHz and below. If you have multiple PICs connected to one Xtal for example, you may find that the additional loading requires the Master PIC to drive the Xtal at HS_OSC even if it is 4MHz.

    Now the question is how fast is your PIC actually running?

    The DEFINE OSC 20 tells PICBASIC that you've got a 20MHz circuit and to slow down it's internal timing accordingly - so TIME critical commands like PAUSE, SERIN, SEROUT etc work properly.

    Do an experiment, Blink an LED at 1Hz with a simple program...

    LED var PortB.1
    Loop:
    High LED
    Pause 500
    Low LED
    Pause 500
    Goto Loop

    Compare it against your wristwatch... is it 1Hz WITH or WITHOUT the Define OSC 20 statement?

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Melanie

    Yes, what you suggested is what I did initially to find that adding DEFINE OSC 20 changed the timing on a blinking LED (using some PAUSE statements) back to what it was at 4 MHZ.

    I guess I should have looked at page 172 of the manual a little closer.

    From that I gather then, only the "timing - related" commands will operate at basically a 4MHX clock rate, - and everything will be faster by a factor of 5 ..

    I need the extra speed to get through a lot of IF-THEN statements faster.

    Thanks

    Ken

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Yes you are correct. Only Timing Critical commands will be brought back into line (eg PAUSE, PAUSEUS etc) in order to operate correctly (not nescessarilly to operate at 4Mhz but to operate CORRECTLY at your processor speed). All others will be quicker x500%.

Similar Threads

  1. First time with external oscillator - 16F877a Not working
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 15th October 2009, 17:14
  2. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. How to use an external oscillator
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th February 2008, 14:19
  5. External oscillator and startup
    By RussMartin in forum General
    Replies: 4
    Last Post: - 17th March 2007, 01:53

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