nfg.forums

NFG Forums => Controller Technic => Topic started by: ulao on June 25, 2009, 10:33:19 PM

Title: Analog controller saturn unraveled.
Post by: ulao on June 25, 2009, 10:33:19 PM
Ok I read many posts in the past year on here about the mystery of the saturn analog pad ( 3d controller ). I never really got around to it until last night after doing a bit of research. I'm glad to present.. the protocol.

I was successfully able to design a usb converter to auto detect the digital and analog if any one is interested. the HEX is for an atmega style chip if anyone is interested in that.  Also note, the protocol chart I found has confidential as a water mark on it. So my guess is its SEGA property. I will not post that link unless I'm told I can, but I can jot it down for you here. Also worth pointing our, there are two places on the net with info on this beast.  One is written by a Spanish fellow attempting to type in English on a forum.  If I never read that I may have saved a few brain cells. He went by SaturnAV and from what I can tell is a very bright guy. his  English, as he admits, is just hard to follow.  He was the one that linked the Protocol chart.  The other resource was much easier to read  but had some inaccuracies. I did learn from there that a delay of 7 was needed.   I used the two to figure out this protocol on my own.  I dont think I could have done it with out, and certainly not in one night ;)

Ok so how does it work... Well there is a lot to it that simply does not need to be said.  So I will only mention what is needed.  Most of you know the pin out.
1   VCC   +5v (Out)
2   D1   Data 1
3   D0   Data 0
4   S0   Select 0
5   S1   Select 1
6   5v   +5v (Inp)
7   D3   Data 3
8   D2   Data 2
9   GND   Ground

Do not use pin 6, it is used by the console for acknowledgment ( on the analog controller ) but you do not need it! And if used wrong you could damage the controller(pulling low on it in digital mode ).

First thing is to make sure to set all data d0-d3 to input, and s1 and s0 as out. Same as you would do with a digital pad.  S1 is our clock of sorts. We bring it Hi and then low , contrary to popular belief we need 7 us waits.   s[zero] ( damn text.. )  is our latch of sorts, it starts the data moving by bringing it low, raised when finished.  s2 could be thought of as a ack, its completely not needed as I mentioned.

Protocol flow..

set switch in this order :

switch   0     0  ( used for ID data ) then delay 7us
switch   0     1  (  used for ID data ) then delay 7us

now loop 14 times alternating switch 1 ( the clock ;) )
{
delay 7us
starting with switch   0     0   ,   next cycle will be switch   0     1  ( this is the switching each time you get here to the opposite you did before 00, 10, 00, 10, ...)
[read your data, the 4 bits]
delay 7us ( yes delay again! )
}
then finish with  switch   1     1 and  delay 7us

In the loop you will get the following.

switch  pass       data

00         1          NA second part of ID data
01         2          NA //
00         3          right, left, down up ( Directional keys )
01         4          Start, A, C, B
00         5          Right shoulder, X, Y, Z
01         6          Left shoulder, 1, 1, 1 ( these 1,1,1 are some sort of analog data, I think used for the mission stick. )
00         7          X axis first 4 bits
01         8          X axis second 4 bits
00         9          Y axis first 4 bits
01         10        Y axis  second 4 bits
00         11        R_shoulder first 4 bits
01         12        R_ shoulder  second 4 bits
00         13        L_shoulder first 4 bits
01         14        L_shoulder  second 4 bits

The analog values are in revere.  for example... pass 7 is four bits hex (i.e 1110 ) but meant as 0111 you then add the next pass to it. So say you received 0x80 ( neutral) or 10000000 in binary  . pass 7 would be  0001 then you revere it. next you get 0000 on pass 8 and revere that.  Then put them together 10000000.  The data can be   FF max to 00 min and as I said 80 neutral. The triggers are the same from 0 to FF and 0 is neutral.

note: I use inline function to speed things up. but depending on your coding you may need to adjust the delays. They are consistent so make it a var so you can change it if needed )


So that is one pass, do it again to get more data; ) There we have it the protocol from the 3d controller. I hope someone will find this useful. If I learn more I will add it.

As for the mission stick as some of you are wondering, I have no idea what it does( Sorry kendrick ), but If I had one I could figure it out in no time. I think I saw a twin stick for the saturn and if so I think it just sends the second stick as the triggers, only its the same as the x,y and neutral is 0x80, but I dont have one. Some code would need to be changed but not much. Same goes for the fighting stick and gun( no idea ) I just dont have them to test with.  And some are way out of my budget. If anyone wants to lone me one I'd be happy to look at it.


Thx to those on the net that provided info to make this possible, I wish I knew more about them, but the net tends to cast anonymity  to us all.



UPDATE, this code work for a mission stick, but be sure to have a 15 ms delay between calls.







Title: Re: Analog saturn unraveled.
Post by: NFG on June 25, 2009, 11:35:24 PM
Nice work.  =D

I front-paged it, hope you don't mind.  ^_^
Title: Re: Analog saturn unraveled.
Post by: ulao on June 25, 2009, 11:47:54 PM
Nope not at all

So I had a thought? The switch on the controller is designed for analog to direction pad choosing, but I can get both data regardless.  If it werer you( whom ever ) and you had a USB adapter would you want the directions to work as the movement, or extra buttons?

I think I can allow the directional or analog for movement ( simultaneously), and  also have the directional trigger buttons. I need to look at that switch in a bit more detail but looks like I can do what ever I need with it.


UPDATE:
Ok the switch basically makes the analog a digital pad.  So I left that functionality that way it was intended, but when in analog mode the directional buttons still work, were they used in any analog games?

Title: Re: Analog controller saturn unraveled.
Post by: l_oliveira on June 26, 2009, 03:40:52 AM
I have an Mission Stick and would be willing to tinker with it if you're interested. I could "beta test" code or probe the controller if you have an idea of how we can do it.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on June 26, 2009, 10:21:27 PM
l_oliveira , thx so much . Do you have  a way to write a hex file ro an avr chip? You need an atmega 168-pu. I could also an atmega 8 but need to make a bit of modification to get that to work.  What I'd need to see is how the data come over. I dont really see me getting much done without have the stick here, but maybe you have a avr setup there?
Title: Re: Analog controller saturn unraveled.
Post by: l_oliveira on June 27, 2009, 12:17:49 AM
If I find the AVR chip for purchase I can get it. I can get ATMEGA 8 chips from a friend but it's possible that he has the bigger version too....
I know he have ATMEGA 128 chips.

And yes, due to me being forced to work with wii modchips I'm familiar with AVR programming through the SPI bus.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on June 27, 2009, 03:40:11 AM
QuoteAnd yes, due to me being forced to work with wii modchips I'm familiar with AVR programming through the SPI bus.
HA!!

Going to PM about this.


Ah,, forgot to ask before the PM, do you know anything about object dev? AKA V-USB .  If not you need to do some serious catching up before any of my code would work. It handles all the usb stuff. unless you have another means to talk to HID.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on June 29, 2009, 02:30:02 AM
I'm confused. I have a PIC microcontroller that has code to read digital Saturn pads. I believe I understand the breakdown of the analog protocol, but how can I automatically let the PIC know what kind of controller is plugged in?

I understand it has something to do with pin 6, but if I have pin 6 connected as a input on the PIC, what should I be expecting on that input if the controller is digital and if is analog.

Also Ulao, your warning about using pin 6.....I'm guessing you mean by hooking pin 6 to an output line on a microcontroller?? Do you believe having that pin read by an input would hurt it as well? Could you elaborate?

Thanx
Title: Re: Analog controller saturn unraveled.
Post by: l_oliveira on June 29, 2009, 04:13:28 AM
Waterbury:
All controllers have a set of "fixed value bits" on one of their addresses which is used by the SATURN console to identify which protocol need to be used.
His program reads that information from the PAD itself and from that it decides which program flow to follow.
Nothing too complicated, honestly.

For example, the digital PAD (simplest one) has a fixed value of 001X on it's 4th bank of 4 bits where X is the status of the L button but the other three
bits are *aways* 001. That's how the SATURN knows it's a digital pad connected.
If there were nothing connected to the port it would read 1111 all the time.

On the SATURN motherboard, the PIN 6 is connected to an input of the hitachi processor that controls the I/O. 
His warning means that you should not tie that pin to +5v on the female connector that takes the controllers as while the Digital PAD internally jumpers that pin to +5v other
pads/controllers might use it as a signal line and they could be damaged by your circuit if the female connector has it shorted to +5v.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on June 29, 2009, 05:50:13 AM
l_oliveira, pretty much answered it but I will as you asked.



The warning is that you dont want to pull low when the digital is pulling high.. if you are set that pin to output ..

BUT! you dont need pin 6 for anything at all. period!.

How to detect, simple.

The delay of 100 would only be needed if you need 3 values.

1 digital
2 analog
3 none.

If you just need digital or "else" then you dont need it. Set the switches to ( on, on ) and look at the data pins.. in ,my case
PINC>>2) == 0x3    0010
or
(PINC>>2) == 0x2) 1100

Why, so that it still works if you are pressing L

If you need the three way option, it gets a lot more confusing, let me know.




_delay_ms(100);// a delay of about 100 is needed for the saturn analog to respond.

PORTC  |= 0x3; _delay_us(7); // on  on
if( (PINC>>2) == 0x3 || (PINC>>2) == 0x2) { saturnPad=0; return 0;}; //It's a digital pad.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on June 29, 2009, 10:00:10 AM
 :D Thanx. I get it now. I plan on applying pull-up resistors to d0-d3 and now I know a tad bit more information.

Unfortunately, I don't have enough I/O pins to output the analog signal I'm capable of getting now. What sucks about being a tinkerer is your work is never done. You always find a way to improve on something after you think you're done.  :'(
Title: Re: Analog controller saturn unraveled.
Post by: ulao on June 29, 2009, 01:59:41 PM
QuoteWhat sucks about being a tinkerer is your work is never done.
- words I live by,

Good luck with it, glad you got it understood.

QuoteUnfortunately, I don't have enough I/O pins to output the analog signal I'm capable of getting now
Cant you use a serialize interface?

Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 02, 2009, 03:16:48 PM
Quote
If you need the three way option, it gets a lot more confusing, let me know.

I do.


Quote
Quote
Unfortunately, I don't have enough I/O pins to output the analog signal I'm capable of getting now
Cant you use a serialize interface?

I'm using a PIC chip with 24 I/O pins. I already have 16 dedicated to individual digital buttons. Another 6 are used for S0+S1 & D0 - D3 for Saturn control, leaving 2 I/O pins. I was planning on using those two for mode switching as plan to have both SNES and Saturn controllers controlled by the chip using multiplexing. I'll have to consider a solution, but at this point seems a little too complex without at least coming u with analog code. I have a spare PIC with the same amount of I/O pins I may dedicate for a a straight up Saturn only interface.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 03, 2009, 11:11:26 AM
Quotecoming u with analog code
not sure if you mean the controller or me LOL. You are more then welcome to pm me.

As for the 3 way detection.  I have stream lined it now... Just by luck and tested to to work ok..
this is my code..


_delay_ms(100);// a delay of about 100 is needed for the saturn analog to respond.

PORTC  |= 0x3; _delay_us(7); // on  on
if( (PINC>>2) == 0x3 || (PINC>>2) == 0x2) { saturnPad=0; return 0;}; //It's a digital pad.
PORTC &= 0x3D;_delay_us(7); // off on
if ( (PINC>>2) == 0x8 )  { saturnPad=1; } //It's a analog pad.
else    { saturnPad=-1;} //neither
return saturnPad;


the digital is easy, then you can make another switch and set for 0x8, at that point nothing will be ff I think.. either way you just else it and you have the third.. YOU NEED! the 100 wait...


BTW: PINC>>2  is my 7 bit pins register cutting off 2 bits.. so I only see the 4 inputs.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 03, 2009, 11:58:03 AM
Quote from: ulao on July 03, 2009, 11:11:26 AM
Quotecoming u with analog code
not sure if you mean the controller or me LOL. You are more then welcome to pm me.

I meant to say "coming up with analog code." It was 2:15AM and I wasn't making coherent thoughts.  :P

What I meant was I want to breadboard out a solution and come up with efficient PIC code for analog function before trying to implement the code into an existing project which is working fine and that I'd rather not mess up.

My current project interfaces a Saturn controller to a hacked up XBOX controller. To include analog control into the project would involve taking off one of the potentiometers that control the left thumbstick and feeding an analog signal to where the Pot is. The project would have to generate a stable default voltage at all times to keep the thumbstick control centered. Ideally I would just be interfacing to the Xbox without a hacked controller but I don't have the resources yet. The current configuration for digital control is working great!
Title: Re: Analog controller saturn unraveled.
Post by: l_oliveira on July 03, 2009, 12:38:28 PM
Dude ... What you're doing (If it's the classic XBOX) is exactly what ulao is doing, with small differences:

