Osctune


Closed Thread
Results 1 to 36 of 36

Thread: Osctune

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Osctune

    I can't seem to find any reference as to the range of the OSCTUNE register. That is, if I vary the value from 01111 to 10000, approximately how far does the frequency shift?

    My goal is to find the frequency error of a chip, calculate the correct OSCTUNE value in one step and write the new value.

    I realize that it won't be perfect. Close is good enough. I can try it myself tomorrow, but does anyone know the answer?
    Charles Linquist

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Now that I have had a chance to test it in the lab, I have an answer:

    First, I used an 18F8723 with

    OSCCON = $62 ; 4Mhz, INT osc.
    OSCTUNE.6 = 0 ; PLL disabled

    Adjusting OSCTUNE[4:0] from %01111 to %10000 changed the
    frequency from 4.507 Mhz to 3.440 Mhz.

    The change was nearly linear. With each count giving about .8% frequency change.
    Charles Linquist

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Charles

    4.5.2 OSCTUNE REGISTER
    The internal oscillator’s output has been calibrated at the
    factory but can be adjusted in the application. This is
    done by writing to the OSCTUNE register (Register 4-1).
    The tuning sensitivity is constant throughout the tuning
    range. The OSCTUNE register has a tuning range of
    ±12.5%.
    from the 16F88 Datasheet ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default how did you check the osc freq?

    Hey Charles,
    Nice work answering your own question

    Would you please explain how you tested the osc freq? Could you share your test code?

    I would like to learn more about this.

    I usually base my projects around the following 3 PIC's, as they share the same basic pinout...
    8pin - 12F683
    14pin - 16F688
    20pin - 16F690

    I would like to learn how to set/test the osctune register. I would also like to know how to read a new chip to view the osctune register as set from the factory.

    Thanks
    Dwight

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    These parameters vary from device to device - eg. while the 8723 has 5 frequency tuning bits, others (such as a 46K20) have 6 bits.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Alain, I guess some datasheets have more information than others. I haven't used any 16F parts for years, so I never considered looking there.

    Heckler, I used a frequency counter connected to CLKOUT.



    You can write to OSCTUNE at any time.

    In my case, I needed all devices to run very close to 4Mhz, so -

    After programming, the first thing the PIC (in my case, an 18F2221) looks for is for a pin to go low (the pin is connected to a pushbutton). A LED connected to another pin is flashed in a particular pattern. This indicates it is in the CALIBRATION mode.

    Another PIC (actually an 18F8722 development board used as a "calibrator") is connected to another pin on the 18F2221. The "calibrator" board sends out a precise 30ms low (using pulsout), followed by a 1 second high, followed by another 30ms low followed by a 1 second high....

    The '2221 looks for the 30ms low and times it, (using pulsin). If the pulse appears shorter or longer than 30ms to the '2221, it divides the difference by 24 and increments or decrements a variable and writes that variable both to the the OSCTUNE register and to EEPROM. The LED is flashed in a pattern that indicates calibration was successful. Another EEPROM cell is written with $AA to indicate the calibration process was successful. This cell is checked on power up. If it is $AA the entire calibration process is bypassed.

    On power up, the calibration value in the EEPROM is read and loaded into OSCTUNE.

    I have found very few '2221s that were more than 1% off. They are remarkably temperature-stable as well.



    On power up, the EEPROM
    Charles Linquist

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Heckler View Post

    Would you please explain how you tested the osc freq? Could you share your test code?

    I would like to learn more about this.

    I usually base my projects around the following 3 PIC's, as they share the same basic pinout...
    8pin - 12F683
    14pin - 16F688
    20pin - 16F690

    I would like to learn how to set/test the osctune register. I would also like to know how to read a new chip to view the osctune register as set from the factory.

    Thanks
    Dwight
    Hi, Dwight

    I do not think you can tune OSCTUNE without a good time reference in one hand ...

    What I do here is use my R/C set ... transmitter neutral is a precise 1500µs positive pulse ... and I also built a precise pulse meter ...

    so, I just use the PULSOUT command to output a 1500µs pulse and trim OSCTUNE to get the good value on the meter.
    Ok, I should write a small program and a board to make it automatically ( need 1 ref signal Pic, a thermostated enclosure ...etc,etc )... hoping I won't erase the EEPROM on the " live " programming !!!

    Alain

    PS: When leavin factory ... osctune is ... ZERO !!! ( see registers default values in the datasheet ... )
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    642


    Did you find this post helpful? Yes | No

    Default

    Charles,

    The next link might also be helpful for what you are doing. I thought about doing this oscillator calibration procedure for one of my projects, but since the chips come calibrated from the factory I gave up on the idea. Also, I didn't need that much accuracy.

    http://melabs.com/resources/articles/osccal.htm

    Robert

  9. #9
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The oscillators are close when they come from the factory, but I need 100% reliable communication at 19.2K baud, over the temperature range of -45 to 100C when running from a 4Mhz internal oscillator, and the supply voltage varying between 4.7 and 5.1V.

    Now you see why I'm interested in frequency stability and calibration!

    Amazingly, the 18F2221's (without calibration) are *usually* good enough to get this done.
    Charles Linquist

Members who have read this thread : 1

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