Announcement

Collapse
No announcement yet.

Internal Oscillator Setup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Internal Oscillator Setup

    Hi,

    I have a demo board with a PIC16F689 that has a long period timer, it was using a 4mhz oscillator, and was quite accurate.

    I changed the configuration settings on the PROGRAMMER to "Internal Oscillator" and the timing is no longer accurate, the error is about 4 x what it was.

    Having read the help on the website, do i need to DEFINE the settings?

    I.e. I understood the compiler would assume 4Mhz - do i need to use OSCCON to tell it?

    "As always the fix is in the datasheet. On most of the parts so equipped, set the OSCCON register to a value of $60 for 4MHz operation. This should be the first thing you do in your program."

    Also, should i be using the OSCTUNE / OSCCAL DEFINE, i noticed the programmer is set to "Erase before Program"?

    If i use OSCCAL is this reading the calibration value and then automatically adding it to my code?

    Thank you for any help.







  • #2
    Section 3.0 of the Data Sheet (page 47) covers the Oscillator circuit. Figure 3.1 shows all of the available options. Register 3.1 is your OSCCON Register. For 4 MHz Internal Oscillator:
    bits 6-4 must be 110
    bit 0 must be 1

    The OSCTUNE Register (Register 3.2 on page 52) allows minor tweaking to the Internal clock. Unless you know what you're doing, just leave it at the default = $00.

    As for CONFIG settings, refer to Register 14.1 on page 199. PBP will use the naming shown, not the bit settings. So for Internal Oscillator, you need:
    FOSC_INTOSCIO (100).

    Finally, at the top of your PBP program:
    DEFINE OSC 4

    The Data Sheet covers each PIC's unique features and ways of accomplishing things. The PBP Manual is written generically. You need to refer to the Data Sheet for each project you're working on to ensure the proper bits are set in the proper Registers, and often for proper nomenclature. Hope this helps.
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      Thank you mpgMike,

      So I must define the OSCCON to be 4Mhz, I had thought that PBP assumes this if it’s not defined?

      I am trying to understand why I would see such a big change in my timings. Over 12 hours I had around 2 minutes error with the resonator and 8 minutes with the internal oscillator.

      I know I can improve the error, but I first need to understand why such a big difference.

      I also now see the device does not have OSCCAL.

      thanks







      Comment


      • #4
        OSCCAL - OSCTUNE, different names for the same thing. Again, why referencing the Data Sheet is so important. Older PICs like the PIC16F689 you are using had sloppy Internal Oscillators. The newer ones are much more accurate. They will change with temperature. If you do the same experiment with a newer PIC16F18446, you will find the Internal Oscillator is much more precise. Oh, and you are NOT defining OSCCON with PBP, you are defining:

        DEFINE OSC 4
        We can crack this cotton PIC'n thang!

        Comment


        • #5
          The Internal Oscillator is enabled by one of two methods: Set the Fosc bits in a configuration register to select the internal oscillator. Set the SCS bits in the OSCCON register to select the internal oscillator. The OSC1 and OSC2 pins are available as general purpose I/O when the internal oscillator is selected.
          official site
          Last edited by Davidharris; 12-15-2022, 09:06 PM.

          Comment

          Working...
          X