BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:23 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Tue Mar 22, 2011 11:26 pm 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
Hi. I'm looking for an example of how to hook up and program a lynxmotion PS2 controller without using the BotBoard. I have a Universal Development Board for the Atom Pro40 I am using for a Dev board rather than a BotBoard, but all the examples I can find to program the PS2 controller are for the BotBoards.

My DevBoard
http://www.basicmicro.com/USB-Universal ... _p_69.html

Note: I've already tried using the code from the BotBoard I and II examples and just plugging the controller straight to the proper ports on the Atom Pro, but I couldn't get it to work. The code I'm using is shown below, and is from an example I found online. When it runs, it outputs all 0's in the terminal. I'm pretty sure the receiver and controller are powered properly. When it first turns on, the green light is solid and the red light is blinking on the receiver. Then when I turn the controller on, the red light on the receiver goes solid. But like I said, I'm still having trouble getting the controller to output correctly, and I didn't know if it was because the code I was using was for a BotBoard II or something. My connections are to the proper pins, including a 10k pullup resistor on the DAT line. Any ideas on what the problem could be? Thanks!

Code:
DAT con P4
CMD con P5
SEL con P6
CLK con P7
;-----------------------------

index var byte
temp var byte(19)
mode var byte
Small_Motor var byte
Large_Motor var byte

;PS2Init
high CLK

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high SEL
pause 100

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high SEL
pause 1

main

;-----------PS2 Mode----------
low SEL
; asking "mode" to PS2 controller
shiftout CMD,CLK,FASTLSBPRE,[$1\8]
; reading "mode" from PS2 controller
; 73(hex) is dualshock1 (digital buttons)
; 79(hex) is dualshock2 (analog buttons)
shiftin DAT,CLK,FASTLSBPOST,[mode\8]
high SEL
;-----------------------------

pause 1

;-----------PS2 Data----------
low SEL
; asking data to PS2 controller
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8]
; reading data from controller
; (don't use a "for-next" loop, it's too slow to read PS2 data)
shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(8)\8, |
temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(18)\8]
high SEL
;-----------------------------

pause 1

;-----------PS2 Vibration motors----------
Small_Motor = 1 - Temp(1).bit5 ; Numeric right arrow button (Small Motor on/off)
Large_Motor = Temp(8) ; Analog left arrow button (Large Motor speed)

low SEL
; asking data to PS2 controller (again)
; sending at the same time the vibration motors speed to perform
; (using the previously read analog buttons position ( <- : large motor, -> : small motor )
; the more you press on these buttons, the more the corresponding motor vibrates fast
; some wireless PS2 controllers react only to the large motor command and some have no motor at all.
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8,$0\8,Small_Motor\8,Large_Motor\8]
; we don't care about reading the data from the controller here.
; so, why not use this to read PS2 data the first time? because it's not working:
; as the PS2 controller is starting to send data just after receiving the
; "shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8..."<------here
; and as we are sending after that some data for motors "... ,$0\8,temp(7)\8,temp(8)\8]"
; it's now too late to read all the data from the PS2 controller
; because there's already some bytes sent by it and lost (no buffer here).
high SEL
;-----------------------------

;-----------Basic Micro IDE terminal----------
; sending carriage return (CR = 13) and the PS2 mode(hex) to the PC
;serout S_OUT,i57600,[13, hex2 mode\2] ; Basic Micro IDE <= 02.2.1.1
;serout S_OUT,I8N1_57600,[13, hex2 mode\2] ; Basic Micro IDE <= 05.3.0.0
serout S_OUT,i57600,[13, hex2 mode\2] ; Basic Micro Pro IDE <= 08.0.1.7

for index = 1 to 18 ; temp(0) contains a dummy variable so we don't send it to the PC
; sending all the data to the PC
;serout S_OUT,i57600,[" ", dec3 temp(index)\3] ; Basic Micro IDE <= 02.2.1.1
;serout S_OUT,I8N1_57600,[" ", dec3 temp(index)\3] ; Basic Micro IDE <= 05.3.0.0
serout S_OUT,i57600,[" ", dec3 temp(index)\3] ; Basic Micro Pro IDE <= 08.0.1.7
next
;-----------------------------

goto main


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 6:32 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
One thing to check is to make sure you are passing +5v and not VIN to the PS2. You probably are as I think Vcc connections are, but...

