Precision statement serial command
Kye
Posts: 2,200
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
·
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
regards adrian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye