~ PSC Mrmory Out ! ~
Hi, I have a question with my PSC program, I decide to build a robot that required to use the 32 servo, but the program I follow from the instruction manual, I can only control 11 servo since the “RAM Map” already full (Out of Memory), I know that it is something wrong with my program, can any expert help me to reduce the memory space or· solve this problem?·····
·
The following is my program that can control 11 servo:
'{$STAMP BS2}
pwa··· VAR· Word
pwb··· VAR· Word
pwc··· VAR· Word
pwd··· VAR· Word
pwe··· VAR· Word
pwf··· VAR· Word
pwg··· VAR· Word
pwh··· VAR· Word
pwi··· VAR· Word
pwj··· VAR· Word
pwk··· VAR· Word
pwl··· VAR· Word
ra··· VAR· Byte
Sdat· CON· 15
baud· CON· 396
· ra = 12
Servo:
· pwa=800
· pwb=800
· pwc=800
· pwd=800
· pwe=800
· pwf=800
· pwg=800
· pwh=800
· pwi=800
· pwj=800
· pwk=800
· pwl=800
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",0,ra,pwa.LOWBYTE,pwa.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",1,ra,pwb.LOWBYTE,pwb.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",2,ra,pwc.LOWBYTE,pwc.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",3,ra,pwd.LOWBYTE,pwd.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",4,ra,pwe.LOWBYTE,pwe.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",5,ra,pwf.LOWBYTE,pwf.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",6,ra,pwg.LOWBYTE,pwg.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",7,ra,pwh.LOWBYTE,pwh.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",8,ra,pwi.LOWBYTE,pwi.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",9,ra,pwj.LOWBYTE,pwj.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",10,ra,pwk.LOWBYTE,pwk.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",11,ra,pwl.LOWBYTE,pwl.HIGHBYTE,CR]
· PAUSE 1000
· DEBUG " step 1"
· pwa=750
· pwb=750
· pwc=750
· pwd=750
· pwe=750
· pwf=750
· pwg=750
· pwh=750
· pwi=750
· pwj=750
· pwk=750
· pwl=750
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",0,ra,pwa.LOWBYTE,pwa.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",1,ra,pwb.LOWBYTE,pwb.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",2,ra,pwc.LOWBYTE,pwc.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",3,ra,pwd.LOWBYTE,pwd.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",4,ra,pwe.LOWBYTE,pwe.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",5,ra,pwf.LOWBYTE,pwf.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",6,ra,pwg.LOWBYTE,pwg.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",7,ra,pwh.LOWBYTE,pwh.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",8,ra,pwi.LOWBYTE,pwi.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",9,ra,pwj.LOWBYTE,pwj.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",10,ra,pwk.LOWBYTE,pwk.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",11,ra,pwl.LOWBYTE,pwl.HIGHBYTE,CR]
· PAUSE 1000
· DEBUG " step 2"
GOTO Servo
·
The following is my program that can control 11 servo:
'{$STAMP BS2}
pwa··· VAR· Word
pwb··· VAR· Word
pwc··· VAR· Word
pwd··· VAR· Word
pwe··· VAR· Word
pwf··· VAR· Word
pwg··· VAR· Word
pwh··· VAR· Word
pwi··· VAR· Word
pwj··· VAR· Word
pwk··· VAR· Word
pwl··· VAR· Word
ra··· VAR· Byte
Sdat· CON· 15
baud· CON· 396
· ra = 12
Servo:
· pwa=800
· pwb=800
· pwc=800
· pwd=800
· pwe=800
· pwf=800
· pwg=800
· pwh=800
· pwi=800
· pwj=800
· pwk=800
· pwl=800
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",0,ra,pwa.LOWBYTE,pwa.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",1,ra,pwb.LOWBYTE,pwb.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",2,ra,pwc.LOWBYTE,pwc.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",3,ra,pwd.LOWBYTE,pwd.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",4,ra,pwe.LOWBYTE,pwe.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",5,ra,pwf.LOWBYTE,pwf.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",6,ra,pwg.LOWBYTE,pwg.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",7,ra,pwh.LOWBYTE,pwh.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",8,ra,pwi.LOWBYTE,pwi.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",9,ra,pwj.LOWBYTE,pwj.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",10,ra,pwk.LOWBYTE,pwk.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",11,ra,pwl.LOWBYTE,pwl.HIGHBYTE,CR]
· PAUSE 1000
· DEBUG " step 1"
· pwa=750
· pwb=750
· pwc=750
· pwd=750
· pwe=750
· pwf=750
· pwg=750
· pwh=750
· pwi=750
· pwj=750
· pwk=750
· pwl=750
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",0,ra,pwa.LOWBYTE,pwa.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",1,ra,pwb.LOWBYTE,pwb.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",2,ra,pwc.LOWBYTE,pwc.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",3,ra,pwd.LOWBYTE,pwd.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",4,ra,pwe.LOWBYTE,pwe.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",5,ra,pwf.LOWBYTE,pwf.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",6,ra,pwg.LOWBYTE,pwg.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",7,ra,pwh.LOWBYTE,pwh.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",8,ra,pwi.LOWBYTE,pwi.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",9,ra,pwj.LOWBYTE,pwj.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",10,ra,pwk.LOWBYTE,pwk.HIGHBYTE,CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",11,ra,pwl.LOWBYTE,pwl.HIGHBYTE,CR]
· PAUSE 1000
· DEBUG " step 2"
GOTO Servo
Comments
The EEPROM can only be written to about 10 million times -- which sounds like a lot until you use it every 10 mS. If you write to a location in the EEPROM every 10 mS, you'll wear it out in around a week or two.
You could use external EEPROM to store your settings -- but that starts getting slow after a while.
What in the world are you using 32 servos for, anyway?
Oh, another solution is to use 2 BS2's, or even an SX, to send out servo control signals.
Another solution is to define certain 'sets' of settings for your servos, put THOSE in DATA statements, then read the data statements and send the data out using only a couple of 'Temp' variables.
EDIT: Nevermind, didn't understand the problem.
Post Edited (Robert Schwartz) : 3/23/2005 10:15:50 PM GMT
You may have to insert a 'PAUSE 100' before the loop to give the servo's time to move.
Appreciate if someone can help me solve this problem.
Appreciate if someone can help me solve this problem.
"
MAIN:
· ServoID = 0
· ServoPos = 750
· DO WHILE ServoID < MaxServos
··· GOSUB SendServo
··· ServoID = ServoID + 1
· LOOP· ' END WHILE
· ServoID = 0
· ServoPos = 800
· DO WHILE ServoID < MaxServos
··· GOSUB SendServo
··· ServoID = ServoID + 1
· LOOP· ' END WHILE
· GOTO MAIN
· END
' Subroutines
SendServo:· ' Wants ServoID set to servo number, ServoPos set to position (Word value)
· SEROUT SDat, SBaud + $8000, [noparse][[/noparse]"!SC", ServoID, ra,
······························ ServoPos.LOWBYTE, ServoPos.HIGHBYTE, CR]
· RETURN
You need to find some way to organize the set of data you want to send to the servos.
In fact, you need to find some way to describe the set of data you want to send to the servos.
For instance, from your description, it sounds like you want to cycle Servo1 from 900 to 500 -- but I don't know how many steps.· If so, then:
Serv1Pos CON 0
Serv2Pos CON 6
Serv3Pos CON 12
DATA @Serv1Pos, 900, 800, 700, 600, 500, 0
DATA @Serv2Pos, 1000, 900, 800, 750, 0, 0
DATA @Serv3Pos,· 200, 350, 500, 600, 600, 700
MAIN:
· ServoID = 0
· ServoPos = 750
· FOR I = 1 TO 6
··· ServoID = 0
··· DO WHILE ServoID < MaxServos
······ READ (ServoID*6) + (I-1), ServoPos
······ IF ServoPos <> 0 THEN
········ GOSUB SendServo
······ ENDIF
······ ServoID = ServoID + 1
··· LOOP· ' End While
··· PAUSE 200· ' Pause 200 mSec so servo's can move for awhile...
· NEXT· ' Next 'I' Servo position..
Here, I've divided the movements into 6 parts, and put them into DATA statements.
Then, I calculate which ServoPos value to use in that "(ServoID * 6) + (I-1)", which reads the correct ServoPos from the Data given a ServoID and the Ith position of that Servo.
Now, some servo's don't take 6 positions, so I put in a 'zero' for those -- and then don't do the 'SendServo' for a 'zero' value.
Hope this helps.
P.S. Oh, and for this example, you should set MaxServos to 3.
P.P.S Oh, and you need to add the 'Word' modifier in the Data statements
Post Edited (allanlane5) : 4/5/2005 6:54:15 PM GMT