byuu's message board

For discussion of projects related to www.byuu.org/


1, 2  Next
A jump into hardware: Gamecube controller port 
Author Message

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post A jump into hardware: Gamecube controller port
Last weekend, I decided to jump into a hardware engineering/hacking project for the first time. Since my knowledge of electronics is rudimentary and barely functional, I figure I might as well see if anyone here wants to give me advice on what I'm doing.

The project is related to the GameBoy Advance Link cable for the GameCube. This cable communicates via the controller ports of the GameCube. At first, I just want to get regular controllers working, though: no need to worry about this link cable device yet. I have a feeling there will be a whole mess of its own there.

So far, I've ordered the following materials, most of which are scheduled to hit here near the end of the week:
  • A solderless breadboard.
  • A Teensy 3.0, which I plan to do all of the logic on. To make life easier, hopefully, I got it with pins.
  • A GameCube controller extension cable, which will be used to wire my controller up to the Teensy.

So far, I understand the following:
  • The controller port operates at 250000 hz.
  • Low bits are signaled with 75% low and 25% high, high bits 25% low and 75% high.

Naively, this starts to seem relatively simple. The 3.3v of the Teensy seems like it can power everything except for the rumble, which needs a 5v rail.

Some questions:
  • How can I approach turning signals into bits? My first thought is to simply loop, watching the pin, counting how long it's up or down and decoding from there. Is that sound?
  • I know I need a pull-up resistor for the data pin. Will the internal pull-up resistor on the Teensy be OK? Another document suggests a 1K Ohm pull-up resistor for Gamecube controllers. I have no idea what resistance the Teensy pull-up resistors have.

And of course, if anything seems like a bad idea, or is just plain wrong, I'd want to know. I'm really new to this.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup


jchadwick


Mon 28 Oct 2013, 21:04:05

Joined: Fri 10 Apr 2009, 15:00:08

Posts: 13668
Post Re: A jump into hardware: Gamecube controller port
Only thing I can tell you about is that once you plug that Teensy into the breadboard, it'll never come back out, so be very certain of where you place it.

Mon 28 Oct 2013, 21:38:27
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: A jump into hardware: Gamecube controller port
jchadwick wrote:
  • The controller port operates at 250000 hz.
  • Low bits are signaled with 75% low and 25% high, high bits 25% low and 75% high.


And default state? It's high.

jchadwick wrote:
  • How can I approach turning signals into bits? My first thought is to simply loop, watching the pin, counting how long it's up or down and decoding from there. Is that sound?
  • I know I need a pull-up resistor for the data pin. Will the internal pull-up resistor on the Teensy be OK? Another document suggests a 1K Ohm pull-up resistor for Gamecube controllers. I have no idea what resistance the Teensy pull-up resistors have.


I found a good example of how not to do it: http://www.raphnet.net/electronique/gc_n64_usb/index_en.php.

Basically, the guy loops in his main code using delay methods to measure time. When a USB interrupts hits "at the right time" he will discard data from the controller.

You should use a timer interrupt instead, periodically sample the signal, smooth it (to account for the inaccuracies between controllers for example; and sampling inaccuracies). Do all the counting relative to your sampling frequency and use a ring buffer to have code in the mainloop interpret the button press and put it into the USB stack never to be seen again.

Pull-ups for MCUs are typically in the 100 MOhms range, so you will most definitely have to use an external resistor or else you might run into high rise/fall times on your signal line.

cYa,

Tauwasser

Mon 28 Oct 2013, 22:28:56

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
Thanks, all of that makes sense.

I figure I'll probably just put the Teensy on the farthest left of the breadboard (of course along the divide - I made sure to understand how a solderless breadboard works, at least.) Any way that would backfire on me? I figure as long as it's aligned on an edge, I'll always have plenty of room for other circuits if need be.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Tue 29 Oct 2013, 00:37:32

Joined: Sat 16 Feb 2013, 07:04:31

Posts: 179
Location: Arizona
Post Re: A jump into hardware: Gamecube controller port
jchadwick wrote:
Any way that would backfire on me?


Sure, if you put the USB port facing towards the middle of the breadboard :P

