Serial Control of a Motor Mind C with a VB6.0 Application
There are a few editions of Microsoft's Visual BASIC available. There is .net and the 2008 Express version (see here for free download). 6.0 is no longer supported by Microsoft, but I know a lot of people still use it, and I happen to have a copy on my lab computer.
I use the 6.0 version of the software to write test programs for any designs I have that interface to a PC. And if the design is not communicating with a PC I'll often need to connect a specific piece of test hardware to a PC to display test results.
Our Motor Mind C (MMC, see product web page here) is a low current dual motor controller (up to 2.25A per motor). It's used for a variety of applications but often finds itself applied to robot chassis controls and camera controls. The MMC comes in a 40 pin DIP footprint, and can be controlled with serial, analog, or RC (1-2ms pulse) signals.
I started with a simple VB form that converted 2 slidebar objects to motor speeds for the Motor1 and Motor2 connections. But then I couldn't stop myself and added subroutines that read all of the registers, a button driven command to write to the DEAD_BAND, PWM_STEP, and BRAKE_MODE registers. Here's the form that resulted from the software work.

Screen capture of VB6.0 control software
I'm not going to delve into how VB6.0 works but here is the source code and installation software for this application.
http://www.solutions-cubed.com/solutions%2...mmc_vb6_app.zip
I will briefly go into the communication protocol for the updating the speed of both motors through the serial interface. The two slider objects both have values ranging from -1023 (full reverse) to +1023 (full foward). Speed control is proportional between these values with 0 being stopped.
The slider value's upper byte is logically ANDed with 65535 (hex FFFF) to limit the value to 16 bits, and then divided by 256 to shift the upper 8 bits into an 8 bit value. The lower 8 bits are logically ANDed with 255 (hex FF). This leaves just the lowest 8 bits to be transmitted to the MMC.
The format of the serial data sent to update the motor speed is...
Command (decimal 208, hex D0), Address (1 or 2), number of bytes before the checksum (always 4), Motor1 MSB, Motor1 LSB, Motor2 MSB, Motor2 LSB, checksum. The checksum is calculated by adding all of the byte together in the message and sending the lowest 8 bits of the result.
As and example, if you were sending speeds of 0 to both motors the data string would look like this in decimal format...
208,1,4,0,0,0,0,213
In hex format it would look like this...
D0,1,4,0,0,0,0,D5
The subroutine below is used with a VB6.0 comm object (MSComm1) to send the serial data, and a separate routine is called upon a communication event when the number of bytes in an input buffer is equals or exceeds a predefined threshold (MSComm1.RThreshold). In this case is the threshold is 1, since the speed command only responds with an ACK (hex or decimal 6).
Private Sub SendMotorSpeed()
'Convert slider value to two bytes for sending serially, do this for both
' motors
M1_MSB = ((2 ^ 16 - 1) And sldMotor1.Value) \ 2 ^ 8
M1_LSB = ((2 ^ 8 - 1) And sldMotor1.Value)
M2_MSB = ((2 ^ 16 - 1) And sldMotor2.Value) \ 2 ^ 8
M2_LSB = ((2 ^ 8 - 1) And sldMotor2.Value)
'Calculate checksum = 208 (command byte) + 1 (address) + 4 (# bytes) + motor
' speed values from sliders
Checksum = 213 + M1_MSB + M1_LSB + M2_MSB + M2_LSB
Checksum = Checksum Mod 256
'Prepare to send motor speed values see datasheet for more information
Output$ = Chr$(208) + Chr$(1) + Chr$(4) _
+ Chr$(M1_MSB) + Chr$(M1_LSB) _
+ Chr$(M2_MSB) + Chr$(M2_LSB) _
+ Chr$(Checksum)
'Send serial command using the comm1 object. RThreshold sets the number of bytes
' that need to be received before comm event occurs. InBufferCount resets the receive
' buffer. Output sends the serial data.
MSComm1.RThreshold = 1
MSComm1.InBufferCount = 0
MSComm1.Output = Output$
' Timer2_RXCounter ensures that we spend no more than ~20ms waiting for data
Timer2_RXCounter = 0
Do Until Timer2_RXCounter > 2
DoEvents
Loop
End Sub
There is much more to the VB6.0 program that can be used or stripped down to communicate and control with the MMC.
From a hardware standpoint there is very little circuitry required to interface the MMC with a PC and it's serial port. Since PC's are now being sold with USB ports you will likely need a USB to serial converter. These are not difficult to find. You'll also need a 5V regulator and a linedriver IC to convert RS232 level signals to logic levels.

