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
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
Current Project / Post can also be found using:
- PIC 12F629 timer calibration