Good morning, PSCD32!
Where were we?
Oh wow, yeah, this thing! It's real! How cool is that?
But now I have to make it do something other than just look amazing...
Here's my plan:
• I'm going to solder on five LEDs to the Up, Down, Left, Right and Fire2Out unidirectional outputs of the CD32 side so I can temporarily use them as indicator lights while I get the PS2 side to work. I could leave the pad until later and have them as lights by themselves, but I'm confident enough to skip the 'just get a light blinking with nothing else at all soldered on' stage (I'm still going to do it, just with the pad available).
• I'm going to power the pad from a mains USB +5V power supply. This is going to be my substitute for the CD32's power supply. I don't have a bench power supply. I'm using what claims to be an Apple-branded charger, so I hope it'll be stable. It'll surely be nicer than the CD32's twenty-five year old electronics...
• To get the USB power into the board, I'm going to chop up a USB A cable and solder the +5V and ground leads onto the board, and have a male A lead ready to plug into the charger.
• On the left side, I'm going to split, strip and solder the Playstation extension cable to the nine terminals on the board.
Here we go.
Cutting and stripping leads is easy if you're careful. You should probably tin leads before you solder them in place, but I don't always do that. These big holes I laid down are perfect for this job.
You might notice that I'm not soldering the correct leads into the correct locations according to the colours given in the USB specification. This is because this is a Wire of Lies. You can only trust reality - use your multimeter in continuity to determine which leads go to which terminals on the USB plug side, and then confirm this by using a voltage test against the exposed leads when the power has been applied.
... you should probably wear gloves for that last part if your charger isn't very trustworthy.
With the ability to apply power to the board, you can test a lot more now: you can test if the pull-up resistors are installed correctly, and whether the regulator is providing power to the PIC properly. If you had a signal analyser, you could possibly see the MCU's default internal Fast RC oscillator being fired out of its butt at the CLKO pin, pin 10. I don't know why by default the PIC clock is set to output on that pin, but it is, and it's confusing if you don't know how to turn it off and use it as GPIO.
I have gotten this wrong before - Murphy says that any component that can fit equally well turned 180 degrees probably should be turned 180 degrees. But I've stared at the Micrel datasheet for hours and I'm sure I got it right. With the Ocelot, I made a mistake with a tiny, transistor-package-like regulator, and had to cut it out and rearrange the power section to accomodate a better regulator installed correctly.
Next up, stripping the Playstation extension cable.
First, you should use it with a real Playstation to test if it works!
Here's my cut and stripped cable. I've got eight leads, as expected. The NOT CONNECTED lead isn't present.
Now I'm going to test each pin in turn to see which colour lead it goes to. Drawing lots of clear diagrams at this point is essential. You could really blow something up if you get it the wrong way around. Other people's tutorials may give you the colours to use, but as with the USB cable, everything is totally arbitrary. Even official controllers won't have the same colours for the same leads every time, I'd bet.
You Have To Test.
And there we go. Double check to make sure.
Write down the colours you get, and list them in the order that they should appear on the board.
I've decided to twist the wires together into pairs or braid them into triads before soldering them to the board. Not for signal reasons, but just because it looks nicer, and maybe it's physically stronger?
Because you haven't been a buffoon and mutilated and soldered a real Playstation pad to the board instead of an extension cable, you can use the end of the cable to test continuity - put one probe on a safety pin inserted into a hole in the socket you've attached to the PSCD32, and the other probe onto the appropriate location on the board. If you can identify the correct path from the ATTENTION pin on the socket to the corresponding pin on the PIC with the correct resistance being reported by the multimeter, everything is cool!
You should also be able to see +3.3V on the supply pin in the socket when you apply power to the board. That means that if you were to attach a controller, it would work...
That's it!
What I have now is a device, powered by USB +5V power, with a PS2 controller socket.
Plug in the USB power, turn it on. Then press the Analog button on the controller... if it lights up, the pad is being powered correctly! The default behaviour of the pad is to be in Digital mode when it powers up, so don't be surprised if the light doesn't come on by itself. Also, this means that if there's a break in one of the leads somewhere and the power is interrupted, the Analog light will go out. If it doesn't go out when you wiggle the controller a little, the leads are good and everything is shiny.
This post is not sponsored by Sony, btw. If they didn't want their name on pictures of items they manufacture, they shouldn't print their name on items they manufacture.
Right, let's unplug that for now, since I don't need the pad attached to test the board and the PICkit behaviour.
Here's my array of LEDs, reporting for duty. I've soldered the negative terminals to the CD32 interface pads. The positive leads need to be all soldered together and linked to either the +3.3V or +5V rails. This creates a sequence of (+5V)--->|---(470R)---(PIC GPIO), so I can toggle the LED on and off by setting the GPIO to open-drain low or high-Z.
The soldering work down there isn't pretty, but it's functional.
And that's all the hardware work that's needed. It's time to plug this thing into my PC, and see how much damage it does.
I've got my PICkit 2, I've got my charger, I've got my anti-static bag for the device to rest on, I've got a Playstation 2 pad.
Let's see what happens!
Aw yeah!
This is a Timer incrementing a variable at regular intervals and setting five bits of PORTB to that value.
There's also a whole bunch of other stuff involved to get this far: connecting the PICkit 2 to MPLAB X, starting a project, getting it to compile, setting the directionality of the pins, enabling/disabling remappable peripheral modules of the PIC, setting the clock speed.
This means:
• The PICkit hasn't blown up.
• My PC hasn't blown up.
• The USB power supply is working.
• The PICkit ICSP header is installed nicely.
• I inserted the ribbon connector between the PICkit and the board the right way around.
• The PICkit is communicating with the PIC correctly.
• The LEDs are the right way around.
• The LEDs, the resistors, and all the other components are somewhat-appropriate values.
• The PIC itself and all its capacitors are installed and working.
• I still know how to write code that increments a variable.
This is good news all round!
The next easiest thing is to have it read the state of the DIP switches so I can interact with the gizmo somewhat in real-time.
To do that, I activate the Change Notification Pull-ups, which act as weak pull-ups within the specified pins within the PIC. These let you attach switches or keypads to the PIC directly without having to supply external pull-up resistors. The open or closed state of the switches can be read by reading the voltage at the pin through PORTx. I mounted my DIP switches so that the open state was left and the closed state was right, purely because that matched the numbers 1, 2 and 3 on the component I bought.
A few abstractions later, and I can interrogate the switches with DIP_SWITCH_1_IS_RIGHT() macros and twiddle the lights manually. Yay!
All that's left is to work out how to communicate with the PS2 pad.