Ulao's microcontroller interfaces to a windows PC with a generic HID USB PID
XBOX controllers are USB/HID devices with different (mangled) USB PID so windows cannot detect and use them (And also make the XBOX not work with generic HID.

I think you could get a customized version of such USB interface code and make a fully functional adapter without butchering any original XBOX controllers.
But if you meant XBOX 360 then we're out of luck because with the 360 Microsoft went "apeshit" and put digital certificates and such on the authentication protocol of the device.
That makes custom XBOX360 controllers difficult to develop ... ;)
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 03, 2009, 01:33:18 PM
QuoteDude ... What you're doing (If it's the classic XBOX) is exactly what ulao is doing, with small differences:
The force is strong with this one.

I'm not sure about howthe XBOX reads the usb, or if it support a foreign usb device, but he is right. In theory, if you plug in my adapter to an xbox, you would get any  controller you ever wanted working on the xbox.. All you would need is to get the xbox to accept a HID joystick. And again, in theory it already does.

maybe here  http://spritesmods.com/?art=xpad&page=5 (http://spritesmods.com/?art=xpad&page=5)

I can get you the atmega8 code for the saturn analog.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 07, 2009, 03:30:55 PM
Quote from: l_oliveira on July 03, 2009, 12:38:28 PM
Dude ... What you're doing (If it's the classic XBOX) is exactly what ulao is doing, with small differences:

Ulao's microcontroller interfaces to a windows PC with a generic HID USB PID
XBOX controllers are USB/HID devices with different (mangled) USB PID so windows cannot detect and use them (And also make the XBOX not work with generic HID.

I think you could get a customized version of such USB interface code and make a fully functional adapter without butchering any original XBOX controllers.

I'll tell you what. Show me one hobbyist project in which a microcontroller has successfully been used to communicate as a controller to an XBOX and I'll pursue that route. I plan on attempting that next, but kind of what I meant when I said I lack the resources is that I have PIC chips and programmers at my disposal. However, I do not have the electronics yet to do what you describe.

I have to say this is the first time I've done a controller hack and it's coming out great. One step at a time.  ;)

I was inspired by Twisted Symphony's Saturn to Xbox 360 project. I used his code as a base but rewrote most of it and wrote SNES code too. I plan on making a professional looking SNES + Saturn controller box for the 360 but REALLY need this project for the original XBOX for emulators.

The Saturn Analog controller will be incorporated somehow in my next project. Thanks to ulao I now know how to ignore the analog controller that won't work anyway with my current setup.



P.S.  One last thing... in order to interface analog control with a 360 controller I have to emulate the potentiometer of a controller anyway so it is all in education which is my main goal here.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 07, 2009, 10:04:17 PM
QuoteI'll tell you what. Show me one hobbyist project in which a microcontroller has successfully been used to communicate as a controller to an XBOX and I'll pursue that route. I plan on attempting that next, but kind of what I meant when I said I lack the resources is that I have PIC chips and programmers at my disposal. However, I do not have the electronics yet to do what you describe.

