element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Pic Microcontrollers Forum [PIC18F25K20] Internal oscillator
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 195 subscribers
  • Views 849 views
  • Users 0 members are here
Related

[PIC18F25K20] Internal oscillator

Former Member
Former Member over 15 years ago
Can enybody help me, how to configure inrernal oscillator to 16 MHz ?
  • Sign in to reply
  • Cancel
Parents
  • KennyMillar
    KennyMillar over 15 years ago

    Certainly :-)

     

    First you need to set certain bits in the CONFIG registers - normally you do this in your compiler or programmer:

    Primary oscillator modes are set with the FOSC 0:3 bits of the CONFIG1H register - with these bits you can choose to use the internal oscillator, and have RA6 and RA7 as general purpose IO or as a clock output.

     

    Then you need to set bits in the OSCCON (Oscillator Control) register - you can set these bits at runtime in code.

    The internal High Frequency oscillator runs at 16Mhz, so you want to select the HF internal oscillator and set bits 4,5 & 6 of OSCCON all to 1 to use it without a divisor.

    See page 29 of the Data sheet for more details of the OSCCON register.

     

    See page 41 of data sheet for a full description of all the registers involved in setting the oscillator speed and options.

     

    Since these registers also contain bits for other functions, it's not possible for me to just say sat CONFIG1H to this and OSCCON to that in order to get 16 Mhz.

     

    But the steps are:

    Set CONFIG1H to select the internal HF oscillator

    and then set bits 4,5 & 6 of OSCCON to 111 to select 16Mhz.

     

    The other bits of these registers will need to be set in accordance with your other requirements.

    The data sheet can be found here.

     

    I hope this has helped.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • JohnDSiviter
    JohnDSiviter over 14 years ago in reply to KennyMillar

    Question, if the PIC has been set to 64Mhz and then you put this in main:

     

    while(1)

    {

    PORTD=0xFF;

    Nop();

    Nop();

    PORTD=0x00;

    }

     

    what is the port d frequency?, I am getting just under 4Mhz?

     

    If I make FOSC=INTIO7, then I can see a 16Mhz squarewave (abeit a poor one) or RCA-6, is the HSPLL only for external crystals, or can it be set for the internal clock as well?

     

    Also has anyone got an example of I2C communication?, I believe I am setting it up correctly, but if I try and send a byte, I can see diddly squat on the I2C pins (SCL for example).

     

    Also is it possible to change the configuration bits implicitly, such as FOSC = 0b1001 (this does not work btw), rather than by assigned variable (INTIO67, INTIO7, HSPLL etc).

     

    John.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 14 years ago in reply to JohnDSiviter

    Hi,

     

    If the PIC has been set to 64Mhz then the PORTD frequency is about 2,6MHz (1/ (375 ns x 6 instruction)) or 1/(62,5e-9*6)= 2,6MHz

     

    Do you no that PIC18F25K20 do not have PORTD ?

     

    Arnauld

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • JohnDSiviter
    JohnDSiviter over 14 years ago in reply to Former Member
    Hi sorry posted out of context I know these are similar to the one I am using PIC18F45K20-I/MLPIC18F45K20-I/ML, did you get the 375ns from the datasheet?, ok I can see 6 instructions in total, 4 within the While loop and 2 hidden (thats why I had to include 2 Nop()'s in the on time due to the 2 instruction delays caused by the loop back to the start of the while loop).
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • JohnDSiviter
    JohnDSiviter over 14 years ago in reply to Former Member
    Hi sorry posted out of context I know these are similar to the one I am using PIC18F45K20-I/MLPIC18F45K20-I/ML, did you get the 375ns from the datasheet?, ok I can see 6 instructions in total, 4 within the While loop and 2 hidden (thats why I had to include 2 Nop()'s in the on time due to the 2 instruction delays caused by the loop back to the start of the while loop).
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • Former Member
    Former Member over 14 years ago in reply to JohnDSiviter

    A simple example simulation : choose the correct value of the clock frequency in Debugger Settings > Osc/Trace

     

        imageimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube