Home

Saturday, March 27, 2010

Set PS1 Controller as PSP Controller by ACIDMODS

Soldering to the Powerboard

For the X [] /\ and O buttons, I found it easiest to solder through the vias on the powerboard. If you use 30awg wire you can run the wires under the board and poke the wire up through the holes, then just apply a little solder and trim away any excess wire. For the button bar connections it is similar, except these are blind vias, so you have to go through the top.



The picture below shows the connector pinout for the cable that links the powerboard and motherboard. A good solder point for the right trigger button can be found at one end of this connector, as well as alternative points for the other powerboard connections.




Soldering to the D-pad

I use a cheap ($15 at RadioShack) "helping hands" soldering clamp that is very useful for this type of precise work. It has a set of gator clips and a magnifying glass on adjustable arms, plus a soldering iron holder that I continually burn myself on.

To begin, clean the pins on the back of the connector with some rubbing alcohol. Next apply a little flux to the pins you are going to be soldering to. Because the pins are so small and close together, I decided not to add any solder to them directly, as it is very easy to bridge them with excess solder. So for each of the five points this was the basic procedure:

•   Strip a short amount at the end of the wire
•   Dip the stripped end in flux
•   Melt a small amount of solder onto iron tip
•   Touch the tip of the wire to the iron to transfer a small amount of solder
•   Dip tinned wire end back into flux again
•   Clean all excess solder f-rom iron tip
•   Hold the wire firmly in place against connector pin with tweezers
•   Carefully touch iron tip to the back of the wire (the flux on the wire and pin should help the solder bond quickly with the pin)
•   Hold the wire very still for a couple seconds while the solder cools
•   Inspect under magnification to ensure there is a good bond and no bridged pins

Once all the wires are soldered its a good idea to check everything again with a multimeter, then adjust your wires so they will not interfere with the fit of other components (picture 2). I applied a little superglue to the wires to secure them to each other and keep them in shape.




Soldering to the Power Switch

This may be useful if you have a broken power switch and want to send the On/Off/Standby and Hold functions out to an external controller or switch. The switch basically works like the other buttons and activates these functions by grounding pins 1, 3, or 4 to pin 2. The power on/off and standby functions are all activated by pin 4 when grounded to pin 2 (power off or standby is determined by how long the switch is held in position.)




Analog Stick Contacts

The joystick contacts on the motherboard can be wired to external potentiometers to provide analog input. If you aren't familiar with how this type of potentiometer based joystick works, here is a basic summary.

Potentiometers are variable resistors, inside them is a resistive material with three pins connected to it. On either end of the resistive material are the power and ground pins, these typically remain at a constant voltage. The third pin is called the wiper, this is just a piece of metal that can move along the resistive material (in this case the wiper is attached to the arm of the joystick). As the wiper moves closer to ground the voltage read from this pin approaches 0, as it moves closer to the power input the wiper voltage approaches whatever the supply voltage is. When the wiper is directly in the middle, its voltage will be half of the input voltage (in accordance with Ohm's law). By reading the voltage on the wiper pin, the psp is able to determine the position of the joystick at any time.

Two different examples for providing analog input are shown in this post, one using an MCP4251 digital potentiometer, and another using hardwired Ps1 controller joysticks. When looking at your PSP motherboard in the way it would normally be oriented while using the PSP, the analog connections are as follows:

  [[ ]  ]  =GND
[  [ ]]    =X-Axis
  [[ ]]    =+2.5v
[  [ ]]    =Y-Axis

The 2.5v supply to the joystick is not constant, but pulsed for approximately 200µs at 130Hz, this can be seen in the oscilloscope view below. These 2.5v pulses are only present when the running application requires input from the joystick, otherwise the joystick supply will be at a constant 0v.



Using a Microcontroller to Interface a Ps1/Ps2 controller to the PSP

The following code written for the ATmega168 microcontroller (should also work with the mega48 and 88) allows a Ps1/Ps2 controller to be used to control a PSP through wires soldered to the points shown in the images above. An MCP4251 digital potentiometer is also used to provide analog input. The benefit to this approach is that any Ps1/Ps2 controller can be used without having to modify the controller in any way, so wireless controllers can also be used. I still need to draw up a connection schematic and write a proper description of this, but for now here is the code.

Code: [Select]
/* MCP4251 8-bit SPI digital potentiometer, ATmega168 *-bit microcontroller */

#include
#define F_CPU 8000000UL
#include
#include
#include

#define LED_PORT      PORTC   // port, data direction, and input register definitions
#define LED_DDR         DDRC
#define ATTENTION_PORT      PORTC
#define   ATTENTION_DDR      DDRC
#define CS_PORT         PORTC
#define CS_DDR         DDRC
#define BUTTON0_PIN      PIND

#define PSP_CROSS      PC1   // I/O pin definitions
#define   PSP_SQUARE      PC2
#define   PSP_TRIANGLE      PD2
#define   PSP_CIRCLE      PD3
#define   PSP_UP         PD4
#define PSP_DOWN      PD5
#define PSP_LEFT      PD6
#define PSP_RIGHT      PD7
#define PSP_START      PB0
#define PSP_SELECT      PB1
#define PSP_HOME      PB6
#define PSP_L1         PB7
#define PSP_R1         PC0
#define   STATUS_LED_GREEN   PC5   // green LED cathode on PC5; indicates psx controller connected
#define COMMAND         PB3   // SPI MOSI; sends commands f-rom AVR to DSC
#define DATA         PB4   // SPI MISO; receives incoming data f-rom DSC; 1k external pull-up resistor required
#define CLOCK         PB5   // SPI SCK; serial clock controlled by AVR, DATA is read on rising edge
#define ATTENTION      PC3   // initiates and closes each data packet transmission
#define   CS         PC4   // chip select for MCP4251
#define SS         PB2   // SPI slave select pin; set as output to ensure AVR remains SPI master
#define BUTTON0         PD1   // button to connect/disconnect potentiometer terminals within the MCP4251

#define   PS_SELECT      0   // psx_data[0] byte
#define   PS_L3         1
#define   PS_R3         2
#define   PS_START      3
#define   PS_UP         4
#define   PS_RIGHT      5
#define   PS_DOWN         6
#define   PS_LEFT         7

#define   PS_L2         0   // psx_data[1] byte
#define   PS_R2         1
#define   PS_L1         2
#define   PS_R1         3
#define   PS_TRIANGLE      4
#define   PS_CIRCLE      5
#define   PS_CROSS      6
#define   PS_SQUARE      7

#define Y_POT_ADDRESS      0x00   // MCP4251 wiper 0 register address (datasheet p.48)
#define X_POT_ADDRESS      0x10   // MCP4251 wiper 1 register address (datasheet p.48)
#define TCON_ADDRESS      0x40   // MCP4251 terminal control register (datasheet p.35)
#define TCON_CONNECT_ALL   0xFF   // connect all six potentiometer terminals within the MCP4251 (datasheet p.36)
#define TCON_DISCONNECT_ALL   0x88   // disconnect all six potentiometer terminals within the MCP4251 (datasheet p.36)

/* SR0 (status register 0) bit defines */
#define   DSC_CONNECT_STATUS_BIT   0
#define TCON_CONNECT_STATUS_BIT   1
#define BUTTON0_STATUS_BIT   2

//SPE enables SPI hardware; DORD sets data order to LSB first; MSTR selects master mode; CPOL sets clock polarity (high when idle)
//CPHA selects data setup on leading (falling) edge of clock, read on trailing (rising) edge; SPR1, SPI2X sets clock frequency prescale factor at 32 (250kHz clock)
#define PSX_SPI_CONFIG      SPCR = 0x7E;\
            SPSR |= _BV(SPI2X);
 
//SPE enables SPI hardware; DORD low sets data order to MSB first; MSTR selects master mode; CPOL low sets clock polarity (low when idle)
//CPHA low selects data setup on trailing (falling) edge of clock, read on leading (rising) edge; SPR1, SPI2X sets clock frequency prescale factor at 32 (250kHz clock)
#define MCP4251_SPI_CONFIG   SPCR = 0x52;\
            SPSR |= _BV(SPI2X);

// macro for mapping button presses f-rom psx controller to psp
#define MAP_DIGITAL_CONTROL(in_byte, in_bit, out_byte, out_bit){\
            (~in_byte & _BV(in_bit)) ? (out_byte &= ~_BV(out_bit)) : (out_byte |= _BV(out_bit));\
   }

