complement number is all it takes. Negative numbers slow
the clock down, while positive ones speed it up. Tuning
over a range of ± 12.5% is possible.
The register T1CON concerns itself with controlling
Timer 1 which is typically clocked by an external 32.768
kHz crystal which can also do double-duty as the system
clock. You might remember this as T1OSC mode from
Figure 2. The important flag here is T1OSCEN which
enables the Timer 1 crystal oscillator.
At this point, we've hit the fundamentals of clocking
the PIC for most common situations. Let's finish up by
taking a brief look at the secondary clocks and what
they're good for.
The day may come when you'll want to go beyond
just turning on a primary clock and letting it do its thing. If
so, then you'll need to know a little bit about clock
switching. Figure 5 gives the big picture. Essentially, you
can manually switch between primary and secondary
clocks, or do so automatically under certain conditions.
To manually switch from one to another, you're back
to Figure 4 and simply need to alter a few bits in the three
registers described there. For example, to change from
INTRC to INTOSC, you'd adjust bits IRCF0 through IRCF2
as required. Or, to go from a crystal oscillator, say, to
INTOSC, head to SCS0 and SCS1 which let you flip back
and forth from primary to secondary. You get the idea;
manually switching oscillators is just a matter of bit-twiddling in your program.
So, what about automatic switchovers? Well, there are
two situations in which it's handy to have one clock take
over for another. The first is the failsafe mechanism.
Imagine you're designing a circuit to operate in a critical
environment in medicine or industrial safety monitoring,
for example. If the primary oscillator was a crystal, for
instance, and it failed for some reason, then the PIC would
simply come to a standstill. Not good! With a secondary
clock in the wings, the chip could switch over to it almost
seamlessly and still keep operating until the original fault
could be attended to. As Figure 5 shows, the failsafe
feature can check for problems with any of the four crystal
modes (LP, XT, HS, or T1OSC). It's enabled via the
FCMEN bit in CONFIG2.
If avoiding delays is a concern, then the two-speed
wake-up option might prove useful. Here's the basic
idea. Suppose you were operating the circuit on a
crystal. As you probably know, crystal oscillators take a
moment or two to warm up. The PIC understands this
and patiently waits a bit before letting the clock start
shooting the instructions through the pipeline. In other
words, your project is just sitting there doing nothing
for a few moments. On the other hand, the internal
oscillators INTRC and INTOSC are essentially put in
gear instantaneously. So, why not choose one of these
to serve as a secondary clock?
Now, the sequence will be that the internal oscillator
handles everything (possibly at a slower rate, but a least
it's moving!) until the crystal is ready to assume the mantel
of system clock. The switchover is automatic and there's
no dead time where nothing is happening.
When is this needed? As intimated earlier, PICs
support a sleep command. When executed, the power
hungry stuff is shut down and the chip idles in a very low
current state. In particular, any crystal being used as a
primary clock is halted. Various signals like a reset, an
interrupt, or something called the watchdog timer can
wake the chip up again. If you want some instant action
while the crystal revs up, then consider the two-speed
Figure 4. These registers can be changed during runtime.
Figure 5. Clocks can
January 2014 41