Circuit and software provide accurate recalibration for baseline PIC microcontroller’s internal oscillator
A simple circuit and an assembly-language program allow you to recalibrate the internal oscillator of a PIC microcontroller.
Noureddine Benabadji, University of Sciences and Technology, Oran, Algeria; Edited by Charles H Small and Fran Granville -- EDN, May 1, 2008
All of Microchip’s baseline PIC microcontrollers have internal 4-MHz oscillators, which are useful for freeing up one or two pins for I/O use and allowing you to build minimal-component-count designs using these devices. You must calibrate the internal oscillator by reading a factory-programmed calibration setting that resides at the last address in the user-program memory and then writing that setting into the microcontroller’s oscillation-calibration register during the application software’s initialization of the device. Because the calibration value is unique to each microcontroller, problems arise for time-sensitive applications if you erase or overwrite the last address.
The circuit in Figure 1 recovers the calibration value by recalibrating against a reference clock, the 4-MHz crystal. The frequency looks for the best calibration value to ensure that the microcontroller’s internal oscillator runs within 1% accuracy at 4 MHz. You can download the microcontroller’s program and a flow chart from this compressed zip file.
The baseline PIC microcontroller, which includes the PIC10F, PIC12C508/509/510, or PIC16F505/506 series, uses its internal timer, Timer 0, to count the number of instruction cycles that execute in one period from output Q8 of a Fairchild Semiconductor CD4060 oscillator/divider to the only input, GP3, of the PIC microcontroller. The 4-MHz crystal drives the CD4060, which yields a period of 128 µsec from the output Q8.
The four LEDs display the two 4-bits nibbles of the 8-bit oscillation-calibration register’s best value. Output GP2 acts as a multiplexing line to drive these LEDs for 8 to 10 sec and then as the oscillator output to yield a 1-MHz signal, which you can measure with a frequency meter or an oscilloscope.


















