Oscillator setup


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2024
    Posts
    6

    Default Oscillator setup

    Hi guys,

    I’m trying to setup the internal oscillator for a 18F2580 mcu at 32Mhz using PLL but I have a few basic questions and just wanted to make sure I get it right…
    As I can read from the datasheet, I need to set the config bit, osccon and osctune (and obviously define the OSC in the code).

    For the config I used:
    Code:
    #CONFIG
    CONFIG OSC = IRCIO67 ; Internal oscillator block, port function on RA6 and RA7
    .
    .
    .
    #ENDCONFIG
    For osctune I selected the following bits (not real code format):
    OSCTUNE.6=1 -> enable PLL
    OSCTUNE 4-0=00000 -> Center frequency

    For osccon I selected the following bits (not real code format):
    OSCCON 6-4=111 -> select 8Mhz
    OSCCON.7=0 -> Sleep when sleep command

    However, for the osccon and osctune I have the following doubts…

    OSCCON bits 1-0:
    What is the difference between 1x=Internal oscillator block and 00=Primary oscillator?

    OSCCON bit 2:
    INTOSC frequency is stable or not stable…should I set this to 0?

    OSCCON bit 3:
    Should I set to 0 or 1?

    OSCTUNE bit 7:
    What is the difference between the 2 options?
    “1 = 31.25 kHz device clock derived from 8 MHz INTOSC source (divide-by-256 enabled)
    0 = 31 kHz device clock derived directly from INTRC internal oscillator”

    Thanks

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


    Did you find this post helpful? Yes | No

    Default Re: Oscillator setup

    Hi,
    Kudos for actually reading the datasheet!

    Your CONFIG looks allright for selecting the internal oscillator.

    [quote]
    However, for the osccon and osctune I have the following doubts…

    OSCCON bits 1-0:
    What is the difference between 1x=Internal oscillator block and 00=Primary oscillator?
    [quote]
    Look at figure 3-8 in the datasheet. There they show the primary oscillator as the one interfaced to OSC1/OSC2 pins of the PIC. Then again, in the text they say that "The primary oscillators include the external crystal and resonator modes, the external RC modes, the external clock modes and the internal oscillator block".

    OSCCON bit 2:
    INTOSC frequency is stable or not stable…should I set this to 0?
    No. This is a read-only bit indicating if the frequency is stable or not.
    If you look above the bit definition in the datasheet you'll see something like [R/W-1] or [ R-0 ]. The first means that bit is Read/Write and its default value is '1'. The second means that it's a read-only bit and its default value is 0.

    OSCCON bit 3:
    Should I set to 0 or 1?
    Same as above. Status bit for you to read (if you need to) but you can't write to it.

    OSCTUNE bit 7:
    What is the difference between the 2 options?
    “1 = 31.25 kHz device clock derived from 8 MHz INTOSC source (divide-by-256 enabled)
    0 = 31 kHz device clock derived directly from INTRC internal oscillator”
    Again, look at figure 3-8. You can see that the 31kHz into the MUX can come from either the internal oscillator block OR from the (low power) RC oscillator.
    If you want a real low power solution and run at 31kHz you'd do that by shutting down the power hungry (relatively speaking) internal 8MHz oscillator and tap of the 31kHz from the RC oscillator. If you're not going to run the PIC at 31kHz it doesn't matter.

    Hope that helps.
    /Henrik.

  3. #3
    Join Date
    Aug 2011
    Posts
    439


    Did you find this post helpful? Yes | No

    Default Re: Oscillator setup

    OSCCON bits 1-0:
    What is the difference between 1x=Internal oscillator block and 00=Primary oscillator?
    This can be confusing the way they word this.
    The 'primary oscillator' is the one selected by the 'config' setting.

  4. #4
    Join Date
    Jul 2024
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Oscillator setup

    Greetings,

    HenrikOlsson and tumbleweed thank you so much for your help.

    I think I have a better understanding of these settings with your help.
    I also found this:
    8-bit PIC® MCU Clock Switching - Developer Help (microchip.com)

    I
    n there they also say

    Code:
    When the SCS bits = 00, the system clock is switched to the clock source selected by the Fosc bits in the Configuration Register. This can be the Internal Oscillator, External Crystal/Resonator, or External Clock.When the SCS bits = 01, the system clock is switched to the Secondary Oscillator which is an external 32.768 Khz crystal that controls the Timer1 Peripheral. The external clock crystal is an optional clock source that must be part of the Timer1 design circuit.
    When the SCS bits = 10 or 11, then the system clock is switched to the Internal Oscillator independent of the Fosc configuration bit settings. The IRCF bits of the OSCCON register will select the internal oscillator frequency.
    This makes me believe that, if we have the internal osc setup in the FOSC<2:0>, the result will be the same if I select any of the 2 options:

    "1x = Internal oscillator block" or "00 = Primary oscillator"

    Am I right?

Similar Threads

  1. PIC16F777 - setup
    By orjon1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd June 2011, 20:17
  2. Using PIC16F88 oscillator as oscillator for other ICs
    By Torael_7 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 30th March 2008, 12:58
  3. ADCIN setup help need
    By dangill in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th February 2008, 15:22
  4. LCD setup
    By ruijc in forum General
    Replies: 11
    Last Post: - 19th November 2007, 09:04
  5. How to setup Bootloader
    By koossa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th January 2006, 19:52

Members who have read this thread : 11

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