Help for ps2 controle programme

Hello,
I’m french: sorry for my english.
I try to make a robot like johnny 5 ( bigger).
I use a basic atom pro 28 and boatboard II .
It’s my first programme and i’ve a lot of trouble:
I want to commande my tracks with the pad of the PS2 joystick.
All work very well with the lynxmotion programme .
My prog:

[code]DAT con P12
CMD con P13
SEL con P14
CLK con P15

temp var byte
buttons var word
Lastbuttons var word

bpress1 var bit
bpress2 var bit

rhori var byte
rvert var byte
lhori var byte
lvert var byte

Dpad_haut var bit
Dpad_droite var bit
Dpad_gauche var bit
Dpad_bas var bit

moteur_droit var word
moteur_gauche var word
acceleration var word
increment var word
incrementation con 30
minvitesse con 2250
maxvitesse con 750

low p0
low p1
low p2
low p3
low p10
low p11

moteur_droit = 1500
moteur_gauche = 1500

high CLK

sound 9, [100\880, 100\988, 100\1046, 100\1175]

main

gosub get_PSX_data

increment = - acceleration

if Dpad_haut=1 and (Lastbuttons.bit4 = 0) then
	moteur_droit=(1500-acceleration) min maxvitesse
	moteur_gauche=(1500-acceleration) min maxvitesse
	sound 9, [100\880]:pause 10
	increment = incrementation;
endif

if dpad_bas=1 and (Lastbuttons.bit6 = 0) then
	moteur_droit=(1500+acceleration) max minvitesse
	moteur_gauche=(1500+acceleration) max minvitesse
	increment = incrementation;
endif

if  dpad_gauche=1 and (Lastbuttons.bit7 = 0) then
	moteur_droit=(1500+acceleration) max minvitesse
	moteur_gauche=(1500-acceleration) min maxvitesse
	increment = incrementation;
endif

if  dpad_droite=1 and (Lastbuttons.bit5 = 0) then
	moteur_droit=(1500-acceleration) min maxvitesse
	moteur_gauche=(1500+acceleration) max minvitesse
	increment = incrementation;
endif

acceleration = acceleration + increment

pulsout 0,(moteur_droit*2)					
pulsout 1,(moteur_gauche*2)	

pause 20
goto main

get_PSX_data

Lastbuttons = buttons
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]						
shiftin DAT,CLK,FASTLSBPOST,[temp\8,buttons.LOWBYTE\8,buttons.HIGHBYTE\8,rhori\8,rvert\8,lhori\8,lvert\8]								
high SEL
pause 1

buttons = buttons ^ $FFFF
	
	Dpad_haut 		= Buttons.bit4
	Dpad_droite 	= Buttons.bit5
	Dpad_bas 		= buttons.bit6
	Dpad_gauche 	= Buttons.bit7

return
[/code]

Could you help me for understand why it don’t work
thank
David

A good place to start is to tell us what you mean by, it doesn’t work. Can you go into more detail as to what it does or does not do. We need more information.

viewtopic.php?f=32&t=6286

When i push the pad_hight i heard one bip but the motors doesn’t work.
If i put Lastbuttons.bit4 = 1 , i heard multiple bips but anythink for the motors.
thank

All my connections like this:
lynxmotion.com/images/html/build138.htm

Ah… The problem is the pulsout for Atom Pro is 0.5uS. So…

pulsout 0,1500 makes a pulse that is 750uS, not 1500uS.

[code]pulsout Pulse length

500uS 1000
1500uS 3000
2500uS 5000[/code]

Yes it’s for that i x2 for
pulsout,(moteur_droit*2)
Or i don’t understand what you want to explain.

Yep, I missed it, you have it right. Not sure what the problem is, sorry

Perhaps you could send some data to the terminal to see what values are being sent to the pulsout part of the code.

I have make some little change (little bug).But it doesn’t work anymore.
The terminal :
500 500 000 000
500 500 000 000
push hight pad
500 500 001 000
500 500 001 000
Any change of the value moteur_droit ou moteur_gauche
if someone can help me,thank.

[code]DAT con P12
CMD con P13
SEL con P14
CLK con P15

temp var byte
buttons var word
Lastbuttons var word

bpress1 var bit
bpress2 var bit

rhori var byte
rvert var byte
lhori var byte
lvert var byte

Dpad_haut var bit
Dpad_droite var bit
Dpad_gauche var bit
Dpad_bas var bit

moteur_droit var word
moteur_gauche var word
acceleration var word
increment var word
incrementation con 30
minvitesse con 2250
maxvitesse con 750

low p2
low p3
low p10
low p11

