independently controlling both speed and direction
of the motors using OC1, OC2, and using two half H-bridges. The bridge package we are using is the 16-
pin DIP L913D; this supplies two half bridges (one for
each motor). Again, we need a +5V system, so we
use a three terminal 7805 +5V regulator. One other
piece of electronics is a 14-pin DIP 74HC04 quad
NOR gate (however, any logic inverter will do) for
driving dual pulse inputs (positive and negative
polarities) to each half bridge. Finally, again we have
our 10K pot for the actual control settings. Note
because the Experimenter + 3. 3 OCX outputs are TTL
compatible, there is no need for pull-ups. Hook-up
connections are shown in Figure 5. The bridge runs off
+5V for logic but the motor voltage has to be higher than
this (we are using + 6 DC available as input value to the
7805 regulator). Note the similarities with the previous
■ FIGURE 7. Input Compare peripheral.
• motor_init () — Initializes OC1, OC2 for PWM
operation using TMR2 as the common timing
source. All the OCx are enabled for 50% duty cycle
— causing both motors to stall.
• Motor1_on (), Motor1_off(), Motor2_on (),
Motor2_off() — Individual functions per motor to
turn them on or off.
• Set Motor1 (setting), Set Motor2 (setting) — Sets
the PWM duty cycle of the designated motor.
Designated motor is selected via pushbutton by user.
Current selected servo is stored as number 1 to 2 in
variable selmotor. If PWM is less than 50% duty
cycle, then the motor is in the reverse direction with
variable speed; if duty cycle is more the 50%, motor
is in the forward direction with variable speed. If
duty cycle is 50%, motor is stalled and not moving.
pulse level measurement. The ICX can measure the width
of the pulse by capturing each leading and trailing edge
and subtracting the time differences from both edges.
Again, as in the OCX, most ICX activities occur in the
hardware of the peripheral (software is minimal). It can be
configured with either timer 2 or timer 3 as a free running
time base. Edge captures are automatically loaded into a
buffer (ICXBUF). We will look at the ICX operations and
work through the following applications (hardware hook-ups and source code are provided):
Demo 4. Measuring the pulse output from a two-axis
accelerometer (changing duty cycle is
proportional to changes in sensor
We are using the LCD, ADC, and pushbutton C
libraries again from earlier 16-bit Experimenter articles. The
code is contained in MOTORDEMO.
Please review the PWM profile (Figure
6) to understand the PWM requirements for
The accelerometer is the MX2125 dual axis unit
offered by Parallax.com and provides the X and Y output
PWM pulse corresponding to acceleration forces acting on
each of these axis. IC1 connects to the X output of
MX2125 using pin 8 of the I/O expansion. IC2 connects to
the Y output of MX2125 using pin 7 of the I/O expansion
bus. A hook-up diagram is supplied (see Figure 8).
Fortunately, the MX2125 can operate in a + 3.3V
As we mentioned earlier, the
PIC24FJ64GA002 has five Input Compare
modules. Any of the five Input Compare
module ICX (X can represent any number
from 1 to 5 for our processor) can be
mapped to a number of pins on the
Experimenter’s 10-pin I/O expansion bus. A
block diagram of the ICX is shown in Figure
7. The ICX uses designated external level
conditions to capture a free running 16-bit
timing source. This becomes the basis for
■ FIGURE 8. Accelerometer
August 2010 49