Also try adding a pause at the bottom before you jump back up to main and see if this helps. I have found at times if you ask too quickly, it does not get any valid data. It is like the receiver is too busy responding to the requests that it does not have time to talk to the remote...

I have not looked at the schematic of the USB board, to see if there are other things those pins are connected to. You might try some different pins and see if that helps.

Kurt


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 8:31 am 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
Thanks for the quick reply Kurt. I checked and made sure there is 5V coming into the controller, and that checked out fine. I also added a pause 50 right before my goto main with no luck. Finally, I tried a few other port setups with no luck. Is there a better way to troubleshoot just that the PS2 controller and the ucontroller are seeing one another or that the individual pins are outputting correctly/at all (LED?)? Attached is a picture of my setup (now moved to pins 0-4). I've run other programs where that have proved the USB Dev board connects the pins where it says it does. Could it be a lack of pull-up resistors?


Attachments:
photo.JPG
photo.JPG [ 119.09 KiB | Viewed 570 times ]
Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 8:36 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
I do beleive you need pullups on the cmd and data pins or one or the other. Its been a while since I wired one up manually.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 8:49 am 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
So I was messing around with the pin connections, and I accidentally had the CMD wire going into the DAT pin, and the terminal ouput all high values (FF, 255). (incidentally, the DAT pin was floating) When I plugged it back in to the CMD pin, it went back to all 00s. Yes, I know crossing wires is not a good idea, but it accidentally happened and it caused a response, so I was just wondering if it might indicate any part of my problem.

Also, I have pullup resistors on the DAT and CMD pins (just added one on the CMD pin), no luck.


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 8:57 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
1ks? If 10ks use 1ks instead.And/or change to regular mode instead of fast mode on the shiftin/out commands.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 9:34 am 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
I just switched from 10k to 5k pullups (no 1ks available) and changed the code, still no luck. After programming, my receiver is just displaying solid green and red LEDs. Shouldn't the red be oscillating if it is transmitting? The only times it flashes are when I turn the PS2 controller off.


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 9:36 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
The BB2 has 1K pull-up resistors on the DAT line and the CLK line. I think it really only needs it on the DAT line as the controller will pull the DAT line down to indicate low. Could have multiple controllers (on the game console) sharing the same line. The clock line is driven by the BAP so it probably does not need one..

I am not sure if this will help or not, but here is an extract of PS2 code that is from the Arc32 Phoenix (hex) code...
Code:
;--------------------------------------------------------------------
;[InitController] Initialize the PS2 controller
;    Warning: this version has been updated to allow both XBee and
;          PS2 to control the robot... Which ever one issues a start
;         will take over until it does a stop...
;--------------------------------------------------------------------
#ifdef USEXBEE
InitPS2Controller:
#else
InitController:
#endif
;PS2 controller

RetryPs2TestInit:
  high PS2CLK
  LastButton(0) = 255
  LastButton(1) = 255
  BodyYOffset = 0
  BodyYShift = 0

  low PS2SEL
  shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8]
  shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DS2Mode\8]
  high PS2SEL
  pause 1
 
  if DS2Mode <> PadMode THEN
   low PS2SEL
   shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
   high PS2SEL
   pause 1

   low PS2SEL
   shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
   high PS2SEL
   pause 1
#if 0
   low PS2SEL
   shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
   high PS2SEL
   pause 1
#endif
   low PS2SEL
   shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
   high PS2SEL
   pause 1
#if 0
   low PS2SEL
   shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
   high PS2SEL
#endif   
   pause 1
      
   sound cSOUND,[100\4000, 100\4500, 100\5000]
   if (wDebugLevel and DBG_LVL_CONTROL) then
      hserout ["PS2: ", hex DS2Mode," ", hex  PUCR5, 13];   
   endif
   
   goto RetryPs2TestInit ;Check if the remote is initialized correctly
  ENDIF
return
;--------------------------------------------------------------------
;[ControlInput] reads the input data from the PS2 controller and processes the
;data to the parameters.
;
; Updated to handle both XBEE and PS2
;--------------------------------------------------------------------
#ifdef USEXBEE
ControlPS2Input:
#else
ControlInput:
#endif
  ; In case the controler gets out of whack double check to see if we are still in the right
  high PS2CLK   ;init clk state
  low PS2SEL
  shiftout PS2CMD,PS2CLK,LSBPRE,[$1\8]
  shiftin PS2DAT,PS2CLK,LSBPOST,[DS2Mode\8]
  high PS2SEL
  pause 1
 
  if(DS2Mode <> PadMode)then
   gosub RetryPs2TestInit   ; use secondary name so does not depend on if XBee is also defined...
  endif


  low PS2SEL
  shiftout PS2CMD,PS2CLK,FASTLSBPRE,[$1\8,$42\8]   
  shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
     DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
  high PS2SEL
  ;pause 10   