moteur_droit = 1500
moteur_gauche = 1500

high CLK

sound 9, [100\880, 100\988, 100\1046, 100\1175]

main
serout S_OUT,i57600,[dec3 moteur_droit\3," “,dec3 moteur_gauche\3,” “,dec3 dpad_haut\3,” “,dec3 dpad_bas\3,” ", 13]
gosub get_PSX_data

increment = - acceleration

if Dpad_haut=1 and (Lastbuttons.bit4 = 0) then
	sound 9, [100\880]
	moteur_droit=(1500-acceleration) min maxvitesse
	moteur_gauche=(1500-acceleration) min maxvitesse
	increment = incrementation;
endif

if dpad_bas=1 and (Lastbuttons.bit6 = 0) then
	moteur_droit=(1500+acceleration) max minvitesse
	moteur_gauche=(1500+acceleration) max minvitesse
	increment = incrementation;
endif

if  dpad_gauche=1 and (Lastbuttons.bit7 = 0) then
	moteur_droit=(1500+acceleration) max minvitesse
	moteur_gauche=(1500-acceleration) min maxvitesse
	increment = incrementation;
endif

if  dpad_droite=1 and (Lastbuttons.bit5 = 0) then
	moteur_droit=(1500-acceleration) min maxvitesse
	moteur_gauche=(1500+acceleration) max minvitesse
	increment = incrementation;
endif

acceleration = acceleration + increment

pulsout 0,(moteur_droit*2)					
pulsout 1,(moteur_gauche*2)	

pause 20
goto main

get_PSX_data

Lastbuttons = buttons
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]						
shiftin DAT,CLK,FASTLSBPOST,[temp\8,buttons.LOWBYTE\8,buttons.HIGHBYTE\8,rhori\8,rvert\8,lhori\8,lvert\8]								
high SEL
pause 1

buttons = buttons ^ $FFFF
	
	Dpad_haut 		= Buttons.bit4
	Dpad_droite 	= Buttons.bit5
	Dpad_bas 		= buttons.bit6
	Dpad_gauche 	= Buttons.bit7

return

[/code]

i have change my prog now it work,but i don’t know how do to put the motors=1500 when you push any buttons of the pad:
Thank for your help

[code]DAT con P12
CMD con P13
SEL con P14
CLK con P15

temp var byte
buttons var word
Lastbuttons var word

bpress1 var bit
bpress2 var bit

rhori var byte
rvert var byte
lhori var byte
lvert var byte

Dpad_haut var bit
Dpad_droite var bit
Dpad_gauche var bit
Dpad_bas var bit

moteur_droit var word
moteur_gauche var word
acceleration var word
minvitesse con 2250
maxvitesse con 750

low p2
low p3
low p10
low p11

moteur_droit = 1500
moteur_gauche = 1500

high CLK

sound 9, [100\880, 100\988, 100\1046, 100\1175]

main
serout S_OUT,i57600,[dec3 moteur_droit\4," “,dec3 moteur_gauche\4,” “,dec3 dpad_haut\3,” “,dec3 dpad_bas\3,” ", 13]
gosub get_PSX_data

if Dpad_haut=1 and (Lastbuttons.bit4 = 1) then
	moteur_droit=(moteur_droit-10)min maxvitesse
	moteur_gauche=(moteur_gauche-10)min maxvitesse
endif

if dpad_bas=1 and (Lastbuttons.bit6 = 1) then
	moteur_droit=(moteur_droit+10) max minvitesse
	moteur_gauche=(moteur_gauche+10) max minvitesse
endif

if  dpad_gauche=1 and (Lastbuttons.bit7 = 1) then
	moteur_droit=(moteur_droit+10) max minvitesse
	moteur_gauche=(moteur_gauche+10) min maxvitesse
endif

if  dpad_droite=1 and (Lastbuttons.bit5 = 1) then
	moteur_droit=(moteur_droit-10) min maxvitesse
	moteur_gauche=(moteur_gauche+10) max minvitesse
endif


pulsout 0,(moteur_droit*2)					
pulsout 1,(moteur_gauche*2)	

pause 20
goto main

get_PSX_data

Lastbuttons = buttons
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]						
shiftin DAT,CLK,FASTLSBPOST,[temp\8,buttons.LOWBYTE\8,buttons.HIGHBYTE\8,rhori\8,rvert\8,lhori\8,lvert\8]								
high SEL
pause 1

buttons = buttons ^ $FFFF
	
	Dpad_haut 		= Buttons.bit4
	Dpad_droite 	= Buttons.bit5
	Dpad_bas 		= buttons.bit6
	Dpad_gauche 	= Buttons.bit7

return

[/code]