/* init() sets all registers and enables necessary interrupts */
void init(void){

   /*Set pin I/O registers*/
   DDRB |= _BV(SS) | _BV(COMMAND) | _BV(CLOCK) | _BV(PSP_START) | _BV(PSP_SELECT) | _BV(PSP_HOME) | _BV(PSP_L1);
   DDRC |= _BV(STATUS_LED_GREEN) | _BV(ATTENTION) | _BV(CS) | _BV(PSP_R1) | _BV(PSP_CROSS) | _BV(PSP_SQUARE);
   DDRD |= _BV(PSP_TRIANGLE) | _BV(PSP_CIRCLE) | _BV(PSP_UP) | _BV(PSP_DOWN) | _BV(PSP_LEFT) | _BV(PSP_RIGHT);
 
   PORTD |= _BV(PSP_TRIANGLE) | _BV(PSP_CIRCLE) | _BV(PSP_UP) | _BV(PSP_DOWN) | _BV(PSP_LEFT) | _BV(PSP_RIGHT) | _BV(BUTTON0);
   PORTC |= _BV(STATUS_LED_GREEN) | _BV(ATTENTION) | _BV(CS) | _BV(PSP_R1) | _BV(PSP_CROSS) | _BV(PSP_SQUARE);
   PORTB |= _BV(SS) | _BV(COMMAND) | _BV(CLOCK) | _BV(PSP_START) | _BV(PSP_SELECT) | _BV(PSP_HOME) | _BV(PSP_L1);
}

/* Core AVR-DSC send/receive communication function; takes command_byte, returns single data byte f-rom controller. */
uint8_t psx_comm(uint8_t command_byte){

   SPDR = command_byte;         // Write command byte to SPI data register to begin transmission (pg. 175)
   while(!(SPSR & _BV(SPIF)));      // Conditional loop to prevent write collision
   _delay_us(30);            // Delay between byte transmissions
   return(SPDR);            // Return byte f-rom controller in shift register receive buffer (pg. 175)
}

/* AVR-MCP4251 write command plus data to MCP4251 register */
void write_mcp4251_reg(uint8_t register_address, uint8_t data){
 
   CS_PORT &= ~_BV(CS);      // lower MCP4251 chip select line
   _delay_us(2);         // delay required by datasheet
   SPDR = register_address;   // write first 8-bit command+address prefix
   while(!(SPSR & _BV(SPIF)));   // wait for transmission complete flag to set
   SPDR = data;         // write data for x-axis potentiometer
   while(!(SPSR & _BV(SPIF)));   // wait for transmission complete flag to set
   _delay_us(2);         // delay again for no good reason
   CS_PORT |= _BV(CS);      // return chip select line high
}

/* Functions for remapping buttons between controllers */
void OR_map(uint8_t source_byte, uint8_t destination_byte, uint8_t source_bit, uint8_t destination_bit){

   if(~source_byte & _BV(source_bit))
      destination_byte &= ~_BV(destination_bit);
   }

/* Function to simplify configuration of psx controller; requires 4 command bytes, loop_bytes sets number of bytes following the default 6 */
uint8_t config_comm(uint8_t byte2, uint8_t byte4, uint8_t byte5, uint8_t byte6, uint8_t loop_bytes){

   uint8_t config_id = 0x00;
   ATTENTION_PORT &= ~_BV(ATTENTION);
 
   _delay_us(16);

   psx_comm(0x01);
   config_id = psx_comm(byte2);
   psx_comm(0x00);
   psx_comm(byte4);
   psx_comm(byte5);
   psx_comm(byte6);

   for(uint8_t x = 0; x < loop_bytes; x++)
      psx_comm(0x00); 
     
   _delay_us(16);

   ATTENTION_PORT |= _BV(ATTENTION);
   return(config_id);
}

int main(void){

   uint8_t psx_data[6];         // array stores data f-rom psx controller
   uint8_t SR0 = 0x00;         // status register 0
   uint8_t   psx_config_counter = 0x00;   // counter to increment psx controller config sequence
   uint8_t psx_config_id = 0x00;      // mode ID given by psx controller, 0x41 = digital, 0x73 = analog
   uint8_t left_analog_x = 0x80;
   uint8_t left_analog_y = 0x80;
   uint8_t right_analog_x = 0x80;
   uint8_t right_analog_y = 0x80;
 
   init();                     // set important AVR configuration registers
   _delay_ms(200);
   MCP4251_SPI_CONFIG;               // configure AVR SPI registers for MCP4251 communication
   write_mcp4251_reg(TCON_ADDRESS, TCON_CONNECT_ALL);   // initialize MCP4251 by setting TCON to connect all potentiometer terminals internally
   SR0 |= _BV(TCON_CONNECT_STATUS_BIT);
   _delay_us(16);

   /* Infinite while loop*/
   while(1){

      psx_data[0] = 0xFF;      // reset data variables to inactive values
      psx_data[1] = 0xFF;
      left_analog_x = 0x80;
      left_analog_y = 0x80;
      right_analog_x = 0x80;
      right_analog_y = 0x80;

      PSX_SPI_CONFIG;         // configure AVR SPI registers for psx communication
      _delay_us(4);

      if(SR0 & _BV(DSC_CONNECT_STATUS_BIT)){         // test if a controller is connected and configured
         ATTENTION_PORT &= ~_BV(ATTENTION);      // begin communication with psx controller by lowering select line
         _delay_us(16);               // required delay between select line low and data transmission


         psx_comm(0x01);               // byte 0; standard controller address header
         psx_config_id = psx_comm(0x42);         // byte 1; standard polling command
                if(psx_comm(0x00) == 0x5A){              // byte 2; standard header, data reply should always be 0x5A, tests connection status

                 for(uint8_t x = 0; x < ((psx_config_id & 0x0F) << 1); x++)    // loop loads data array with mode specific byte count
                       psx_data[x] = psx_comm(0x00);
             
                 _delay_us(16);                      // delay following data transmission before ATTENTION returns high

                   ATTENTION_PORT |= _BV(ATTENTION);         // end communication with DSC
                 LED_PORT &= ~_BV(STATUS_LED_GREEN);       // green status LED on (controller connected)
       
            if(psx_config_id == 0x73){      // if psx controller is in analog mode...
                    right_analog_x = psx_data[2];   // copy x/y axis values f-rom joysticks into variables
               right_analog_y = psx_data[3];
               left_analog_x = psx_data[4];
               left_analog_y = psx_data[5];
                }
              }
              else{
                 SR0 &= ~_BV(DSC_CONNECT_STATUS_BIT);     // if 0x5A not received in command byte 2, controller != connected; set status register
                   LED_PORT |= _BV(STATUS_LED_GREEN);       // green status LED off (controller not connected)
              }
      }

          if(!(SR0 & _BV(DSC_CONNECT_STATUS_BIT))){
              // this switch handles the configuration commands to send over six main loops when the DSC is first plugged in
              switch(psx_config_counter){
                    case    0:    psx_config_id = config_comm(0x42, 0x00, 0x00, 0x00, 0x00); psx_config_counter = 1; break; // standard initial polling request, 5 bytes total
                     case    1:    psx_config_id = config_comm(0x43, 0x01, 0x00, 0x00, 0x00); psx_config_counter = 2; break; // enter config mode, 5 bytes total
                     case    2:    psx_config_id = config_comm(0x44, 0x01, 0x03, 0x00, 0x03); psx_config_counter = 3; break; // enable analog mode and lock controller, 9 bytes total
                     case    3:    psx_config_id = config_comm(0x4D, 0x00, 0x01, 0xFF, 0x03); psx_config_counter = 4; break; // vibration motor control byte mapping
                     case    4:    psx_config_id = config_comm(0x43, 0x00, 0x5A, 0x5A, 0x03); psx_config_counter = 5; break; // exit config mode
                    case    5:    psx_config_id = config_comm(0x42, 0x00, 0x00, 0x00, 0x03); SR0 |= _BV(DSC_CONNECT_STATUS_BIT); psx_config_counter = 0; break;
                  }
                 // test will reset configuration switch if a communication error occurs or controller is disconnected before full configuration is complete
              if((psx_config_id == 0x00) || (psx_config_id == 0xFF)){ psx_config_counter = 0; SR0 &= ~_BV(DSC_CONNECT_STATUS_BIT);}
          }

     
      MCP4251_SPI_CONFIG;               // configure AVR SPI registers for MCP4251 communication
      _delay_us(4);
      write_mcp4251_reg(X_POT_ADDRESS, left_analog_x);   // write value f-rom psx controller left analog x-axis to wiper 0 register in MCP4251
      _delay_us(2);
      write_mcp4251_reg(Y_POT_ADDRESS, left_analog_y);   // write value f-rom psx controller left analog y-axis to wiper 1 register in MCP4251
     
      MAP_DIGITAL_CONTROL(psx_data[0], PS_UP, PORTD, PSP_UP);      // map digital button presses f-rom psx controller to psp
      MAP_DIGITAL_CONTROL(psx_data[0], PS_DOWN, PORTD, PSP_DOWN);   // all buttons are active low
      MAP_DIGITAL_CONTROL(psx_data[0], PS_LEFT, PORTD, PSP_LEFT);
      MAP_DIGITAL_CONTROL(psx_data[0], PS_RIGHT, PORTD, PSP_RIGHT);
      MAP_DIGITAL_CONTROL(psx_data[0], PS_SELECT, PORTB, PSP_SELECT);
      MAP_DIGITAL_CONTROL(psx_data[0], PS_START, PORTB, PSP_START);
      MAP_DIGITAL_CONTROL(psx_data[0], PS_R3, PORTB, PSP_HOME);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_CROSS, PORTC, PSP_CROSS);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_SQUARE, PORTC, PSP_SQUARE);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_TRIANGLE, PORTD, PSP_TRIANGLE);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_CIRCLE, PORTD, PSP_CIRCLE);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_R1, PORTC, PSP_R1);
      MAP_DIGITAL_CONTROL(psx_data[1], PS_L1, PORTB, PSP_L1);

      if(~psx_data[1] & _BV(PS_L2)){ (PORTD &= ~_BV(PSP_LEFT));}   // map secondary shoulder buttons to left/right directional buttons
      if(~psx_data[1] & _BV(PS_R2)){ (PORTD &= ~_BV(PSP_RIGHT));}
      if(right_analog_x > 178){ (PORTD &= ~_BV(PSP_CIRCLE));}      // define right analog dead zone and map movements to digital buttons
      else if(right_analog_x < 78){ (PORTC &= ~_BV(PSP_SQUARE));}
      if(right_analog_y > 178){ (PORTC &= ~_BV(PSP_CROSS));}
      else if(right_analog_y < 78){ (PORTD &= ~_BV(PSP_TRIANGLE));}

      // the following checks for a single press of button0 and toggles the connection of the potentiometer terminals within the MCP4251
          if(~BUTTON0_PIN & _BV(BUTTON0)){
              if(!(SR0 & _BV(BUTTON0_STATUS_BIT))){          // BUTTON0_STATUS_BIT indicates whether or not the button is already being pressed
                      if(SR0 & _BV(TCON_CONNECT_STATUS_BIT)){         // if poterntiometer terminals are already connected...
               write_mcp4251_reg(TCON_ADDRESS, TCON_DISCONNECT_ALL);
                             SR0 &= ~_BV(TCON_CONNECT_STATUS_BIT);   // ...disconnect potentiometer terminals and set status bit
            }
                      else if(!(SR0 & _BV(TCON_CONNECT_STATUS_BIT))){ // if poterntiometer terminals are already disconnected...
               write_mcp4251_reg(TCON_ADDRESS, TCON_CONNECT_ALL);
                             SR0 |= _BV(TCON_CONNECT_STATUS_BIT);    // ...connect potentiometer terminals and set status bit
            }
                 SR0 |= _BV(BUTTON0_STATUS_BIT);              // set BUTTON0_STATUS_BIT flag so we know the button press has been recognized
              }
          }

      if(BUTTON0_PIN & _BV(BUTTON0))               // if the button is high (default state)...
              SR0 &= ~_BV(BUTTON0_STATUS_BIT);         // ...reset BUTTON0_STATUS_BIT to wait for next press
     
   _delay_ms(15);            //delay for roughly 60 samples per second
     
   } // while(1)


} // main()


Hardwiring a Ps1 Controller

As an alternative to reading and interpreting data f-rom the controller, it can also be modified to act as a set of independent switches with parallel output. This will result in the controller no longer being usable as a playstation controller, so it is only recommended for controllers which are already defective. The following image shows the pinouts for rewiring a Sony SCPH-1200 Ps1 Analog Controller for a point to point connection to the PSP, with the addition of a modified right analog stick (A2D mod) to mimic the X, [], /\, and O buttons.



The Ps1 controller and the PSP differ slightly in the way the analog stick is grounded, so some simple modifications will need to be made to the controllers PCB for it to work. This may involve cutting traces, desoldering components, or bridging points with additional wires. It’s difficult to be specific here because Sony seems to change the PCB layouts on their controllers a lot. What is important is that the pins on the potentiometers (3 on each) are wired and grounded according to the diagrams above. Keep checking all of the pot pins with a multimeter, and make any necessary modifications until everything is correct.

The points labeled A1, A2, and A3 on the left analog stick will be wired to three of the four contacts on the PSPs Analog nub or the motherboards analog contact pads. The remaining contact should be grounded with the other buttons. So, when looking at your PSP motherboard in the way it would normally be oriented while using the PSP, the analog connections are as follows:

  [[ ]  ]  =GND
[  [ ]]    =X-Axis (A1)
  [[ ]]    =+2.5v  (A2)
[  [ ]]    =Y-Axis (A3)

The wiring of the right analog stick shown in the diagram is optional, and allows it to perform the same function as the “Razor Nub” on the PSP. This will require some additional work beyond just rewiring the solder points, to make the potentiometers function like simple momentary switches. You will need to desolder the right analog stick, remove the potentiometers, and cut away part of the conductive track inside them. This is all much easier than it sounds, and TimmyDX has made an excellent video tutorial on how to do it.

As I mentioned earlier there were many different hardware revisions to these controllers, so yours may not look exactly like the picture, but the basic ideas here should be applicable for most Ps1 analog controllers. I think it is safe to assume that the pin order on the ribbon cable connector should be the same for all Ps1 controllers which use the membrane button contacts, but I am not 100% sure of this. The early Ps1 Analog controllers have the button contacts on a solid PCB, in which case these pinouts do not apply.