I recently started playing around with micro-controllers, and with a pc interface and it's software, when reading a program from a micro controller i got a field that said OSCALL byte and seems to give me a different value everytime, my question is, what is this byte? What does it stand for?
From the name i would guess something like OSScillator CALLibration, although both the S and L are doubled, this is what makes more sense to me…
Best Regards
Best Answer
Your related question says that you are using a 12F629, so I will refer to this datasheet throughout.
Many modern microcontrollers have inbuilt oscillators. These are fairly accurate but the exact frequency will vary due to the manufacturing process. Because of this most of these microcontrollers have some way of "tuning" or calibrating the oscillator whilst it is running.
With the PIC 12F (and other similar PIC families) there is a register called
OSCCAL
. You can read about it in section 9.2.5.1 "Calibrating the Internal Oscillator" on page 56 of the datasheet I linked above.The datasheet says:
This value can be calculated and set by Microchip's PICKit2 and PICKit3 programmers and probably by some of the better compatible tools.
Example 9-1 on page 56 shows how this is loaded into the
OSCCAL
register, which is volatile and therefore needs to be set at each powerup.This is a simple piece of code that selects the correct bank, calls the last memory location (0x3FF) and then moves the result into the
OSCCAL
register. This explains why the last byte in a hex file disassembles toRETLW XX
, it simply returns the calibration value.If you want to use this value which is stored in program flash you need to include a small stub like the above code that runs each time your device undergoes a power-on reset. Some PIC C compilers will automatically include this for you on relevant devices.
You can read some more about OSCCAL at the following links: