OSCON setting for 18F4520


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

    Default OSCON setting for 18F4520

    Hi all

    Just a quick question regarding the OSCON setting in an 18F4520 PIC

    Here are my settings currently
    Code:
    'Ocsillator selections here
    OSCCON = $70 'Int CLK 8MHz
    OSCTUNE.6 = 1 'PLL 4x
    ADCON1= %00001111 '$0F = disable A/D converter
    cmcon = 7
    INTCON2.7 = 0 'switch pull-ups ON
    'END of oscillator selections
    'timer/oscillator defines
    DEFINE OSC 32 '4x 8MHz
    'END of timer/oscillator defines
    I have read through the datasheet and undertstand how the internal clock works and the various clock settings and so forth...BUT ... what I can't make sense of or remember is why my OSCON value is $70 ..is this REVERSED HEX 70 as per the required register setting ?
    So binary would be 1110000 ?
    And if I wanted 4 MHz the setting would be $60 or 0110000 not so ?

    In the datasheet there is a bit to set internal clock as stable or not, ie 0 or 1 ..does anyone have a recommendation for that one ?

    Kind regards
    Dennis

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    DEFINE OSC 8
    OSCCON=%01110000

    or
    DEFINE OSC 4
    OSCCON=%01100000


    OSCTUNE.6 = 1 'PLL 4x
    does not do PLL. As far as I know PLL is not possible with the internal OSC.

    The other OSCON bits leave at zero, they are for reading.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    .... As far as I know PLL is not possible with the internal OSC.
    From the datasheet (DS39631A):
    2.5.2 PLL AND INTOSC
    The PLL is also available to the internal oscillator block
    in selected oscillator modes. In this configuration, the
    PLL is enabled in software and generates a clock output
    of up to 32 MHz.

    2.6.4 PLL IN INTOSC MODES
    The 4x frequency multiplier can be used with the internal
    oscillator block to produce faster device clock
    speeds than are normally possible with an internal
    oscillator. When enabled, the PLL produces a clock
    speed of up to 32 MHz.
    Unlike HSPLL mode, the PLL is controlled through
    software. The control bit, PLLEN (OSCTUNE<6>), is
    used to enable or disable its operation.

    The PLL is available when the device is configured to
    use the internal oscillator block as its primary clock
    source (FOSC3:FOSC0 = 1001 or 1000). Additionally,
    the PLL will only function when the selected output frequency
    is either 4 MHz or 8 MHz (OSCCON<6:4> = 111
    or 110). If both of these conditions are not met, the PLL
    is disabled.
    The PLLEN control bit is only functional in those internal
    oscillator modes where the PLL is available. In all
    other modes, it is forced to ‘0’ and is effectively
    unavailable.

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    I have read through the datasheet and undertstand how the internal clock works and the various clock settings and so forth...BUT ... what I can't make sense of or remember is why my OSCON value is $70 ..is this REVERSED HEX 70 as per the required register setting ?
    So binary would be 1110000 ?
    And if I wanted 4 MHz the setting would be $60 or 0110000 not so ?

    In the datasheet there is a bit to set internal clock as stable or not, ie 0 or 1 ..does anyone have a recommendation for that one ?
    Hello Dennis,

    $70 hex is 01110000 binary, and $60 hex is 01100000 binary, so yes I think you have got it. That would be 8mhz and 4mhz respectively.

    The stability bit is a read only bit. It tells you when the oscillator is stable again, as you could change your oscillator frequency in software.

    The PLL does work for internal oscillator. See section 2.6.4 of the data sheet.
    Last edited by ScaleRobotics; - 29th November 2009 at 05:14.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Thanks for the correction.
    The data sheet for the 18F4550 does not have the sections you referred to.
    DOH!!!

    Time to check my glasses...
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default so to clarify ...

    First of all thanks all of you for your replies, thoughts and guidance :-)

    All postings have raised a few questions though ...

    Code:
     DEFINE OSC 8
    OSCCON=%01110000
    or
    DEFINE OSC 4
    OSCCON=%01100000
    
    OSCTUNE.6 = 1 'PLL 4x
    So far we know ..according to the datasheet that PLL is only available if we run at 4MHz or 8MHz and the PLL bit is enabled.

    With this in mind, if your desired frequency is either 4 or 8 MHz , you probably want to make sure that OSCTUNE.6=0 since this would disable the PLL setting.
    So the above code settings for 4 or 8MHz would be as follows
    Code:
     DEFINE OSC 8
    OSCCON=%01110000
    or
    DEFINE OSC 4
    OSCCON=%01100000
    
    OSCTUNE.6 = 0 'PLL Multiplier disabled
    And thats as per this in the datasheet
    Unlike HSPLL mode, the PLL is controlled through
    software. The control bit, PLLEN (OSCTUNE<6>), is
    used to enable or disable its operation.
    The PLL is available when the device is configured to
    use the internal oscillator block as its primary clock
    source (FOSC3:FOSC0 = 1001 or 1000). Additionally,
    the PLL will only function when the selected output fre-
    quency is either 4MHz or 8MHz (OSCCON<6:4> = 111
    or 110). If both of these conditions are not met, the PLL
    s disabled.
    The PLLEN control bit is only functional in those inter-
    nal oscillator modes where the PLL is available. In all
    other modes, it is forced to ‘0’ and is effectively
    unavailable.
    Am I correct ?
    Kind regards
    Dennis

  7. #7


    Did you find this post helpful? Yes | No

    Default hmm...?

    Just another thought..

    Can you achieve 20MHz then ?

    Can the PLL multiplier be altered to achieve 20MHz maybe ?

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    The PLL multiplyer will multiply x4 whatever your OSCILLATOR is running at. There are no other options... it's either x4 or OFF.

    You need a 5MHz Crystal or Resonator if you want 20MHz using the PLL Multiplier.

    The Internal Oscillator does not have 5MHz as one of it's selectable options (neither does it have 20MHz).

    So if you WANT 20MHz, you'll need a 20MHz Xtal or Resonator, use HS Mode and have the PLL multiplier OFF (or 5MHz Xtal or Resonator, HS Mode and have the PLL multiplyer ON).

    Section 2, Datasheet DS39631A explains it in great detail (for the 18F4520 chip) which you said you were using at the start of this thread.

  9. #9


    Did you find this post helpful? Yes | No

    Default got it !

    Thank Melanie and everyone else who replied to this thread !

    It is all CRYSTAL CLEAR now !!
    :-)

    Thank a million

Similar Threads

  1. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 14:01
  2. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  3. code size VS speed optimization setting?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2008, 14:38
  4. Setting up the oscillator
    By J_norrie in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd October 2007, 14:53
  5. Help with setting adcon1 for 16f877
    By jessey in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th August 2005, 11:13

Members who have read this thread : 2

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