SELF-CALIBRATION
Yet
another feature of the LUB system is that space-hogging
calibrations that only need to be run occasionally
can be kept in the bootloader. In this example,
there is no external crystal. Instead, the internal
RC oscillator is calibrated against a real-time
clock that provides a 4,096-Hz output signal.
The target frequency is 7.37 MHz, which enables
error-free data rate communication at 115,200
bps. After calibration, the value is stored
in the DataFlash, where it can be read by the
tinyloader and stored in the OSCCAL register
at every start-up.
The
sharp-eyed among you are probably wondering
if you’ll be left with a dead system that can’t
communicate if power fails while you’re writing
this value. No! If the power fails, the ATmega88
AVR will still have the bootloader code loaded
into its flash memory. At the next start-up,
the tinyloader won’t see valid data from the
computer. It will proceed to start the code
in the ATmega88. This code, which is the bootloader,
will calibrate the oscillator and store it.
Now you’ll have a system that works. At that
point you can finish working with the bootloader.
Whether or not emulating a certain operating
system—an operating system for which troubleshooting
involves rebooting—is advantageous is up to
you.