46 SERVO 08.2014
should be enabled, then, in
order to respond to interrupts.
Enough Theory — Let’s Build Something
Really, the only decent way
to learn electronics is by doing
electronics. So, let’s head to the
workbench and fire up the
breadboard. Here are four
laboratory exercises for you to
try — the very ones I whipped up
for myself when first learning
how the compare module works.
Begin by going to the article
link and fetch the source code
for these experiments. The
software has been written in the
easy-to-learn open source (and
free) Great Cow Basic language.
Since the code has been heavily
documented, it should be quite
simple to port it over to any
other language or dialect you
prefer working with.
In Exercise 1, the compare
module is used to generate the
frequencies 1 kHz on up to 16 kHz, in 1 kHz
steps. Figure 6 shows the circuit, and it’s an
easy one. Four switches are used to select
the desired frequency.
With these, then, you can create the
binary numbers 0 through 15, corresponding
to the frequencies just mentioned. I decided
to clock the PIC on a 20 MHz ceramic
resonator since that’s what I had handy.
If you check out the source, you’ll see
that the fourth mode is being used which
automatically clears Timer 1 when a match
occurs. Moreover, an interrupt routine sets or
clears port line B.0 on appropriate half-cycles.
When monitoring the results with a
homemade frequency counter, I found that
the unit was fairly accurate, generating
frequencies within 0.6% — about what you’d
expect with a ceramic resonator. A crystal
would give even more precise results.
Exercise 2 — the schematic is shown in
Figure 7 — probably looks like a step back
into your past. Here, we’re simply going to
Figure 7.
Schematic for
Exercise 2.
Figure 6. Schematic for
Exercise 1.