I know of two projects that I have talked to the authors.  Twisted as you stated, and Toodles.  Are these not microcontrollers  ?

http://forums.shoryuken.com/showthread.php?t=131230

QuoteP.S.  One last thing... in order to interface analog control with a 360 controller I have to emulate the potentiometer of a controller anyway so it is all in education which is my main goal here.
What pot, is there one in the Xbox? Both devises are digital I thought.



Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 08, 2009, 01:08:26 PM
Quote from: ulao on July 07, 2009, 10:04:17 PM
QuoteP.S.  One last thing... in order to interface analog control with a 360 controller I have to emulate the potentiometer of a controller anyway so it is all in education which is my main goal here.
What pot, is there one in the Xbox? Both devises are digital I thought.

The Pots for the analog sticks.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 08, 2009, 09:49:32 PM
QuoteThe Pots for the analog sticks.
Oh right before the chip in your case, I'm with you.  If the pot gives you troubles,  use two leads of the pot and treat it like a variable resistor ( like the  atari paddles ).  This limits the jumpiness a bit.  You may not have any issues though.  It really depends on if the pot gets in the meg ohms or not, I tend to doubt it. But if it does you could also use a op amp to get it with in reason.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 21, 2009, 02:35:02 PM
Quote from: ulao on July 08, 2009, 09:49:32 PM
QuoteThe Pots for the analog sticks.
Oh right before the chip in your case, I'm with you.  If the pot gives you troubles,  use two leads of the pot and treat it like a variable resistor ( like the  atari paddles ).  This limits the jumpiness a bit.  You may not have any issues though.  It really depends on if the pot gets in the meg ohms or not, I tend to doubt it. But if it does you could also use a op amp to get it with in reason.


I'm new to electronics. Please correct me where I am wrong.

The way I understand how pots are used on controllers for thumbsticks and triggers is that the center pole is the signal in and the other two poles connect to ground and VREF.

When moving the wiper, resistance to ground either increases or decreases as the resistance to VREF changes proportionately. This combination acts as a voltage divider and the voltage out is fed into a ADC.

If I were to emulate a controller pot and I increase resistance between two poles for example, would I have to decrease resistance going towards the other pole? Please elaborate, I'm learning.  ;D
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 22, 2009, 12:41:01 AM
QuoteThe way I understand how pots are used on controllers for thumbsticks and triggers is that the center pole is the signal in and the other two poles connect to ground and VREF.
This is one method, a second is the VR trick like the atari did. Sort of a strange way of doing it IMO but it seems to be a trick to get a cleaner signal. The attari 2600 charges a cap the discharges it. It measures the time to complete, then by changing the resistance this time changes, thus you get a value.  

This is not needed when using a VR if you use an op amp ;)

here is some info on that atari
http://www.atariarchives.org/ecp/chapter_4.php

Quote
If I were to emulate a controller pot and I increase resistance between two poles for example, would I have to decrease resistance going towards the other pole? Please elaborate, I'm learning.
- Let me make sure I understand you right here. You want to create a circuit that emulates a pot? With out using a pot its self? So that you fake a controller in to thinking its a pot? And I'm guessing you are  going to fake it with an avr/pic  of some sorts? If so does it have a DC2anolog conversion?  Becvause AFAIK a pic or avr alone cant create an analog signal.




Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on July 22, 2009, 10:43:36 AM
Quote from: ulao on July 22, 2009, 12:41:01 AM
QuoteThe way I understand how pots are used on controllers for thumbsticks and triggers is that the center pole is the signal in and the other two poles connect to ground and VREF.
This is one method, a second is the VR trick like the atari did. Sort of a strange way of doing it IMO but it seems to be a trick to get a cleaner signal. The attari 2600 charges a cap the discharges it. It measures the time to complete, then by changing the resistance this time changes, thus you get a value.  