Tue 29 Oct 2013, 00:43:10
User avatar

Joined: Sat 01 Dec 2012, 01:50:23

Posts: 240
Location: Oregon, USA
Post Re: A jump into hardware: Gamecube controller port
jchadwick wrote:
no need to worry about this link cable device yet. I have a feeling there will be a whole mess of its own there.

Yeah, good luck there. I'm not even sure if the link protocol has been fully RE'd yet...
jchadwick wrote:
So far, I've ordered the following materials, most of which are scheduled to hit here near the end of the week:
. . .

So far, I understand the following:
. . .


Looks good to me...
jchadwick wrote:
Naively, this starts to seem relatively simple. The 3.3v of the Teensy seems like it can power everything except for the rumble, which needs a 5v rail.

You should be able to run the motor off the 3.3V line as long as the current draw isn't too high, it'll just spin a little slower. The current draw is the only reason N64 Rumble Paks require batteries, despite running at 3V.
jchadwick wrote:
Some questions:
  • How can I approach turning signals into bits? My first thought is to simply loop, watching the pin, counting how long it's up or down and decoding from there. Is that sound?
  • I know I need a pull-up resistor for the data pin. Will the internal pull-up resistor on the Teensy be OK? Another document suggests a 1K Ohm pull-up resistor for Gamecube controllers. I have no idea what resistance the Teensy pull-up resistors have.

And of course, if anything seems like a bad idea, or is just plain wrong, I'd want to know. I'm really new to this.


A simple delay loop is incredibly inefficient, but it's dead simple, and it *does* work. The only caveat is that if a USB interrupt occurs during the delay loop, it'll screw up the timing. I'm not sure if the Teensy's USB implementation is polled or interrupt-driven, so I can't say whether or not that will be a problem. Using a timer interrupt is a much cleaner solution, but it's more complicated if you've never done interrupt-driven programming before. As for the pull-up resistors, the internal ones will probably work, I've done it on an ATmega8 without an external resistor, but the pull-up resistor values really aren't ideal for high-speed signals, you'd be better off with an external ~1.5K resistor.
byuu wrote:
Only thing I can tell you about is that once you plug that Teensy into the breadboard, it'll never come back out, so be very certain of where you place it.

That's a bit of hyperbole, you just have to be careful, and if necessary, use a screwdriver that fits in the breadboard's middle slot to leverage it out. Just be sure to alternate sides and pull it out evenly or you'll bend the pins.

Tue 29 Oct 2013, 02:58:03

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
Well, shuffle2 of Dolphin-emu says the link cable was reverse engineered already. I just want to have the ability to test everything first hand.

Also thanks for looking that over. I will try to implement it the cleaner way, but first thing I will probably do a loop to see if everything is reading properly.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Tue 29 Oct 2013, 03:04:17
User avatar

Joined: Mon 20 Apr 2009, 08:11:50

Posts: 5266
Location: 日本
Post Re: A jump into hardware: Gamecube controller port
Is there a GC controller => USB adapter driver that you could somehow reverse engineer?

_________________
CaptainJistuce: He's totally in the wrong, Kakashi's 100% in the right.
Note: The above statement is subject to act of byuu.

Wed 30 Oct 2013, 00:29:51

Joined: Fri 10 Apr 2009, 22:30:48

Posts: 3797
Location: Salem, Oregon
Post Re: A jump into hardware: Gamecube controller port
makes me wonder how the poll rates on different consoles controller ports compare. Which top 3 are the fastest?

_________________
Krita Kickstarter -- https://www.kickstarter.com/projects/kr ... erate-deve

Wed 30 Oct 2013, 11:22:16

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
panzeroceania wrote:
makes me wonder how the poll rates on different consoles controller ports compare. Which top 3 are the fastest?

Poll rates or bit rates? On the GameCube, polling rate is controlled by the console/software.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Wed 30 Oct 2013, 11:58:27

Joined: Fri 10 Apr 2009, 22:30:48

Posts: 3797
Location: Salem, Oregon
Post Re: A jump into hardware: Gamecube controller port
Both?

