Settings for internal oscillator


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2009
    Posts
    16

    Default Settings for internal oscillator

    How do i setup the internal oscillator?
    I know i can use command "DEFINE OSC 4 (for 4mhz)".
    And also in the *.inc file at PBP folder. Somthing like this:
    Code:
    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L 
    __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H

  2. #2
    Join Date
    Jan 2009
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    This would be found on the datasheet for the chip that you are working with. It will vary from chip to chip. All pic datasheets can be downloaded in PDF form from microchip.

    Look in the index for the section called "Special Features". It will list all of those configurations (fuses) for your chip, and how they are used.

    Then at the top of your PIC Basic code, use a line similar to this:

    "@ device hs_OSC, wdt_on, pwrt_on, protect_off" (You "can" make the modifications in the '16Fxxx.inc' include file, but that will be a change for all projects, instead of just this one)

    For setting the speed, use a define statement in your code...

    DEFINE OSC 4

    Again, check datasheets for correct syntax and that it works for your chip.

    Cheers!

    SmugWimp

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


    Did you find this post helpful? Yes | No

    Default

    You will find files in the MPASM Suite subdirectory of the Microchip directory on your C: something like P16f648A.inc . Open the one for the chip you are using (do not change anything here ) and you will find all the configuration fuse settings for that chip ( that MPASM USES ) PM will use the same fuses but may spell the names a little differently, and will likely use different syntax.
    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.

  4. #4
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    It is my understanding that DEFINE OSC actually does nothing to configure the PIC's oscillator; it is used by PBP to correct time-dependent commands (PAUSE would be an example). It's also my understanding that PBP assumes 4 MHz as a default value, so a DEFINE is necessary only if a different oscillator speed is used.

    To configure the internal oscillator, see the section of the data sheet entitled "Oscillator Module" or "Oscillator Configuration" or the equivalent. Recently, I've done stuff with the 12F683, the 16F628A/648A, the 16F877A, and the 16F88. Of these, three have internal oscillators and two have a register, OSCCON, to load to configure the oscillator.

    For example, to use the 12F683 with its internal oscillator running at 4 MHz, I have to load that register with the statement: OSCCON=%01100000 (or $60--I've never tried decimal 96).
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Actually, on the 12F683 I use the following code and it defaults to 4MHZ

    DEFINE OSCCON_1K 1
    @ DEVICE MCLR_ON, INTRC_OSC_NOCLKOUT, WDT_ON, BOD_OFF, PWRT_ON, PROTECT_ON

    On the 16F819 & 16F88 I use this, otherwise it defaults to the slowest speed (I think 32KHZ)
    OSCCON = $60 'set int osc to 4mhz

  6. #6
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by peterdeco1 View Post

    DEFINE OSCCON_1K 1
    This is a new one for me. Can you tell me more about it?--syntax and such--or direct me to more information?

    And, yeah, I discovered the default-to-32 kHz thing the hard way.

    Thanks!
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It's a new one for everyone I guess

    You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    It's a new one for everyone I guess

    You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.
    Yes, now that you mention it. I find it in my new manual on pp. 12 and 202.

    (My old manual is the one with all the handwritten notes in it!)

    But I find the explanation on p. 12 mysterious.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Code:
     Originally Posted by mister_e  
    It's a new one for everyone I guess 
    
    You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.
    When I use DEFINE OSCCAL_1K, generates errors. "Error C:\PBP\PBPPIC14.LIB 7448:[225] Undefined Symbol 'OSCCAL'

    The only way I don't get an error is:
    DEFINE OSCCON_1K 1 ' Set OSCCON for 1K device

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    peterdeco1,
    if you have this error message it indeed mean that your particular PIC doesn't have the OSCCAL register.

    12F683 have an OSCCON register indeed, and it's directly accessible through your code. Some also have OSCTUNE register, this one is to tweak the internal oscillator in case you need to do so. But still, this one is also directly accessible in code and no need for DEFINEs.

    DEFINE can be everything, if it's not built-in in the compiler instruction set or the spelling (Case) is wrong, it will just do nothing, hence why we already discussed about their spelling.

    DEFINE MarryHadAlittleBoy_HisNameIsJerry 1

    will not return any error, and obviously it will not do anything unless you use it in ASM. This is handy when you want to customized your INCLUDE/Library or feature of your program. Check my Keypad routine for example.
    Last edited by mister_e; - 10th February 2009 at 19:02.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Yes Steve. I did see the Osctune in the datasheet, but haven't played with it yet. I'm using the HPWM in the 12F683 and it's dead-on accurate the way it is. I'm a great believer in "If it works, don't fix it." Besides, Osctune may make me pull more hair out! Thanks.

Similar Threads

  1. PBP and 18F2550
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 15th January 2012, 06:34
  2. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  3. Oscillator Troubles
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th December 2007, 17:15
  4. Advice please - Warning message
    By malc-c in forum mel PIC BASIC Pro
    Replies: 50
    Last Post: - 23rd January 2007, 13:20
  5. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41

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