PDA

View Full Version : Problems connecting PS2 controller to Axon



JadeKnight
09-24-2009, 10:20 AM
I followed the tutorial on the SoR site (cut and paste the code) (http://www.societyofrobots.com/member_tutorials/node/200), however I can't seem to get it to work. It basically loops forever trying to confirm the controller is in analog mode (waiting for a 0x73 byte). The PS2 controller (genuine sony brand) does get put into analog mode (red led turns on), however the data received from the controller is always 0 causing the init loop to go on forever. I've tried different delays between the clock pulses, etc, but nothing helps.

Here's the real kicker, if I turn off the Axon, I correctly get the 0x73 byte (and the 0x5a 'ready' byte) EVERY TIME, along with a few frames of valid controller data before the telnet connection, and the Axon, die out. It does not appear to be random input pin behavior when the Axon is turned off.

Something about turning off the Axon causes the code to work, in it's last dying breaths... :confused:

Any help would be appreciated.

DresnerRobotics
09-24-2009, 12:08 PM
I seem to recall reading that the Axon does not run its code upon boot, rather only after a reset. Have you tried that?

JadeKnight
09-24-2009, 12:45 PM
The code is running, as it posts various status messages and each failure to 'connect' to the the PS2 controller in the telnet session (along with all the bytes received from the PS2 controller). It just doesn't get anything back from the PS2 controller until I turn off the power switch.

Could turning it off, and the slow power down due to the huge capacitor, cause the speed of the processor to go down? Like normally it's running to fast to talk to the PS2 controller at 16MHz, but as it slows down/powers down, it finds a good speed to connect? I've tried increasing the delays at various points during the TX/RX to the controller, but it didn't help, so I am not sure of this theory.

Has anyone else successfully connected a PS2 controller to an Axon, or other AVR MCU (Using C/C++)?

(Oh, and it does immediately run the program after uploading a new .hex or turning on the power. I've added a 10 second countdown at startup so I could connect a telnet session before things get going.)

DresnerRobotics
09-24-2009, 01:05 PM
Ah okay, was worth a shot. I'll get John from SoC over here and have him take a shot at this. I haven't had time to dive into the Axon platform yet, so I'm sort of shooting in the dark.

LinuxGuy
09-24-2009, 01:09 PM
I seem to recall reading that the Axon does not run its code upon boot, rather only after a reset. Have you tried that?
The default is to require pressing the user button before code starts to execute. I commented that out in Axon.c (mine is called walter.c) and now code starts at power up.



/*********ADD YOUR CODE BELOW THIS LINE **********/

//wait until user pushes button
while(!button_pressed()); // <--- comment this line out to autostart code

//reset all timers to zero
reset_timer0();
reset_timer1();
reset_timer2();
reset_timer3();
reset_timer4();
reset_timer5();

while(1)
{
control();//uncomment this for your code (and use control.c only to program)

//servo_controller();

delay_cycles(100);//an optional small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/
8-Dale

DresnerRobotics
09-24-2009, 01:34 PM
The default is to require pressing the user button before code starts to execute. I commented that out in Axon.c (mine is called walter.c) and now code starts at power up.

8-Dale

Thanks for the clarification! I couldn't find that post for the life of me.

societyofrobots
09-24-2009, 09:17 PM
I call this multi-forum double posting http://www.societyofrobots.com/robotforum/Smileys/default/tongue.gif
http://www.societyofrobots.com/robotforum/index.php?topic=9155.0
(linked for cross-reference)

DresnerRobotics
09-24-2009, 09:22 PM
I call this multi-forum double posting http://www.societyofrobots.com/robotforum/Smileys/default/tongue.gif
http://forums.trossenrobotics.com/showthread.php?t=3579
(linked for cross-reference)

Uhh? Wrong link? :P

societyofrobots
09-24-2009, 09:39 PM
oops . . . lol

http://www.societyofrobots.com/robotforum/index.php?topic=9155.0

JadeKnight
09-26-2009, 01:14 AM
Problem solved!

http://www.societyofrobots.com/robotforum/index.php?topic=9155.msg71284#msg71284

Adrenalynn
09-26-2009, 04:24 AM
That's a nice catch! Go ahead and post your code fix here as well, and then I can +rep you. :) [I like to +rep working code here. It's just my thang. And having a localized copy means that it exists as long as the forum does.]

JadeKnight
09-26-2009, 07:21 PM
I swapped the 'CLOCK HIGH' and the 'read PSdata pin and store' lines in the gameByte function, and now it works! :veryhappy:
Still not sure why turning the Axon off made it work though... :confused:

This is the fixed gameByte function (from the tutorial) that works for me, in case anyone else has troubles:



int gameByte(short int command)
{
short int i ;
delay_us(1);
short int data = 0x00; // clear data variable to save setting low bits later.
for(i=0;i<8;i++)
{
if(command & _BV(i)) sbi(PORTA, PScommand); // bit bang "command" out on PScommand wire.
else cbi(PORTA, PScommand);
cbi(PORTA, PSclock); // CLOCK LOW
delay_us(1); // wait for output to stabilise
sbi(PORTA, PSclock); // CLOCK HIGH
if((PINA & _BV(PSdata))) {sbi(data, i);} // read PSdata pin and store
//else {cbi(data, i);}
}
sbi(PORTA, PScommand);

delay_us(20); // wait for ACK to pass.

return(data);
}