BY THOMAS KIBALO
PULSE OPERATIONS
WITH THE 16-BIT MICRO
NTER
In this article, we will look at the digital pulse capture and generation
capabilities of the 16-bit Micro Experimenter (Experimenter for short). Pulse
operations are important for a large variety of microcontroller applications,
and with the Experimenter’s PIC24F we have an impressive arsenal of internal
modules: a total of five Input Capture modules and five Output Compare
modules. The Input Capture modules can capture pulse edges to measure
pulse frequency and pulse width. The Output Capture modules can generate
pulse waveforms with a changeable duty cycle on output. In both cases,
minimal software is required to operate these modules, as a lot of what they
do is done in hardware.
We will cover the use of these modules in a series of ive demos to include: LED brightness control; servo
control; DC motor speed and direction control; reading an
accelerometer; and range finding. Some of these apps may
be familiar to you, but here is an opportunity to apply 16-
bit horsepower and get collection of C drivers to boot!
There is lot of ground to cover, but it is definitely worth it
to be able to understand and use this pulse capability. As
■ FIGURE 1. Output
Compare peripheral.
■ FIGURE 2. Output Compare pulse generation.
46 August 2010
stated in earlier articles, all software will be kept to general
level straightforward functional calls, however, some basic
familiarity with C language syntax will be required. Let’s
start with the Output Compare module first and review the
basics of this peripheral.
Output Compare Module
The PIC24FJ64GA002 (used in the Experimenter) has
five Output Compare modules (OCX; where X = 1, 2, 3, 4,
5). Any OCX can be mapped to a number of the pins of
the Experimenter’s 10 pin I/O Expansion Bus. A block
diagram of an OCX is shown in Figure 1.
The OCX module can use either the PIC24FJ64GA002
16-bit timer 2 (TMR2) or timer 3 (TMR3) as a time base,
and the period setting for the output pulse waveform. PR2
is the period setting for timer 2 and PR3 is the period
setting for timer 3. The OCXRS and OCXR registers are
loaded with a 16-bit value to control the width of the pulse
generated during the output period. This value is
compared against the timer during each period cycle. The
OCX output starts high and then when a match occurs,
OCX logic will generate a low on output. This will be
repeated on a cycle by cycle basis (see Figure 2). For our
demos, we use the OCX in Pulse Width Modulation
(PWM) mode. PWM is a very powerful technique and is
used in a variety of applications. An important notion in
thinking about PWM is that it allows dynamic changing of
the DC voltage level to a load. Wait a minute, you say —-
where’s the DC voltage here? Think of the DC voltage as