Osctune


Closed Thread
Results 1 to 36 of 36

Thread: Osctune

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

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


    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 " !!!
    *****************************************

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    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

  6. #6
    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

  7. #7
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    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.
    Why not use the AUTO-BAUD RATE DETECT feature - no calibration needed and automatic compensation for temperature/voltage variations? Also works with other oscillator modes (XT, HS, EC) besides IntOSC and high baud rates - I use it with speeds up to 230,400 baud.
    Last edited by rmteo; - 3rd April 2010 at 17:45.

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


    Did you find this post helpful? Yes | No

    Default

    I see what you mean. I have never used that feature before. Time to try it!
    Charles Linquist

  9. #9
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    I see what you mean. I have never used that feature before. Time to try it!
    Another neat thing about this feature is that you do not have to set a fixed baud rate in your firmware. I have used it (with IntOSC) to communicate at any standard speed from 2,400 to 230,400 baud. Auto-Baud detect is only available on devices that have an EUSART - most PIC18s (and some PIC16s) do.

  10. #10
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    So what you were looking for was not really to calibrate it, but to reduce the inherent error that occurs when using a close-enough (but not exact source) for the BAUD generator. This makes more sense (since the Oscillators are trimmed at the factory for 8MHz, before they leave the factory).

    Note that 4MHz gives you 0.16% error on the 19,200 BAUD generator. On the other hand, 3.9936MHz is right on. So maybe this was the answer you were looking for through experimentation.

Members who have read this thread : 0

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