![]() |
||||
Measuring RPM via Photo reflector
Computer
Interface
|
Complete Circuit: Using the BASIC Stamp II is very convenient because
all of its I/O lines are interchangeable; the only reason we used the
particular pins indicated in the schematic is because it made the wiring
convenient. The Stamp's on-board voltage regulator allows it to run
straight off of a 9-volt battery, and the LEGO motors are designed to
run at 9V as well. The Stamp's regulated 5V output is used for the motor
controller's logic power supply. The diagram does not show the Stamp's
12 I/O lines available for expansion. 4. BASIC Stamp II Software The BASIC Stamp makes serial I/O very straightforward with its serout instruction. A typical use of the instruction is: serout MC_SOUT, 32, [$80, 0, LFWD, SPEED] 'Left motor forward at SPEED The first value, MC_SOUT, specifies the serial output pin to use, which is P10 in our example. The second argument, 32, specifies the settings for the serial output; we use 32 because it specifies the baud rate to be 19,200, which is the maximum rate at which the motor controller can receive. The four values in square brackets are the values sent out over the serial line. The first two values sent to the motor controller are always hex 80 (128 in decimal) and 0, which let the motor controller know that it is being issued a command. The third value specifies the motor number and direction. To help prevent mistakes with this third parameter, we defined constants for forward and backward for our two motors at the beginning of our program: LFWD con 0 (Of course, which constant gets assigned which number depends on how your robot is wired up and what you call forward and reverse or left and right.) The final parameter in the 4-byte sequence is the speed at which the motor should run, where 0 stops the motor and 127 (7F hex) is full speed. The main loop of the program is rather simple since the robot does not do much. For simplicity, we use the pause instruction to determine the time that the robot backs up or turns, but the BASIC Stamp could potentially be doing something more useful during that time. loop: 'Go forward till bump something
serout MC_SOUT, 32, [$80, 0, LBAK, SPEED] 'Spin in place for random
time, TURNTIME goto loop
serout MC_SOUT, 32, [$80, 0, LFWD, SPEED] goto loop For more details, view the entire program. Note that the pin numbers used in the program correspond to the schematic diagram above. 5. Results and Conclusion
|
|||