Schematic of connecting PC serial port to MMC and controlling two motors.
And here is a pdf version of the schematic that is probably much easier to read (pdf file).
There are a few editions of Microsoft's Visual BASIC available. There is .net and the 2008 Express version (see here for free download). 6.0 is no longer supported by Microsoft, but I know a lot of people still use it, and I happen to have a copy on my lab computer.
I use the 6.0 version of the software to write test programs for any designs I have that interface to a PC. And if the design is not communicating with a PC I'll often need to connect a specific piece of test hardware to a PC to display test results.
Our Motor Mind C (MMC, see product web page here) is a low current dual motor controller (up to 2.25A per motor). It's used for a variety of applications but often finds itself applied to robot chassis controls and camera controls. The MMC comes in a 40 pin DIP footprint, and can be controlled with serial, analog, or RC (1-2ms pulse) signals.
I started with a simple VB form that converted 2 slidebar objects to motor speeds for the Motor1 and Motor2 connections. But then I couldn't stop myself and added subroutines that read all of the registers, a button driven command to write to the DEAD_BAND, PWM_STEP, and BRAKE_MODE registers. Here's the form that resulted from the software work.

Screen capture of VB6.0 control software
I'm not going to delve into how VB6.0 works but here is the source code and installation software for this application.
http://www.solutions-cubed.com/solutions%2...mmc_vb6_app.zip
I will briefly go into the communication protocol for the updating the speed of both motors through the serial interface. The two slider objects both have values ranging from -1023 (full reverse) to +1023 (full foward). Speed control is proportional between these values with 0 being stopped.
The slider value's upper byte is logically ANDed with 65535 (hex FFFF) to limit the value to 16 bits, and then divided by 256 to shift the upper 8 bits into an 8 bit value. The lower 8 bits are logically ANDed with 255 (hex FF). This leaves just the lowest 8 bits to be transmitted to the MMC.
The format of the serial data sent to update the motor speed is...
Command (decimal 208, hex D0), Address (1 or 2), number of bytes before the checksum (always 4), Motor1 MSB, Motor1 LSB, Motor2 MSB, Motor2 LSB, checksum. The checksum is calculated by adding all of the byte together in the message and sending the lowest 8 bits of the result.
As and example, if you were sending speeds of 0 to both motors the data string would look like this in decimal format...
208,1,4,0,0,0,0,213
In hex format it would look like this...
D0,1,4,0,0,0,0,D5
The subroutine below is used with a VB6.0 comm object (MSComm1) to send the serial data, and a separate routine is called upon a communication event when the number of bytes in an input buffer is equals or exceeds a predefined threshold (MSComm1.RThreshold). In this case is the threshold is 1, since the speed command only responds with an ACK (hex or decimal 6).
Private Sub SendMotorSpeed()
'Convert slider value to two bytes for sending serially, do this for both
' motors
M1_MSB = ((2 ^ 16 - 1) And sldMotor1.Value) \ 2 ^ 8
M1_LSB = ((2 ^ 8 - 1) And sldMotor1.Value)
M2_MSB = ((2 ^ 16 - 1) And sldMotor2.Value) \ 2 ^ 8
M2_LSB = ((2 ^ 8 - 1) And sldMotor2.Value)
'Calculate checksum = 208 (command byte) + 1 (address) + 4 (# bytes) + motor
' speed values from sliders
Checksum = 213 + M1_MSB + M1_LSB + M2_MSB + M2_LSB
Checksum = Checksum Mod 256
'Prepare to send motor speed values see datasheet for more information
Output$ = Chr$(208) + Chr$(1) + Chr$(4) _
+ Chr$(M1_MSB) + Chr$(M1_LSB) _
+ Chr$(M2_MSB) + Chr$(M2_LSB) _
+ Chr$(Checksum)
'Send serial command using the comm1 object. RThreshold sets the number of bytes
' that need to be received before comm event occurs. InBufferCount resets the receive
' buffer. Output sends the serial data.
MSComm1.RThreshold = 1
MSComm1.InBufferCount = 0
MSComm1.Output = Output$
' Timer2_RXCounter ensures that we spend no more than ~20ms waiting for data
Timer2_RXCounter = 0
Do Until Timer2_RXCounter > 2
DoEvents
Loop
End Sub
There is much more to the VB6.0 program that can be used or stripped down to communicate and control with the MMC.
From a hardware standpoint there is very little circuitry required to interface the MMC with a PC and it's serial port. Since PC's are now being sold with USB ports you will likely need a USB to serial converter. These are not difficult to find. You'll also need a 5V regulator and a linedriver IC to convert RS232 level signals to logic levels.

Schematic of connecting PC serial port to MMC and controlling two motors.
And here is a pdf version of the schematic that is probably much easier to read (pdf file).
0 Comments On This Entry
Recent Entries
-
-
-
PC Boton Oct 14 2008 12:49 PM
-
Old School Serial Controlon Sep 30 2008 10:10 AM
-
Help
Leave Comment








