Nuts & Volts
Nuts & Volts
Nuts & Volts
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Doing these things allowed me to<br />
add five to the ones variable for each<br />
step of voltage measured by the<br />
MC68HC908MR16’s analog-to-digital<br />
converter. The ASCII values 0x30<br />
through 0x39 represent a readable 1<br />
through 9, respectively. So, I initialized<br />
all of the digit variables to 0x30<br />
(readable zero) and looked for an<br />
overflow to 0x3A after each increment<br />
of five operation. The result is an upcounter<br />
that converts the value of<br />
ANALOG_OutV to a human readable<br />
number between 0.000 and 5.120,<br />
which represents the voltage applied<br />
to the MC68HC908MR16’s analog-todigital<br />
converter input pin.<br />
You can observe the caveman<br />
■ PHOTO 3<br />
30 March 2006<br />
counter’s operation by single stepping<br />
through the code in debug mode. Once<br />
the incoming voltage is converted to<br />
human readable form, I used our RS-232<br />
Bean code to send the ASCII voltage<br />
reading to a terminal emulator running<br />
on a PC. To eliminate missing characters<br />
and to make the voltage values a bit<br />
easier to read, the ASCII characters need<br />
to be paced to the terminal emulator<br />
and instead of writing some homebrew<br />
delay code, I enabled the Delay100US in<br />
the Methods area of the Cpu Bean<br />
Inspector.<br />
I recommend you use Tera Term<br />
Pro as the terminal emulator. You<br />
can get a free copy of Tera Term Pro<br />
from the Tera Term Pro home page<br />
at http://hp.vector.co.jp/<br />
authors/VA002416/tera<br />
term.html You can see the<br />
ADC code running and<br />
talking to Tera Term Pro in<br />
Photo 2.<br />
EASY PWM<br />
WITH THE<br />
MC68HC908MR16<br />
There are two ways to<br />
get a usable PWM signal out<br />
■ PHOTO 2. This is a good look at the<br />
debugging tools provided by the P&E<br />
Cyclone Pro. The voltage readings<br />
are shown in the Tera Term Pro window.<br />
Using the 10K pot, I dialed in +2.500<br />
volts as the input voltage to the MC68HC<br />
908MR16’s ADC. Although the results look<br />
really bad in raw form, if you average the<br />
20 readings you see, the average voltage<br />
works out to be +2.57 volts.<br />
of the MC68HC908MR16. The first<br />
method entails reading the 41 pages of<br />
the MC68HC908MR16 datasheet<br />
describing the care and feeding of the<br />
MC68HC908MR16’s multi-channel PWM<br />
subsystem. Then, write the PWM code<br />
you need. The second method does not<br />
require any datasheet study and allows<br />
you to programmatically set the PWM<br />
period and duty cycle in real time units<br />
of microseconds or milliseconds.<br />
Behold Listing 4. Just by looking<br />
at the code snippet in Listing 4, you<br />
already know which of the aforementioned<br />
PWM generation methods I<br />
used. The song remains the same. I<br />
selected the PWM Bean from the<br />
Timer folder within the Bean Selector<br />
and double-clicked it into my new<br />
MR16_PWM project. Configuration of<br />
the PWM Bean included renaming the<br />
Bean to SERVO, setting a PWM period<br />
of 20 mS, and setting up the pulse<br />
polarity to produce a high-going<br />
pulse.<br />
I compiled the project and inserted<br />
the result=SERVO_SetDutyUS<br />
function, which was generated in the<br />
SERVO.c file. Notice the absence of my<br />
omnipresent LED blinker code. There’s<br />
no need for it here, as I attached an<br />
Airtronics 94102 servo to the fourth bit<br />
of the MC68HC908MR16’s Port E. The<br />
source code you are looking at in<br />
Listing 4 continually takes the servo<br />
rotor to and from both the clockwise<br />
and counterclockwise extremes<br />
stopping at the center point with each<br />
traversal.<br />
ROTATING OUT<br />
All of the additional modifications<br />
to the solderless breadboard<br />
can be seen in Photo 3. As you can<br />
see, I’ve added an RS-232 port, a<br />
potentiometer, and a hobby servo. All<br />
of this circuitry could have just as easily<br />
been assembled in a point-to-