|
 |
Using the MotorMindB with the BX-24
Jen Lewin, 2001
The
MotorMindB is created by Solutions
Cubed
It can be purchased at jameco, digikey, mondo-tronics
and Parallax.
graphics adapted from the
MotorMindB, solutions cubed pdf
BX-24 Serial Setup:
The motormind sends and receives serial data that is 2400 baud, 8bit, no polarity,
NON-INVERTED.
For the BX-24, when using
the DefineCom3 procedure we have to define the parameters of this serial communication.
By looking up 'DefineCom3'
in the BX-24 documentation we the following chart:
| DefineCom3(InputPin, OutputPin, ParameterMask) |
| ParameterMask Value Bit pattern (x = don't care) |
|
| Inverted logic |
1 0 x x x x x x |
| Non-inverted logic |
0 0 x x x x x x |
| Even parity |
x x 1 0 x x x x |
| Odd parity |
x x 1 0 x x x x |
| No parity |
x x 0 0 x x x x |
| 7 data bit |
x x x x 0 1 1 1 |
| 8 data bits |
x x x x 1 0 0 0 |
|
Our serial
parameter is : 8 bit, no parity, non-inverted = 00001000
MotorMind Commands:
The list of commands from the MotormindB pdf manual are below:
Chart from the
MotorMindB, solutions cubed pdf
Each command, can be setup
to return a confirmation. You can for example send a stop command (00 hex) or
a stop command with confirmation (80 hex). If you send the stop command with
confirmation, once the motormind has received and implemented the command, it
will return AA hex, (170 Dec).
Testing your MotorMind and BX-24
Below is a quick code example to make sure your motor mind is wired correctly.
MAKE SURE YOU ARE NOT SENDING MORE THEN 7 VOLTS INTO THE MOTOR MIND VCC PIN.
(You can easily fry your motor minds, by mixing up your VCC and Vmotor supply lines. )
MAKE SURE YOUR GROUNDS ARE ALL SHARED.
--------------------------------------------------------
'''Simple Code example:
''' The motor mind FM pin is wired to the BX-24 pin 12.
''' The TM pin is wired to BX pin 11.
dim outpin as byte
dim inpin as byte
dim outputBuffer(0 to 20) as byte
dim inputBuffer(0 to 20) as byte
dim out as byte
sub main()
outpin = 12
inpin = 11
' open the input and output buffers:
call openQueue(outputBuffer, 20)
call openQueue(inputBuffer, 20)
' define which pins we'll use for serial in and out:
call defineCom3(inpin,outpin,bx0000_1000)
call openCom(3, 2400, inputBuffer, outputBuffer)
'simple code to simply test the motor by turning it on
out = &H055 'send sync byte to motormind (to prepare it for a command)
call putQueue(outputBuffer,out, 1)
out = &H003 ''''''''SETDC turn motor on
call putQueue(outputBuffer, out, 1)
out = 127 ''''''''''50% of total speed
call putQueue(outputBuffer, out, 1)
End Sub
'-------------------------------------------------------------------------------- |
Motor
Mind Routines:
Below are more examples that use several motormind subroutines I have written.
The Routines I have created are
Stopmotor()
Gomotor(speed)
''''takes as speed value of 1 - 255
changedirection(direction)
'''takes the direction. 0 = forward, 1 = backward
Gorampspeed(startspeed, endspeed, changedelay)
'''takes the startspeed (1 - 255), the endspeed (1 - 255) and the delay of change
(0.0 - 3.0)
'Go ramp speed can accelerate, or decelerate... i.e., can go from 1 to 150,
or 200 to 1.
'-------------------------------------------------------
'In this example the motor is accelerated from 1 to 200 , if pin13 is high.
''The motor is then decelerated from 200 to 1 if pin14 is high.
dim outpin as byte
dim inpin as byte
dim outputBuffer(0 to 20) as byte
dim inputBuffer(0 to 20) as byte
dim out as byte
dim inbyte as byte
dim direction as byte
dim forward as boolean
dim backward as boolean
dim x as byte
sub main()
outpin = 12
inpin = 11
forward = false
backward = false
' open the input and output buffers:
call openQueue(outputBuffer, 20)
call openQueue(inputBuffer, 20)
' define which pins we'll use for serial in and out:
call defineCom3(inpin,outpin,bx0000_1000)
call openCom(3, 2400, inputBuffer, outputBuffer)
call stopmotor
do
if getpin(13) = 1 then
if forward = false then 'if not already at full speed forward
''debug.print"forward"
call changedirection(1)
call Gorampspeed(1, 200, 0.0)
forward = true
backward = false
end if
end if
if getpin(14) = 1 then
if backward = false then 'if not already at full speed forward
debug.print"backward"
call changedirection(0)
call Gorampspeed(200,1,0.0)
backward = true
forward = false
end if
end if
loop
end sub
Sub stopmotor()
out = &H055 'send sync byte to motormind (to prepare it for a command)
call putQueue(outputBuffer,out, 1)
out = &H080 'stop motor and send confirm if stoped
call putQueue(outputBuffer,out, 1)
do until inbyte = 170 'wait untill confirm of stop is recieved
call getQueue(inputBuffer,inbyte, 1)
loop
"Motor Stoped"
End Sub
sub changedirection(byVal direction as byte)
dim directionbyte as byte
out = &H055 'send sync byte to motormind (to prepare it for a command)
call putQueue(outputBuffer,out, 1)
out = &H005 'send 'get motor STATUS' command
call putQueue(outputBuffer,out, 1)
call getQueue(inputBuffer,inbyte, 1) 'get initial byte
call getQueue(inputBuffer,directionbyte, 1) 'get direction byte
if directionbyte <> direction then
'change the direction
out = &H055 'send sync byte to motormind (to prepare it for a command)
call putQueue(outputBuffer,out, 1)
out = &H081 'send reverse command with confirmation
call putQueue(outputBuffer,out, 1)
do until inbyte = 170 'wait untill confirm of direction change is recieved
call getQueue(inputBuffer,inbyte, 1)
loop
debug.print"direction changed to "; cstr(direction)
end if
end sub
sub Gomotor(byVal speed as byte)
out = &H055 'send sync byte
call putQueue(outputBuffer,out, 1)
out = &H003 'send motor Go (SETDC) command
call putQueue(outputBuffer,out, 1)
call putQueue(outputBuffer,speed, 1) 'send speed value
debug.print; cStr(speed)
end sub
sub Gorampspeed(byVal startspeed as byte, byVal endspeed as byte, byVal changedelay as single)
dim x as byte
if startspeed < endspeed then
for x = startspeed to endspeed
call gomotor(x)
delay(changedelay)
next
end if
if startspeed > endspeed then
for x = startspeed to endspeed step -1
call gomotor(x)
delay(changedelay)
next
end if
end sub
|
|