Shop OBEX P1 Docs P2 Docs Learn Events
Precision statement serial command — Parallax Forums

Precision statement serial command

KyeKye Posts: 2,200
edited 2008-10-01 23:09 in BASIC Stamp
Hello,
·
I'm working on making a precision statement serial command to decrease the size of my code for my BASIC Stamp. However, I'm not getting working results from the code.
·
Basically, I have two bytes for two motors. The MSB of the byte denotes·the direction of a motor, the other 7 bits denote the speed. However, to communicate to the motor controller I'm using I need to break·the original byte for each motor into two bytes.
·
For motor one the original byte simply needs to be split into a byte equal to %0000000x where x is the MSB of the original byte. And into a following byte equal to %0xxxxxxx where the x's are the rest of the original byte... in the same order.
·
For motor·two the original byte simply needs to be split into a byte equal to %0000001x where x is the MSB of the original byte. And into a following byte equal to %0xxxxxxx where the x's are the rest of the original byte... in the same order.
·
I'm trying to avoid using a buffer variable to do the math. So I would like to compute the math for each serial output in the serout·statement. However, I can't seem to get anything to work properly when doing this. So I could really use some help with the code. Thank you.
·
Here's my example. (Please note that I deleted two constants that were transmitted before the two variables so the code would fit on one line here on the post)
·
SEROUT MC_serial_input, MC_baud_rate, [noparse][[/noparse](MC_motor1_direction_and_speed.BIT7 + %00000000), ((MC_motor1_direction_and_speed >> 1) << 1)]
·
SEROUT MC_serial_input, MC_baud_rate, [noparse][[/noparse](MC_motor2_direction_and_speed.BIT7 + %00000010), ((MC_motor1_direction_and_speed >> 1) << 1)]
·
What I'm trying to do is to add the MSB to the basic value that needs to be sent to the motor controller for the direction, and then compute the speed by shifting over the MSB and then shifting back - thus turning the MSB into a 0.





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye

Comments

  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2008-10-01 07:28
    what about
    SEROUT MC_serial_input, MC_baud_rate,
     [noparse][[/noparse] MC_motor1_direction_and_speed.BIT7,
       MC_motor1_direction_and_speed & %01111111 ]
    
    SEROUT MC_serial_input, MC_baud_rate,
     [noparse][[/noparse] MC_motor2_direction_and_speed.BIT7 | %10,
       MC_motor2_direction_and_speed & %01111111 ]
    
    



    regards adrian
  • KyeKye Posts: 2,200
    edited 2008-10-01 23:09
    Wow, I was not thinking at all about logical operators, thank you very much. However I don't know if it will still work...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye
Sign In or Register to comment.