Internal Oscillator Recalibration Utility for PIC12F629


The PIC 12F629 and 12F675 come equipped with an internal 4MHz oscillator, eliminating the need for an external crystal or RC network. This feature not only frees up one or two pins for I/O purposes but also facilitates integration into designs with minimal component counts.

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.

Internal Oscillator Recalibration

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

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us: