A complete kit to go with this series of articles
can be purchased online from the Nuts & Volts
Webstore at www.nutsvolts.com or call our
order desk at 800-783-4624.
• Ping () — This function sets up IC1 and TMR2 to
capture the echo incoming pulse edges and make
measurements on the pulse width. The pulse width
is directly related to the distance to the target. IC1
interrupts are turned on by this function, and it waits
on the interrupts to complete its pulse
measurements before turning IC1 interrupts off. The
first interrupt occurs when an echo pulse leading
edge is detected. The TMR2 count value is captured
automatically. Once captured, the trailing edge is
subtracted from the leading edge and the interrupt is
shut down with the pulse width captured in the
variable measure.
The main code takes the measured pulse width and
calculates the value in inches. The following formula is
supplied by vendor:
Inches = (measure/2)/75
The inches value is converted to ASCII and displayed
on the LCD (see Figure 11). The whole measurement
PARTS LIST
QTY DESCRIPTION/PART NUMBER
RGB Experiment
1 RGB LED SPARKFUN COM-09264
1 10K POT
3 100 OHM resistors (1/4 watt)
SERVO Experiment
1 LM324 IC quad op-amp 14-pin DIP
1 7805 +5V regulator (three-terminal)
4 Parallax (Futaba) standard servos
4 10K resistors (1/4 watt)
1 10K POT
MOTOR Experiment
Accelerometer Experiment
1 Parallax MX2125 dual axis accelerometer
2 220 ohm resistors (1/4 watt)
PING Experiment
1 Parallax PING ULTRASONIC sensor
1 7805 +5V regulator (three-terminal)
1 470 ohm resistor
1 RED LED
■ FIGURE 11. PING display.
process is continuously repeated and values are updated
and displayed.
In Conclusion
We covered a lot of ground — some of you may have
seen it before (in other implementations). The bottom line
is that the material presented leverages a 16-bit
environment and specifically the Experimenter PIC24F and
alot of its extensive pulse operations. We really haven’t
covered all the capabilities yet, so stand by. The total
PIC24F pulse operation is impressive and you can mix and
match as well as scale up all the material presented here
for your next application. NV
August 2010 51