Internal Oscillator Recalibration Utility for PIC12F629
The PIC 12F629 and 12F675 devices have an internal 4Mhz oscillator that enables the devices to be used without an external crystal or RC network. This frees up one or two pins for I/O use and allows the device to be built into minimum component count designs.
The internal oscillator needs to be calibrated and this is achieved by reading a factory programmed calibration setting and writing it into the OSCCAL register during initialisation of the device by the application software.
The calibration word is located at the last address in the user program memory area, address 0x3FF. It is in the form of a RETLW instruction and the user code should include a CALL 0x3FF instruction which will return with the calibration setting in the W register. This can then be written into the OSSCAL register.
Problems arise if by accident or otherwise, the program memory at address 0x3FF is erased or over written. Since the calibration value is unique to each individual PIC there is no way to know what it was, but it is possible to recover it by recalibrating against a known frequency.
That’s where this software and circuit come into their own. Load a PIC with the code on this page and drop it into the circuit described here and within a couple of seconds it will provide a new calibration value to ensure the internal oscillator runs within 1% of 4Mhz.
PICkit 2 update
If you have a PICkit 2 programmer, get version 2.50 (or later) software from the Microchip website. This includes a menu option to recalibrate and reprogram the OSSCAL setting in one operation. This project page remains here for those who don’t have access to a PICkit2.
How it works
In order to calibrate the internal oscillator a known reference frequency is needed. Fortunately we don’t need signal generators or calibrated test equipment for this. In fact an accurate reference is available from the AC utility electric supply. In most parts of the World the utility electricity supply is generated at a frequency of either 50 or 60Hz (many digital clocks take advantage of this fact to keep time)
Using almost any transformer (or Wall Wart) with a 6 to 12 volt RMS AC output we can obtain an accurate reference source to calibrate the PICs oscillator against.
Schematics, Construction, and Code
So let’s get on with it. Construct the circuit shown below using a piece of strip or pad board, or just hook it up on a solderless breadboard.
For more detail: Internal Oscillator Recalibration Utility for PIC12F629
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w
Current Project / Post can also be found using:
- pic calibrating the internal oscillator
- calibrate internal oscillator by software