How do I calibrate the programmable internal oscillator to a non-factory value?
The programmable internal oscillator can be calibrated using a known clock source selected as SYSCLK. This SYSCLK frequency should be higher than that of the oscillator to be calibrated. The example code 'F330_LFO_Cal.C' shows how to measure the SYSCLK time between the falling and rising edges of the LFO using the timer in capture mode. After the frequency is measured, you can then modify the calibration register (OSCICL for HFO, OSCLCN for LFO) to fine-tune the oscillator to a desired frequency using the formula given in the 'Oscillators' chapter of the datasheet. This example code applies to the F33x devices only. For other devices, necessary changes should be made to the code before it can be used.
Certain devices in the C8051Fxxxx family do not have a calibration register for the internal oscillators. These are the C8051F00x, C8051F01x, C8051F02x, adn C8051F2xx. They only have a clock divider that can operate on the fixed internal oscillator frequency. Nevertheless, that frequency can be measured using the method detailed above.
Some devices have more than one programmable internal oscillator. See the datasheet for details.
For the USB devices, calibrating the internal oscillator away from the factory preset will make it unusable as the USB clock.
On reset, all devices revert back to factory preset calibration values and derive SYSCLK from the internal oscillator frequency divide by 8.
For information pertinent to the oscillator(s) in your device, please refer to the respective datasheet under chapter 'Oscillators'.