Start
Joystick
Anatomy
No
Brain
Got
Brains?
Higher Resolution
Minimum I/O
Visual Feedback
Sources
and PDF
MINIMUM
I/O
Now
that 8-pin microcontrollers are no longer the laughing
stock of the industry, Microchip has reduced the
pin count again. Are three I/Os and one input useful?
Isn't this getting a bit whacky?
I
designed the next circuit using a PIC10F20x series
microcontroller that comes in an SOT-6 package (see
Photo 1). With two output pins defined as SCK and
SDA to control a digital potentiometer or DAC, there
was little left for monitoring the JS1100AQ switches.
I connected JS1100AQ's independent switch to the
microcontroller's input. I then needed to monitor
the other four directional switches with the single
pin that was left. Not an easy job for a digital
input.
|

(Click
here to enlarge)
|
Photo
1—When looking at this analog joystick, notice
the size difference between it and the JS1100AQ
multiposition switch balanced on top of it.
Look closely at the JS1100AQ, and you'll also
see the SOT-6 PIC10F20x. |
I
decided to monitor the capacitor of an RC circuit
with the last I/O pin. The direction switches (JS1100AQ)
connect different resistor values between 5 V and
the capacitor, which has its other lead grounded.
By using resistor values that are half the previous
value, I could get eight different RC time constants
charging the capacitor by using one switch or combinations
of two switches. As an input the microcontroller
could count how long the digital input took to go
from a logic 0 to a logic 1. This was dependent
on the VIH of the port input, but it was consistent
and dependent on VCC. By configuring the same port
pin as an output (outputting a logic low), the capacitor
could be discharged.
The
main loop of execution program monitors the JS1100AQ's
independent switch for closure. This reconfigures
the RC monitor pin to an input and starts a software
loop (12 µs) monitoring the input pin and incrementing
a 16-bit counter variable. Depending on the tilt
direction of the JS1100AQ, one or more of the corner
switches will be closed. Each combination of switch
closures creates a different current flowing into
the capacitor. Thus, the capacitor will charge at
eight different rates. Execution breaks out of the
counter loop after the monitor input is read as
a logic 1. The monitor pin is reconfigured to an
output (discharging the capacitor). The timer's
count is compared to a table of values. The closest
selection from the table returns the position of
the JS1100AQ (N, NE, E, SE, S, SW, W, NW). Branching
to appropriate routines can adjust the XVal and
YVal variables used to update the SPI device.
Just
when I thought I had it licked, I remembered a little
note that explained how SPI values would be internally
transferred after the raising of the device's CS
input. Whoa! I wasn't using the CS and had it tied
low (enable). Did I not use all of the I/Os? No,
I used all four. What to do?
I
was able to tie the monitor pin to the SPI device's
CS input (see Figure 6). Timing the capacitor and
sending SPI commands were independent operations,
so the monitoring pin could do triple duty by monitoring
the voltage input, shorting the capacitor to ground,
and providing a CS signal.
|

(Click
here to enlarge)
|
Figure
6—Even with only four I/Os, this PIC10F20X can
monitor the JS1100AQ and communicate using a
software SPI interface to an external device. |
I
chose an RC combination that would be approximately
100 ms. (The value limits the maximum step speed.)
The three other values became one-half, one-quarter,
and one-eighth of the first value. I needed to find
values for the LUT for each combination of switch
positions. By altering the program to output a pulse
on the SCK pin based on the monitor input, I could
measure the pulse width in microseconds based on
what the circuit actually saw at the monitor input.
I placed the measured values in the LUT to let the
program determine which switches the JS1100AQ was
closing. If I'd had 1% resistor values available,
I might have been able to choose table values based
on a single measurement of the highest resistor
or perhaps a self-calibration routine during power-up.