■ FIGURE 2.
Vin from the power connector (be careful with using Vin;
anything above 7. 2 volts will probably destroy your servos).
The center pin of the voltage select header is routed
through the power switch to the servo headers so that we
can power up the SX without applying power to the servos.
When we want the servos to run, we move the power
switch to the far-right position. These features shouldn’t be
too surprising as they make using the SX28 proto board on
the Parallax Boe-Bot chassis very easy.
The first major subsystem is the analog-to-digital
conversion of the joystick input. Part of the parameters for
this project was to use an off-the-shelf, PC-compatible
analog joystick. The trouble with analog PC joysticks is that
we only get two connections per pot; we don’t get the ends
plus the wiper — we get one end (common, on pin 1) and
the wipers from each axis. What we’re forced to do, then,
is add a second resistor to create a divider. We’ll tap off that
divider and run it into an input channel of the ADC0832.
Figure 2 shows the joystick interface for the circuit. As
you can see, the pot outputs from the joystick (pins 3 and
6) are connected to 10K pull-downs and then on to the
ADC0832. The application of 5V to pin 1 of the joystick
connector routes this voltage to the pots. While this
arrangement works, we don’t get a centered output value
when the pot is in its center position; I don’t like
“fixing” circuits in code, but this is a case where there is
just no choice.
Let’s have a look at the ADC code. The ADC0832 has
two inputs and it can be configured on-the-fly to provide
singled-ended or differential output. Configuration of the
ADC is accomplished by clocking four (mux) bits into the
device. As you can see in the function code, \4 is used to
limit the number of bits sent to the ADC. For convenience,
the waldo program has constants defined for single-ended
channels 0 and 1 that include the ADC start bit. After
shifting the mux bits out to the ADC, an eight-bit value can
be shifted in.
tmpB1 = __PARAM1
Clk = 0
CS = 0
SHIFTOUT Dio, Clk, MSBFIRST, tmpB1\4, 4
SHIFTIN Dio, Clk, MSBPOST, tmpB1, 4
CS = 1
Let me point out a couple things having to do with
the use of SHIFTOUT and SHIFTIN. First, both of these
instructions simply invert the clock pin (twice) for each bit.
What this means is that we need to preset the clock level
before using SHIFTOUT or SHIFTIN; neglecting to do
this is a common mistake for those porting BASIC Stamp
programs to SX/B. Later versions of SX/B include an
optional clock speed multiplier.
Without the multiplier, the data rate is about 83K bits
per second, but many devices will operate significantly
faster than that so we can take advantage by using the
multiplier. Another point of consideration for this particular
project is that a “virtual” servo controller is running in the
Interrupt Service Routine so all foreground operations are
September 2007 81