Steps Involved in the Calibration Procedure

  1. 1.The programming tool writes the calibration firmware into the device and possibly enables the MISO pull-up, and releases the reset line. If the JTAG interface is used, the JTAG disable bit in MCUCSR is set by the calibration firmware in the device. The calibration clock (approximately 32kHz) is applied on the MOSI line by the programming tool.
  2. 2.The device enables the internal pull-up on the MOSI line, sets the MISO line high, and starts listening for the calibration clock on MOSI.
  3. 3.When the device detects the calibration clock a binary search is performed to find an OSCCAL value that meets the criteria of 1% accuracy. If the binary search does not reveal a value that meets this requirement, the neighboring values of the outcome of the binary search are tested to identify one that does. If calibration fails the MISO line is set low and program flow goes to step 6.
  4. 4.The calibration value is stored in EEPROM (skipped if calibration fails).
  5. 5.The MISO line is toggled 8 times/4 cycles by the device. The toggling of the MISO line is performed on the falling edge of the clock on the MOSI line (C-clock), but 5 to 10 CPU cycles delayed. In the case of failing calibration the MISO line is not toggled.
  6. 6.If necessary, the JTAG interface is re-enabled and the device goes into an infinite loop.
  7. 7.If the device does not have an EESAVE fuse, the programmer must read back the calibration byte from EEPROM, for later restoring when the calibration firmware has been erased from the flash memory. If the device has an EESAVE fuse, this fuse can be set so that erasing the Flash does not also erase the EEPROM. It is necessary to copy the calibration byte from EEPROM or FLASH to the OSCCAL register at run-time. A routine for this must therefore be implemented in the final firmware.