LSB
MSB
CLOCK
STANDARD
PS2 DATA
COMMON TIME
OVERLAP
WIRELESS
PS2 DATA
Figure 6. Data signal comparisons between wired and
wireless controllers with respect to the same clock signal.
with both wired and
wireless controllers.
Only one line of
code needs to be
changed, depending on whether you
are using a wired or
wireless controller.
If you are using
a regular wired
controller, set the
Mode to 3, and set
the mode to 1 for a
wireless controller.
Figure 6 shows
the electrical wiring
the clock signal, the SHIFTIN’s mode
needs to be changed to LSBPRE (read
the LSB before sending the clock signal).
The program shown in Listing 1
includes these changes, and will work
Listing 1
‘{$STAMP BS2px}
‘ {$PBASIC 2.5}
‘ This demo program has been shown to work with
‘ BS2p24 and BSpx24, and does not work with regular
‘ BS2 Stamps with the Lynxmotion wireless controller.
clk PIN 7 ‘ Clock Line
att PIN 6 ‘ Attention Line
dat PIN 4 ‘ Data Line
cmd PIN 5 ‘ Command Line
Mode CON 3 ‘ 1 = Wireless Controller = LSBPRE
‘‘‘‘‘‘‘‘‘‘‘‘‘‘ 3 = Wired Controller = LSBPOST
Temp VAR Byte(8) ‘ Controller data
i VAR Byte ‘ Loop Counter
‘ Main Wireless Controller loop
Main:
GOSUB Wireless_PS2
GOTO main
for this circuit.
This doesn’t answer the whole
question, however. The wireless controller has a much tighter timing requirement than the regular PS2 controller. If
the Stamp takes too
long to process the
data to and from
the controller, the
wireless controller
will time out for a
moment and lose its
wireless connection
with the receiver,
and only sporadic
information is transmitted. I have tried
three different BASIC
Stamps with this program. The BS2p24
and the BS2px24 are
fast enough to keep
up with the communications with the
wireless controller,
but the regular BS2
Stamp doesn’t work
because it is too
slow.
I am not the
only one that has
observed all this.
Read the discussions
on the Parallax
forums (http://
forums.parallax.
com/forums/defa
ult.aspx?f= 5&p= 5
&m=138508) about
what other people
have learned. It
looks like the
Wireless_PS2:
‘‘‘ Read Controller mode $41=digital, $73=analog
LOW att
SHIFTOUT cmd, clk, LSBFIRST, [$01]
SHIFTIN dat, clk, mode, [temp(1)]
HIGH att
‘‘‘ Read controllerr
LOW att
SHIFTOUT cmd, clk, LSBFIRST, [$01,$42,$00]
FOR i = 2 TO 7
SHIFTIN dat, clk, mode, [temp(i)]
NEXT
HIGH att
‘‘‘ Display Results
DEBUG CRSRXY, 0, 2,”Mode: “,IHEX2 temp(1), “ “, CR
DEBUG CRSRXY, 0, 3,BIN8 temp(2), “ “, BIN8 temp(3),
““““““““““ “, DEC3 temp(4), “ “, DEC3 temp(5), “ “,
DEC3 temp(6), “ “, DEC3 temp(7), CR
RETURN
MadCatz ( www.madcatz.com) and
the Lynxmotion controllers require
faster speeds to keep up with the
controllers, whereas the Pelican
( www.pelicanperformance.com)
and Thrustmaster ( www.thrust
master.com) have been shown to
work with regular BS2 Stamps.
Logitech ( www.logitech.com) has a
wireless controller, but I haven’t heard
of anyone successfully interfacing their
controller with a microcontroller.
It is interesting how processor speed
has a significant effect on how well you
can interface a wireless controller and
not critical when interfacing with a
regular wired PS2 controller. For example, a Basic Atom microcontroller doesn’t
need to read the data in before the clock
pulse (LSBPRE mode), whereas the
BASIC Stamp does. In fact, the Basic
Atom will not even work if you try to
read the data in before the clock pulse.
It needs to use the LSBPOST mode in the
ShiftIn function to properly read in the
data. Measurements on the actual clock
signal from a Playstation console indicate
that its natural clock speed is about 125
kHz. Since it is transmitting 21 bytes of
data, the time required to read in the
data from both controller types is about
0.3 ms. A Basic Atom will read in the
data in about 4. 5 ms. This speed is probably why the Atom syncs up well with
the controllers. A BS2px24 takes about
13. 8 ms to read in all the data from the
controller. Though the Stamp still works,
it requires reading in the data in a
different format. A regular BS2 Stamp is
about six times slower, and does not
sync up with the Lynxmotion wireless
controller. This indicates that the common overlap time where both systems
work is not much slower than 14 ms.
Figure 6 illustrates this. Slowing the clock
speed increases the common overlap
time, but longer clock times can result in
the wireless controllers timing out.
Interfacing a microcontroller to a
wireless controller is pretty straightforward, but it should be done with the
faster microcontrollers such as a BS2px24,
Basic Atom, or even the new Propeller
chip from Parallax. This is kind-of a long
discussion about wireless controllers in
general, I am hoping that it provides you
enough information to get your controller
to work with your robot. SV
18 SERVO 01.2007