PSC Question: Change (PW) Variable from Word to Byte
Dear all,
Refer to below program from PSC manual, can I change the (PW) variable from Word to Byte??
·
In simply, the program became:
·
PW····· VAR··· · Byte
·
Instead of· ·: PW········· VAR··· · Word,
·
However, after Syntax Check, it show an error “Expected a smaller-size variable modifier”
·
This is important in order to reduce Basic Stamp’s RAM if we need to control > 10 Servo but find that the RAM is not enough to run.
·
PS: The exact Servo position may not important as I just need to control at three position : Center, CW & CCW.
Thanks if someone can help.
Refer to below program from PSC manual, can I change the (PW) variable from Word to Byte??
·
In simply, the program became:
·
PW····· VAR··· · Byte
·
Instead of· ·: PW········· VAR··· · Word,
·
However, after Syntax Check, it show an error “Expected a smaller-size variable modifier”
·
This is important in order to reduce Basic Stamp’s RAM if we need to control > 10 Servo but find that the RAM is not enough to run.
·
PS: The exact Servo position may not important as I just need to control at three position : Center, CW & CCW.
Thanks if someone can help.


Comments
The variable PW can be a BYTE size, but you must be able to keep the value of it at 255 or less. That's why the variable is defined as a WORD. The BYTE sized variable will limit the movement of the servo because of the following range limits, as extracted from the PSC Manual (range is PW value):
"The range, (250-1250), corresponds to 0 to 180 degrees of servo rotation with each step equaling 2 uSec."
All the movement that is possible if you used a BYTE sized variable would be from 250-255 which won't give you the range you need.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
You can't have a byte, and then refer to the higher 8 bits, then the lower 8 bits, it only has 8 bits!
That's why you're getting the error, as for using a byte for that variable instead of a word, I'm a newb so I can't tell you that
What's wrong with using a word?
This does not mean that you need 16 word variables to control 16 servos. You only need one word variable that you assign a value to or have its value pre assigned.
In your case·to move·a servo CW CCW or center you might have three subroutines that would move a servo·to one of those three·positions, the position word value would have its high byte and low byte pre assigned in each sub routine. All that would be needed is the channel number.
Jeff T.
If you really need to conserve variable space on a Stamp without scratch pad ram, you don't *have* to keep actual servo positions in ram. It's certainly saves space (like if you are reading servo positions from an EE table, then you don't have to have *every* servo taking up a byte or word).
Here's some code for sendng 10 servos to PSC. The numbers in scaling up to 2us units from bytes will be hair off at the extreme ends, but it works pretty well:
svoMM CON 195 ' use with * then divide by 100 to convert byte pos to PSC 2us pos svoDiv CON 100 ' 2 decimal place accuracy svoRnd CON svoMM+1/2 ' use for accurate rounding svoOffset CON 500 ' offset to get range up to 1000-2000us svo VAR Byte(10) ' 10 servo positions in BYTES to save lots of space ramp VAR Byte i VAR Nib ' reusable variable tmpW1 VAR Word ' reusable variable ramp = 10 ' you could also use just one svo var, and read values from an EE table! svo(0) = 128 ' center = 1500us = 750 PSC units svo(1) = 128 ' center svo(2) = 255 ' = 2000us = 1000 2us PSC units svo(3) = 0 ' = 1000us = 500 2us PSC units ' etc. FOR i = 0 TO 9 ' loop through servos tmpW1 = svo(i) * svoMM + svoRnd / svoDiv + svoOffset SEROUT Sio, Baud, [noparse][[/noparse] "!SC", i, ramp, tmpW1.LOWBYTE, tmpW1.HIGHBYTE, CR ] NEXT▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
svoMM CON 195 ' use with * then divide by 100 to convert byte pos to PSC 2us pos svoDiv CON 100 ' 2 decimal place accuracy svoRnd CON svoMM+1/2 ' use for accurate rounding svoOffset CON 500 ' offset to get range up to 1000-2000us i VAR Nib ' reusable variable tmpB1 VAR Byte ' reusable variable tmpB2 VAR Byte ' reusable variable tmpW1 VAR Word ' reusable variable frame VAR Byte ' which frame is current? frameDelay CON 2000 ' delay between frames, could be var also ' each frame is 8 bytes with each byte being a servo position and then a ramp value for that servo in this "frame", servos 0 - 3 ' this is sorta how a lot of the walking robots (e.g. hexapod) move servo values to the servo controller(s) _frames DATA 128, 03, 128, 03, 128, 03, 128, 03 ' all centered DATA 000, 10, 000, 10, 000, 10, 000, 10 ' all the way to 1000us DATA 128, 60, 128, 60, 128, 60, 128, 60 ' back to center sloooowly DATA 255, 10, 255, 10, 255, 10, 255, 10 ' now other side DATA 128, 10, 128, 20, 128, 30, 128, 40 ' back to center, but all have different speeds DATA 032, 05, 064, 05, 096, 05, 196, 05 ' all different positions, same speeds _framesover DATA $FF ' used only as data address marker Reset: FOR i = 0 TO 3 ' start by centering all servos tmpB1 = 128 ' servo position as byte tmpB2 = 7 ' ramp as byte GOSUB Send_Servo NEXT PAUSE frameDelay frame = 0 ' initialize Main: FOR i = 0 TO 3 READ _frames + ( frame * 8 ) + ( i * 2 ), tmpB1, tmpB2 ' read correct position and ramp val GOSUB Send_Servo NEXT PAUSE frameDelay frame = frame + 1 IF _frames + ( frame * 8 ) >= _framesover THEN frame = 0 ENDIF GOTO Main END Send_Servo: ' -- parameters: i = svo channel; tmpB1 = svo pos as byte; tmpB2 = ramp tmpW1 = tmpB1 * svoMM + svoRnd / svoDiv + svoOffset SEROUT Sio, Baud, [noparse][[/noparse] "!SC", i, tmpB2, tmpW1.LOWBYTE, tmpW1.HIGHBYTE, CR ] RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 2/17/2008 10:42:59 PM GMT