Menu

Oscal Setting

Help
Keith
2023-07-26
2023-08-05
  • Keith

    Keith - 2023-07-26

    Something that has had me puzzled for donkeys but never got round to asking about it.

    Where is the Oscal value derived from?

    Occasionally I'll screw up the value and how I get round it is by reading the value from another device of the same ilk and reprogram the same onto the device which I have screwed up... It works but it isn't the right way to do it.

     
  • Anobium

    Anobium - 2023-07-27

    The OSCCAL value on a microcontroller is used to calibrate the internal oscillator.

    The oscillator is responsible for generating the clock signal that the microcontroller uses to run its programs. The OSCCAL value is a 8-bit register that can be adjusted to slightly vary the frequency of the oscillator. This is necessary because the actual frequency of the oscillator can vary slightly from device to device due to manufacturing tolerances. By adjusting the OSCCAL value, you can ensure that the oscillator is running at the correct frequency and that your programs will run correctly/at the expected frequency.

    The OSCCAL value is stored in the microcontroller's PROGMEM memory. This means that it will be retained even if the microcontroller is powered off but in the case of the ChipFamily 14 ( 12F, 16F) the value can be erased.

    However, if the OSCCAL value is lost or corrupted, you will need to re-calibrate the oscillator. This can be done using a variety of methods, such as using a PK2/PK3, crystal oscillator or a dedicated calibration tool.

    Here are some of the benefits of calibrating the OSCCAL value:

    • Improved accuracy of the clock signal
    • Increased reliability of the microcontroller
    • Reduced risk of software errors
    • Improved performance of the microcontroller

    If you are working with a microcontroller that has an internal oscillator, it is important to calibrate the OSCCAL value. This will help to ensure that your programs will run correctly and that your microcontroller will be more reliable.

    GCBASIC automatically calls the microcontroller OSCCAL value, this call will load the internal register and then the value is placed in the OSCCAL register. This equates to:

    OSCCAL = microcontroller OSCCAL value
    

    The Oscillator Calibration register (OSCCAL) is used to calibrate the internal 4 MHz oscillator. It contains 6 bits to adjust the frequency up or down to achieve 4 MHz. The 6 bits are the high bits so therefore:

    bit 7-2 CAL5:CAL0: 6-bit Signed Oscillator Calibration bits
    111111 = Maximum frequency
    100000 = Center frequency
    000000 = Minimum frequency
    

    So, the range of 0x00 to 0xFC. This is because the OSCCAL value is actually RETLW XX where the RETLW value is loaded in the microcontroller W register.

    RETLW

    RETLW is RETLW k; 1; 11 01xx kkkk kkkk So, the OSCCAL value in the PROGMEM is actual RETLW 00..FC

     
  • Keith

    Keith - 2023-08-05

    Mmm.... Yes.
    I wonder how many folks have sat back and said, "I'm glad he has asked that question"

    Sometimes it is wiser to keep your mouth shut and look stupid than to open it and remove all doubt.

     
    • Anobium

      Anobium - 2023-08-05

      It was a good question. I gave a detailed answer to cover all aspects.

      Pleasure.

       

Log in to post a comment.