_________________
Krita Kickstarter -- https://www.kickstarter.com/projects/kr ... erate-deve

Thu 31 Oct 2013, 00:06:58

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
I've wired up a Gamecube controller to the board, but alas, timings look to be a serious issue.

I have no real way of telling if anything is done right. I don't have much knowledge on the topic and not a lot of equipment at my disposal. To figure out what wires corresponded to what pins on the controller, I literally just wired up a LED and brute-forced it, testing each pin and wire.

With that being said, I tried to very naively send a rumble command to the controller port. It of course did not work, after quite a while of tinkering. It became rather apparent that microsecond level timing is complicated. This Teensy 3.0 is running at 96 Mhz, double the stock clock, so I have no doubt it's fast enough. However, I worry about how much code I can actually fit into a ~1µs interrupt. Coming from a programming background, the addition of having to deal with realistic limitations is certainly a challenge.

Of course, I still don't know how to deal with interrupts on ARM at all, so I'll be playing with simpler things before I worry too much.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Fri 01 Nov 2013, 14:49:58

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
Things are coming together bit-by-bit. I hooked into the SYSTICK interrupt which I set to run at 1000000hz. This works reasonably well at 96 Mhz. Enough that I can consistently output a signal the controller seems to be able to read. I'm most definitely, 100% certain I'm getting back a correct reply, and 100% of the time I might add. Unfortunately, my teensy is getting an often jumbled interpretation of the reply... this doesn't bode well.

Here's an example. In the second line, I was holding L:
Code:
10001100010111000100010001000100010111000100010001000100010001000100010111011101110111...
10001000110111000100010001000100010111011100010001000100010001000100010111011101110111...

This likely translates to the following bits:
Code:
0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1...
0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1...


Mostly good. The documentation I was reading said the third bit should be 0, but in Dolphin-emu's source code it's marked with a question mark symbol, so I'll chalk it up as a mystery.
Here's the problem: It's not consistent.

Code:
10001000101110001000100010001000101110000000000000000000000001000100010111011101110110...
10000100010111000100010001000100010111000100010001000100010001000100010111011101110111...
10001000010111000100010001000100010111000100010001000100010001000100010111011101110111...
10001000101110001000000010000000010111000000010001000100010001000100010111011101110111...
10001000101110000000000000000000010111000100010001000100010001000100010111011101110111...
10001000101111000100010001000100010111000100010001000100010001000100010111011101110111...

Yikes. Looks like two problems: One, the timings are a bit jittery sometimes. Not a damn clue what to do there. I can probably disable more interrupts, but certainly if it were USB causing this I'd be SOL (unless putting the relevant interrupts at a lower priority was safe/effective.) Two, the segments of zeros tells me the internal pullup is probably not working well enough. Could be wrong, but it surely seems like that kind of issue.

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Fri 01 Nov 2013, 23:49:16
User avatar

Joined: Tue 02 Nov 2010, 01:00:37

Posts: 181
Post Re: A jump into hardware: Gamecube controller port
jchadwick wrote:
So far, I understand the following:
  • The controller port operates at 250khz.
  • Low bits are signaled with 75% low and 25% high, high bits 25% low and 75% high.


4 bits @ 250 kHz (4 µs) => 1 bit @ 1 MHz (1 µs)

jchadwick wrote:
I hooked into the SYSTICK interrupt which I set to run at 1Mhz.


Take a look at Nyquist Frequency (resp. Nyquist-Shannon sampling theorem). You're too slow to reconstruct your signal.

Forget about other interrupts causing this. At 96 MHz, you're too fast to care about exact sampling times in ms. So what if your ISR misses by 100 ms every so often? Won't affect the result unless you're barely making Nyquist frequency anyway.

cYa,

Tauwasser

Sat 02 Nov 2013, 01:37:59

Joined: Tue 21 Feb 2012, 05:42:15

Posts: 2564
Post Re: A jump into hardware: Gamecube controller port
It's 1 bit per 4 microseconds. I may have explained this poorly. On the other hand, looks like I've got more things to learn...

_________________
"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." --Bjarne Stroustrup

Sat 02 Nov 2013, 03:07:02
1, 2  Next

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum