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:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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