Alain, I guess some datasheets have more information than others. I haven't used any 16F parts for years, so I never considered looking there.

Heckler, I used a frequency counter connected to CLKOUT.



You can write to OSCTUNE at any time.

In my case, I needed all devices to run very close to 4Mhz, so -

After programming, the first thing the PIC (in my case, an 18F2221) looks for is for a pin to go low (the pin is connected to a pushbutton). A LED connected to another pin is flashed in a particular pattern. This indicates it is in the CALIBRATION mode.

Another PIC (actually an 18F8722 development board used as a "calibrator") is connected to another pin on the 18F2221. The "calibrator" board sends out a precise 30ms low (using pulsout), followed by a 1 second high, followed by another 30ms low followed by a 1 second high....

The '2221 looks for the 30ms low and times it, (using pulsin). If the pulse appears shorter or longer than 30ms to the '2221, it divides the difference by 24 and increments or decrements a variable and writes that variable both to the the OSCTUNE register and to EEPROM. The LED is flashed in a pattern that indicates calibration was successful. Another EEPROM cell is written with $AA to indicate the calibration process was successful. This cell is checked on power up. If it is $AA the entire calibration process is bypassed.

On power up, the calibration value in the EEPROM is read and loaded into OSCTUNE.

I have found very few '2221s that were more than 1% off. They are remarkably temperature-stable as well.



On power up, the EEPROM