ME Labs, Inc. 719-520-5323 |
Using the oscillator calibration factor on devices with internal RC oscillatorsWhen 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.
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.
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 2019 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|