Issue
155 June 2003
Encore!
Zilog's
Z8 Flash Memory-Based Micro
A
QUESTION OF BALANCE
This
column is a setup for a project that you can work on
yourself. Photo 1 shows the platform I built to experiment
with balance. The idea was to monitor the movement (from
gravity) of a body fixed atop a single leg and attempt
to counteract the movement with a shift of weight.
|

(Click
here to enlarge)
|
Photo
1—Measuring roughly 4' in height with an aligned
ankle and hip axis, the hip servos are responsible
for tilting the upper platform to counteract the
effect of gravity on the inverted pendulum leg. |
|

(Click
here to enlarge)
|
Photo
2—The metal bushings pulled from control knobs are
soldered at right angles to hold the potentiometer’s
shafts creating an X-Y mechanism. The Z8F6401’s
VREF drives the potentiometers, which return voltages
indicating the position (movement) of the vertical
leg. |
|

(Click
here to enlarge)
|
Photo
3—The levers attached to the hip gimble allow the
servos to tilt the body (platform above the gimble)
in a ± X or Y direction referenced to the leg (and
ankle axis). |
The
foot of the leg is attached using a joystick-type ankle
joint. The potentiometers on this joint give the position
indication of the leg as X and Y outputs (see Photo
2). The body (platform) is connected to the leg through
a hip joint, which can be adjusted by X and Y servos
(see Photo 3). A Z8F6401 micro (a 40-pin DIP) is mounted
on the platform and takes in the foot’s position data
through analog inputs 0 and 1 (see Photo 4). The hip
servos are controlled via the PWM outputs of Timers
0 and 1 (see Figure 6).
|

(Click
here to enlarge)
|
Photo
4—The project’s PCB is mounted atop the platform
along with the four AA batteries. Plenty of space
remains on the PCB to accommodate circuitry for
future sensors. I’ve only begun to use the horsepower
and application space available on the Z8F6401. |
|

(Click
here to enlarge)
|
Figure
6—The 40-pin DIP version is used to eliminate surface-mount
soldering. J6 is the debug connector that allows
the debugger interface to be connected for debugging/programming
of the Z8F6401. Q2 and Q3 interface the 3.3-V PWM
outputs to the 6-V servo inputs. (The inverters
require an inverted PWM output.) |
Experimental
code initializes the A/D converter for continuous operation;
it uses DMA transfers to automatically move the conversion
values for channels 0 and 1 into RAM locations (new
sample values). The 10-bit conversion values are left
justified within their 16-bit word, and they must be
shifted to the right by six bits to lower justify them.
The
RC servos used in the hip joint must see a positive
pulse every 20 ms. The width of this pulse determines
the position of the servo. A pulse width of 1.5 ms positions
the servo at the center of its rotation (neutral). Timers
0 and 1 are initialized for a PWM output of 1.5 ms.
This requires the following timer reload value:
Thus,
where
the reload value equals 50,000 (or C350H), and the prescaler
equals eight. The PWM value (i.e., high time) is the
percentage of the period. In this case, you want the
following:

or

Therefore,
you arrive at the following equation for the PWM value:

or

where
the PWM value equals 3750, or 0EA6H.
Maximum
and minimum PWM values are also needed, because you
can’t ask the servos to move more than their design
limits. I used 1.25 and 1.75 ms as the lower and upper
design limits; they correspond to approximately 6.25%
and 8.75%, or values of 3125 and 4375 (or 0C35H and
1117H, respectively).
To
sustain a controlled point of balance, there are many
factors to consider. The leg’s position sensors in the
ankle provide movement information concerning the leg.
The arc of leg movement must be small per bit of the
A/D converter. Using a potentiometer with a full-scale
rotation of 300° and a 10-bit A/D converter gives roughly
0.3° per bit. At a leg length of 38, 0.3° of arc
would represent approximately 0.2 of movement
at the arc’s circumference.
A
weight will fall at 32' per second. This calculation
isn’t so simple when the weight is supported from falling.
When the weight is perfectly centered on the leg, it
will not fall, because the weight’s falling vector (0°
toward the center of the earth) is canceled by the leg’s
supporting vector (180° away from the center of the
earth). As the weight moves off the center, the leg
vector no longer cancels the weight vector, and the
weight begins to fall. The farther from the center,
the less the leg can slow the weight’s acceleration.
By this (and through personal experience), it’s clear
that the faster you respond to an off-balance situation,
the more likely you are to correct it.
Servos
aren’t the quickest positioners. The Cirrus CS-50s that
I used are rated for 60° in 0.16 s (i.e., roughly 3
ms per 1°). There are about a 6 between the platform
holding the electronics and batteries and the hip joint.
This is the (body) weight that the servos must move
to counteract the leg position. When the Z8F sees a
change in leg position, it changes a PWM output in an
attempt to counter the movement.