This is not needed when using a VR if you use an op amp ;)

here is some info on that atari
http://www.atariarchives.org/ecp/chapter_4.php

That's neat, so I'm guessing it used the duty cycle of a digital signal to determine position, kind of like a radar getting faster pings for closer objects.

Quote
Quote
If I were to emulate a controller pot and I increase resistance between two poles for example, would I have to decrease resistance going towards the other pole? Please elaborate, I'm learning.
- Let me make sure I understand you right here. You want to create a circuit that emulates a pot? With out using a pot its self? So that you fake a controller in to thinking its a pot? And I'm guessing you are  going to fake it with an avr/pic  of some sorts? If so does it have a DC2anolog conversion?  Becvause AFAIK a pic or avr alone cant create an analog signal.

I've read there are some digital pot chips that I'm going to use to fully emulate thumbstick pots.

However, right now I'm interested in emulating the extreme positions of trigger pots on a 360 controller. For example, the two states when the trigger is fully pressed, and when it is not. This way say a SNES shoulder button will act to emulate a fully pressed trigger.


Edit: My PIC chip DOES NOT have analog out ports.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on July 22, 2009, 10:04:43 PM
QuoteThat's neat, so I'm guessing it used the duty cycle of a digital signal to determine position, kind of like a radar getting faster pings for closer objects.
- Sounds like you get the idea, neat yes, old yes.. ;)

QuoteHowever, right now I'm interested in emulating the extreme positions of trigger pots on a 360 controller. For example, the two states when the trigger is fully pressed, and when it is not. This way say a SNES shoulder button will act to emulate a fully pressed trigger.
- Ok then I'm with you..

From what I know, and I could be wrong, most modern controllers user a the normal pot paradigm. All you need to be concerned with is the voltage. If you put out 5v your right 0v is left. 5v is down 0v is up. The resistance is use to create/adjust the voltage so you dont know to be worried about it.

If you need analog out you would use 4 pins 0000 and set the hex value 0-ffff and then you need another device to dc2Anolog it.
Title: Re: Analog controller saturn unraveled.
Post by: Waterbury on August 31, 2009, 01:50:53 PM
Ulao, do you know if Saturn 3d pads have a tilt sensor that I've heard they are rumored to have?
Title: Re: Analog controller saturn unraveled.
Post by: ulao on September 01, 2009, 01:36:29 AM
Not that I know of? The protocol has no room for such a thing, and my controller certainly did not give out this data.


But man that'd be cool.
Title: Re: Analog controller saturn unraveled.
Post by: Tiido Priimägi on September 01, 2009, 06:12:03 AM
I don't recall seeing any tilt sensor in my Saturn 3D pads last time I looked
Title: Re: Analog controller saturn unraveled.
Post by: kendrick on September 01, 2009, 07:22:25 AM
The 'tilt sensor' rumor is the result of a translation error. The Saturn mission stick uses hall-effect sensors to detect the angle of the large analog joystick, and one of the earliest Japanese press materials on the subject reported this as a 'tilt' function. A couple of the less well-informed American magazines confused the mission stick and the 3D Nights pad, and you can guess how the telephone game perpetuated the rumor from there. Tilt sensors, accelerometers and other motion detectors are completely absent from the Saturn 3D analog pad.

I apologize for not remembering the names of any of the periodicals in question.
Title: Re: Analog controller saturn unraveled.
Post by: ulao on September 02, 2009, 01:57:43 AM
Thx kendrick!, now I know what the extra data is for, if I ever get one of these I'll add the code for it.
Title: Re: Analog controller saturn unraveled.
Post by: kendrick on September 02, 2009, 06:58:35 AM
Ulao, are you saying that the hall effect sensors in the mission stick give different output than the normal analog pad?
Title: Re: Analog controller saturn unraveled.
Post by: ulao on September 02, 2009, 10:16:59 AM
All I'm saying is I see a place for data that i have no way to send on the 3d stick.  Its two analog bytes. I'm sure its used for various other things.