Shop OBEX P1 Docs P2 Docs Learn Events
PSC and variables — Parallax Forums

PSC and variables

Special_KSpecial_K Posts: 162
edited 2006-07-10 17:29 in BASIC Stamp
I there a way to send a servo position command to the PSC without using a variable.

' {$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

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-09 16:51
    Hello,
    ·· 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.
    SEROUT Sdat,baud+$8000,[noparse][[/noparse]"!SC", 01, 0, 238, 2, CR]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-09 17:24
    Gents -

    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 -->
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-09 17:34
    Bruce,

    ·· 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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-09 17:48
    So I don't confuse anyone, you still can't use the LOWBYTE/HIGHBYTE thing for constants, so...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SSteveSSteve Posts: 808
    edited 2006-07-10 15:38
    Or you could do:

    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
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-07-10 16:21
    SSteve,

    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
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-10 17:29
    SSteve -

    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 -->
Sign In or Register to comment.