#ifdef DEBUG_PS2
  if (wDebugLevel and DBG_LVL_CONTROL) then
     fDSChanged = 0
     for iDS = 0 to 6
       if DualShock(iDS) <> DSPrev(iDS) then
          DSPrev(iDS) = DualShock(iDS)
          fDSChanged = 1
       endif
     next
     if fDSChanged then
        hserout ["DS: ", hex dsPrev(0), " ",hex dsPrev(1), " ",hex dsPrev(2), " ",hex dsPrev(3), " ",|
                 hex dsPrev(4), " ",hex dsPrev(5), " ",hex dsPrev(6), 13]
     endif
  endif
#endif   

You might check to see if any of the timings are different.

Kurt


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 9:48 am 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
So you're saying I only need a pullup resistor on the DAT line, right? Also, I pasted the code above and compiled it and came back with errors. Is there a library to include in order to execute C commands? And where are the pin definitions in that code? Also, what do you mean by checking to see if the timings are different? Thanks for all the help!


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 11:10 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
The code is just an extract from the code. It probably does not have all of the defines in it... I just put it in there so you could compare the two versions of the PS2 code for things like timing delays and which commands are sent to the PS2 to initialize it.

Yes you probably only need a pull-up on the DAT line. I have actually soldered one internal to the PS2 receiver to use with some other micro-controllers such as a Arduino Mega when the internal pull-ups were not sufficient.

Kurt


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 11:57 am 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
Any other suggestions? I'm trying to establish that there is actually data being sent and received bw the controller and receiver. Here is some code I'm using to try and just set and read the mode of the controller. Basically I'm trying to set the controller to be configurable, set and lock analog mode, exit config, and poll to see what mode it is in. When I run the code, the controller does get set to analog and is locked, but when I try to read the mode from the controller using the shiftin command, I just get "0". Am I doing something wrong in my shiftin command or is there a problem with outputting the controller's shifted in values using the serial command?

;PS2 Controller / BotBoard II
DAT con P16
CMD con P17
SEL con P18
CLK con P19
mode var byte
;PS2Init
main
high CLK

low SEL
shiftout CMD,CLK,LSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high SEL
pause 1

low SEL
shiftout CMD,CLK,LSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high SEL
pause 1

low SEL
shiftout CMD,CLK,LSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high SEL
pause 1

;----Retreive Mode and output serially-----
low SEL
; asking "mode" to PS2 controller
shiftout CMD,CLK,LSBPRE,[$1\8]
; reading "mode" from PS2 controller
shiftin DAT,CLK,LSBPOST,[mode\8]
serout s_out,i57600,[hex mode,13]
high SEL

goto main


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 12:26 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
If it were me, I would be hooking up my logic analyzer to see what is going out or in from the 4 pins... Maybe if I get a chance later today or tomorrow, I will get out my Bap40 on the Lab board and try it...

Kurt


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 1:01 pm 
Offline
Citizen

Joined: Tue Mar 22, 2011 11:21 pm
Posts: 9
I wish I could, but I don't have a logic analyzer... :(


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 1:11 pm 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
Kurt,

Guess who just got an old HP Logic Analyzer given to him! I haven't even power it up yet...


Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: Program PS2 controller to BAP40 w/o Bot Board?
PostPosted: Wed Mar 23, 2011 7:13 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
I pulled out my Bap40 on the Lab board. I connected up the PS2 pins on pins 24-27.
Code:
DAT con P24
CMD con P25
SEL con P26
CLK con P27

I used the first program you posted, I used jumpers on the lab board to connect up the correct pins. I connected a 1K resistor to pin 24 and VCC and the program worked: I get results like:

Code:
79 255 255 128 059 255 104 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 058 255 128 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 145 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 128 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 128 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 108 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 069 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 057 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 057 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 128 128 059 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 114 128 062 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 059 128 092 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 059 128 092 000 000 000 000 000 000 000 000 000 000 000 000 000
79 255 255 000 049 128 129 000 000 000 000 000 000 000 000 000 000 000 000

So not sure what to tell you.
Kurt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO