Technical Supplement PS2
Before going further, we need to first look into the details of
what the SPI interface will be communicating to the host. This
involves the PS2 control buttons and analog joysticks.
The PS2 has 16 buttons: four Directional Pad (Dpad) buttons;
four Action buttons (circle, triangle, etc.); and four Shoulder
buttons, (start, select etc.). Both analog joysticks can be pressed
as buttons, in turn. When pressed, each button outputs -0; when
released each button outputs -1.
The two analog joySticks on the PS2 can each be moved in
two axis. The output of each stick is proportional to the amount of
tilt the stick is placed under. Each stick outputs two values of 0 to
255, corresponding and proportional to the tilt on each axis.
Twelve of the PS2 button may be set as Pressure Sensitive
buttons (four Dpad, four Action, four Shoulder), each outputting a
value between 0 to 255, proportional to the amount of pressure
exerted on the buttons.
We can mix and match the function of the buttons and sticks
depending on which of the PS2 three modes of operation has
been set up (either digital, analog, or analog pressure).
In digital mode, analog sticks don’t output a value; pressure
values are also not present. Only the on/off state of the digital
buttons is outputted.
In analog mode, the digital on/off state is outputted, as well
as the analog joystick values.
In analog pressure mode, digital on/off, analog sticks, and
pressure values all are outputted.
The SPI to the host is a synchronous serial half/full duplex
communication protocol. The PS2 controller is the slave and the
host controller — in our case, the PIC microcontroller — is the
master; and generates synchronizing clock. The master PIC sends
command bytes to the PS2, and the PS2 sends data bytes back
(full duplex mode).
Commands have a three-byte header. These bytes request the
PS2 to acknowledge its current mode of operation. The PS2
responds with three data bytes indicating its current mode.
The current state of the buttons, stick, and pressure values
can be requested from the PS2 by a polling method where a
specific button value’s command is sent and the PS2 responds
with the current state.
Every command is divided into a sequence of bytes. The
header is followed by data. The digital button’s polling command,
for example, is five bytes. So, to know button states, the master
has to transmit five command bytes to the PS2; the PS2 will return
five data bytes back to the master. In contrast, the analog polling
commands consist of nine bytes.
In order to select the mode of operation, turn on/off the
vibration motors the PS2 needs to be configured (with
The general function of the PIC program is as follows:
When power is applied, the PS2 default is the digital mode.
The PIC program sends a wireless idle command to the PS2 that is
specifically used for wireless. The command consists of five bytes
1. One should plug the PS2 controller and servomotors on the
interface board before powering up. Only remove them
after turning off the board.
2. Configuration modes can be changed anytime the user
wants in normal operation. However, since the associated
mechanical hardware connected to the motors for different
modes is so different, practically speaking, a need for
changing from one mode to another won’t arise during an
operation. Mode change can be done when required
immediately at power-on, once the status LED goes on. This
will ensure that the servomotors are at the center position
when the mode is changed so an unwanted movement of
the servomotors won’t occur as a result of mode change.
3. Servomotor control is inhibited when the mode change
buttons are pressed.
62 SERVO 02.2011
and data returned is not used.
Commands to the controller should be separated by five to
10 msecs. However, there is no delay between bytes used in a
Next, the digital button’s polling command of five bytes is
sent to the PS2, for which the PS2 returns the button states in
packets of five bytes. Here, the second data byte from the PS2 is a
mode of operation byte. This byte should be $41 hex. If it isn’t,
either the PS2 is absent or is faulty. So the mode byte from the PS2
is used as a reference and benchmark for proper communication.
This command is only to make sure the PS2 is up and working.
Next, the PS2 should be configured for the proper mode of
operation. For that, the configuration enter command is given to
Once into the configuration setup, subsequent commands
such as Vibration Motors On, Pressure Values On, and Analog Lock
Mode are given to the PS2 sequentially. Once the configuration is
set up to our requirements, the exit command is given to the PS2.
Here are a few things you should know:
1. In the configuration mode, if the PS2 is not sent a
command for some time, it automatically falls out of
2. The configuration enter command length is equal to that of
the current mode of operation. For example, if the current
mode is digital, the configuration enter command will have
the same number of bytes as that of the digital polling
3. Once into configuration mode, all configuration commands
(including configuration exit commands) are nine bytes in
4. The PS2 will output the current mode in a data string
(second byte) in response to a configuration enter
command. After that, it will output configuration mode
bytes in data strings.
After configuration, a command is again set to the required
length for the analog - pressure poll command i.e., 21 bytes and
various command bytes are initialized as per the requirements.
Next, comes the servomotor control loop. Every 20 msecs, the PS2
is polled by the analog pressure poll command, and a new
servomotor value is calculated based on current button/stick
states; new values are pulsed out.
We don’t use pressure-sensitive buttons in our program.
For each command, every byte has to be per the
specifications. You will notice that for each command, command
bytes are initialized, the byte length of a command is set, and then
the SPI subroutine will be called. The SPI subroutine will return
If after configuration, the PS2 doesn’t function, it has to be
reconfigured again. So, in the servo loop, the second data byte
(mode byte) is checked every time the PS2 is polled. If that byte is
not what we expect it to be, the PS2 is reconfigured again. The
PS2 also needs to be polled for a minimum number of times in one
second period. Failing to do so will result in the PS2 going back
into the default state.
We are able to maintain a 125 kHz clock frequency for the
synchronous clock in SPI between the PIC and PS2.
turn of your moving platform. The tilt angle of the stick will
determine the speed. Two-level speed control is
Sometimes the stick doesn’t return to the neutral
position on release which may result in unwanted
movements of the servomotors. Creating a small dead
space or band around the center position of the joystick
eliminates this movement. Within this dead band, the
servomotors aren’t activated. To test this mode, I created a
quick and dirty mobile platform using two continuous
rotation (CR) servomotors and a dual servomotor bracket
(see Figure 13).
For mobile operations or if you’re just tight on space,
the PCB can be cut down (before assembly) so its footprint
is much smaller (Figure 14). The PS2 connector is secured