logo image - link to home page

Products | Support | Resources | PurchaseContact  | Basket  | Checkout

  Home
  What's New
  Products
  Distributors
  Purchasing Info
  Developer Resources
  Support
  Upgrades
  Site Index
  Contact Us
  Pb-Free Info (RoHS)
 

 

keyword search:
 


 

Home:
  Developer Resources:

Programming Help
    Sample Programs
    Search the
PICBASIC™ List
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Help
    PICmicro® MCU
Selection Guide
    PIC16F62x Datasheet
    PIC16F84A Datasheet
    PIC16F87x Datasheet
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     

 Other Resources
    MicroCode Studio
IDE for Windows
    melabs Loader
HEX files
    Links to other sites

Using the oscillator calibration factor on devices with internal RC oscillators


When Microchip ships devices with an internal oscillator, they store an oscillator calibration factor in the last location of code space.  You can use this data to calibrate the internal oscillator to exactly 4MHz.

To calibrate manually, you first have to read the data from the new device.  This must be done before you erase the device, because erasure will destroy the stored data.

To read the calibration factor, you'll need some method of reading the code space in the device.  A device programmer like our EPIC™ Programmer is the best thing to use.  The rest of this document assumes that you have an EPIC programmer. 

Insert the new device into the socket on the programmer and select the device part number from the drop down list on the toolbar.  Click the read button on the toolbar or select Read from the program menu.

To view the code space as read from the device, select Code from the view menu.  Scroll down to the very last location in the code space window to find the calibration factor.  The value will be shown as a 4-digit hexadecimal number.  You only need the 2 rightmost digits.

In your source code, you will need to write the calibration factor value to the OSCCAL register.  A typical PICBASIC PRO statement is:

OSCCAL = $C0


Using DEFINEs to automate

If you are programming new parts that have not been erased, you can automate this process with a PICBASIC PRO define.  The compiler will insert code at the beginning of your program that reads the calibration factor and writes it to the OSCCAL register.  This method will only work with new, never-erased devices.

For devices with 1K of code space:

DEFINE OSCCAL_1K    1

For devices with 2K of code space:

DEFINE OSCCAL_2K    1

Add one of these 2 DEFINEs near the beginning of the PICBASIC PRO program to perform the setting of OSCCAL.

PICBASIC PRO will automatically load the OSCCAL value for the PIC12C5xx and 12CE51x devices , if it is available. It is unnecessary to use the above DEFINEs with these devices.

If a UV erasable device has been erased, the value cannot be read from memory. If one of these DEFINEs is used on an erased part, it will cause the program to loop endlessly. 

Calibration is only necessary when you need precise timing from you PICmicro®, as for serial communication.

 

Copyright 2008
microEngineering Labs, Inc.
Box 60039
Colorado Springs CO 80960
(719) 520-5323
(719) 520-1867 fax
email: support@melabs.com

Last Updated: 08/04/2008

Home | What's New | Products | Support
Resources
| Purchase | Index Contact

PIC, PICmicro, dsPIC, and  MPLAB are registered trademarks of Microchip Technology Inc. in the USA and other countries.  PICBASIC, PICBASIC PRO, PICPROTO, and EPIC are trademarks of Microchip Technology Inc. in the USA and other countries.   BASIC Stamp is a trademark of Parallax, Inc.

Microchip third-party partner  Microchip Consultant Program Member