Getting Started

(lily) #1
Chapter 7: Microcontroller Interrupts and Timers

oscillator:


nderstand how it works.

If you try to tell tim ATmega169,
you can duce
ery pr se pulse trains, but due to manufacturing variables, the pulse timing
l’ time. Real time is
ences an atomic clock.
real time requires an external crystal that has
time with the NBS clock. The Butterfly uses
.
stals are accurate, cheap, and make keeping human time easy (‘easy’
eing another relative term).

get an accurate count of a time period by counting pulses from the watch
rystal. For instance if we count 32768 pulses we know that one second has
scillator by
ime period.
Hz, so we are going to get a
tch crystal. If we count 32768
om the oscillator in the same
get 8 million counts from the

Calibrating the Butterfly oscillator:


We first used the OSCCAL_calibration() function in the PC_Comm project,
claiming that we would explain it later. Well, it’s later and, wow, it’s time to
u

e with the uncalibrated oscillator built into the
expect to gain or lose a couple of hours a day. These oscillators pro
v eci
varies from chip to chip and do not correlate to ‘rea
determined by the National Bureau of Standards and refer
To calibrate the built-in oscillator to
been precisely trimmed to pulse in
an external 32.768 kHz watch crystal to calibrate the oscillator to run at 8 MHz
Watch cry
b

We can
c
passed. We use a shorter known good period to calibrate the internal o
setting the oscillator to generate x pulses in the known good t
Remember that the oscillator is running at about 8 M
lot more counts from it than we will get from the wa
pulses from the watch crystal and 8 million pulses fr
period, we know the 8 MHz is accurate. That is, we
oscillator in the same period we get 32768 counts (one second) from the crystal
meaning the oscillator is running at exactly 8 million pulses per second. But we
will actually use a much shorter period and have smaller counts. If the oscillator
count is too small for the period we change the value in a register to speed it up,
and if it is too large we change the register to slow it down. We do this in a loop to
keep bracketing the speed until it gets as accurate as we can make it. Sounds easy,
but as you’ll quickly see, it is a real pain just to get the registers all set up
properly.

In this section we will learn how the Butterfly oscillator is calibrated. This is
presented in two sections, the first shows the OSCCAL_calibration function, and
the second gives a detailed explanation.
Free download pdf