PSC and variables
Special_K
Posts: 162
I there a way to send a servo position command to the PSC without using a variable.
or just
I am using the MacBs2 PBasic app since my PC laptop crashed. I do not know if the PC PBasic app would let this syntax go through or tell me what it expected to me to change.
thanks in advance
' {$STAMP BS2} ' {$PBASIC 2.5} Sdat CON 15 ' PSC Module baud CON 396 ' BS2 baudmode (2400 baud, 8-bit, no parity) dl CON 750 dr CON 750 dlhex CON $6432 main: DO SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, dl.LOWBYTE, dl.HIGHBYTE, CR] SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 00, 0, dr.LOWBYTE, dr.HIGHBYTE, CR] LOOP
or just
SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, 750.LOWBYTE,750.HIGHBYTE, CR] SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 00, 0,750.LOWBYTE, 750.HIGHBYTE, CR]
I am using the MacBs2 PBasic app since my PC laptop crashed. I do not know if the PC PBasic app would let this syntax go through or tell me what it expected to me to change.
thanks in advance
Comments
·· You can hard-code the PULSE value, but you can't do it like that.· You need to break the bytes up into their true LOWBYTE and HIGHBYTE values...Which, for 750 would be 2 for the HIGHBYTE (2 * 256) and 238 for the LOWBYTE.· Add them and you get 750 (2 * 256) + 238.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Rather than the original query, which won't work:
SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, 750.LOWBYTE,750.HIGHBYTE, CR]
or Chris's correct but computational method:
SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, 238, 2, CR]
isn't this easier, and doesn't it make life more simple:
Value VAR WORD
Value = 750
SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, Value.LOWBYTE,Value.HIGHBYTE, CR]
I agree it does use more variable space, and if that was the point or purpose, I apologize.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
·· Of course it can be done that way...That is how it should be...But his exact question was could it be done without variables.· I don't know why, but that's what I offered.· Now, in terms of simplicity, this would've been easier with a constant.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, 750 & $FF, 750 >> 8, CR]
That way you'll know what the constants mean when you come back in a year and look at the code. (I'm not sure whether the tokenizer evaluates those values at run time or compile time.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Great point.
Special_K, if you don't understand what SSteve was suggesting, he's masking with the "&" and rotating with the >>, to get the high and low bytes isolated. (And it keeps things readable, by retaining the actual value of 750 visible)-
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
I certainly can't speak as to how Jeff Martin wrote that part of the PBASIC IDE, but as a general matter, constants are usually resolved at compile time, in my experience. Actually, in this particular case, it really doesn't matter, since nothing changes between compile time and run time. Nice technique, and nearly self-documenting!
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->