MD49 - Dual 24 Volt 5 Amp H Bridge Motor Drive
The MD49 is a robust serial dual motor driver, designed for use with our EMG49 motors. Main features are:
1. Reads motors encoders and provides counts for
determining distance traveled and direction of rotation.
2. Drives two motors with independent or combined control.
3. Motor current is readable.
4. Only 24v is required to power the module.
5. Steering feature, motors can be commanded to turn by sent value.
6. Variable acceleration and power regulation also included
7. Protection against short circuit output, over current and incorrect voltage. Also included is an error LED and error byte for diagnosis of faults.
Automatic Speed regulation
By using feedback from the encoders the MD49 is able to dynamically increase power as required. If the required speed is not being achieved, the MD49 will increase power to the motors until it reaches the desired rate or the motors reach there maximum output. Speed regulation can be turned off with the use of the DISABLE REGULATOR command..
Automatic Motor Timeout
The MD49 will automatically stop the motors if there is no serial communications within 2 seconds. This is to prevent your robot running wild if the controller fails. The feature can be turned off with the DISABLE TIMEOUT command.
Controlling the MD49
The MD49 is designed to operate with a TTL level serial bus (5v levels) at either 9600 or 38400 baud depending on the jumper selection and accepts either one or two stop bits. A jumper is supplied to make the default shipped baud rate 38400. Do not connect the MD49 to RS232 directly, if you wish to connect to RS232 it must be with the aid of a voltage level converter such as a ST232.
An easy to use command set provides all of the functions that the MD49 has to offer. The commands are sent with a sync byte of 0 at the start and then the command followed by any data bytes. The MD49 will then respond if the command is applicable.
|Bytes sent to MD49||Bytes returned by MD49||
|GET SPEED 1||2||1||returns the current requested speed of motor 1|
|GET SPEED 2||2||1||returns the current requested speed of motor 2|
|GET ENCODER 1||2||4||motor 1 encoder count, 4 bytes returned high byte first (signed)|
|GET ENCODER 2||2||4||motor 2 encoder count, 4 bytes returned high byte first (signed)|
|GET ENCODERS||2||8||returns 8 bytes - encoder1 count, encoder2 count|
|GET VOLTS||2||1||returns the input battery voltage level|
|0x27||GET CURRENT 1||2||1||returns the current drawn by motor 1|
|GET CURRENT 2||2||1||returns the current drawn by motor 1|
|0x29||GET VERSION||2||1||returns the MD49 software version|
|0x2A||GET ACCELERATION||2||1||returns the current acceleration level|
|0x2B||GET MODE||2||1||returns the currently selected mode|
|0x2C||GET VI||2||3||returns battery volts, motor1 current and then motor2 current|
|0x2D||GET ERROR||2||1||returns a byte within which the bits indicate errors on the MD49|
|0x31||SET SPEED 1||3||0||set new speed1|
|0x32||SET SPEED 2 / TURN||3||0||set new speed2 or turn|
|0x33||SET ACCELERATION||3||0||set new acceleration|
|0x34||SET MODE||3||0||set the mode|
|0x35||RESET ENCODERS||2||0||zero both of the encoder counts|
|0x36||DISABLE REGULATOR||2||0||power output not changed by encoder feedback|
|0x37||ENABLE REGULATOR||2||0||power output is regulated by encoder feedback|
|0x38||DISABLE TIMEOUT||2||0||MD49 will continuously output with no regular commands|
|0x39||ENABLE TIMEOUT||2||0||MD49 output will stop after 2 seconds without communication|
For example to read the battery voltage, send:
0x00 - sync byte
0x26 - READ VOLTS command
and the MD49 would respond with
0x18 - returned byte (24 decimal) 24v
Depending on what mode you are in, this register can affect the speed of one motor or both motors. If you are in mode 0 or 1 it will set the speed and direction of motor 1. The larger the number written to this register, the more power is applied to the motor. A mode of 2 or 3 will control the speed and direction of both motors (subject to effect of turn register).
When in mode 0 or 1 this operates the speed and direction of motor 2. When in mode 2 or 3 Speed2 becomes a turn value, and is combined with Speed1 to steer the device (see below).
Turn mode looks at the speed1 to decide if the direction is forward or reverse. Then it applies a subtraction or addition of the turn value on either motor.
so if the direction is forward
motor speed1 = speed1 - turn
motor speed2 = speed1 + turn
else the direction is reverse so
motor speed1 = speed1 + turn
motor speed2 = speed1 - turn
If the either motor is not able to achieve the required speed for the turn (beyond the maximum output), then the other motor is automatically changed by the program to meet the required difference.
GET ENCODER 1, GET ENCODER 2 or GET ENCODERS
When a read encoder command is issued the MD49 will send out 4 bytes high byte first, which should be put together to form a 32 bit signed number. For example a GET ENCODER 1 command may return 0x00,0x10,0x56,0x32.
So declare a 32 bit signed variable in your program, for C:
result = serin() << 24ul; // (0x00 shifted 24 bits left)
result += serin() << 16ul; // (0x10 shifted 16 bits left)
result += serin() << 8ul; // (0x56 shifted 8 bits left)
result += serin(); // (0x32)
result now equals 1070642 decimal or 0x105632 hex. If the highest bit was set then it would be -ve.
read encoders will send encoder count 1 and then encoder count 2 but is put together in exactly the same way. The registers can be zeroed at any time by writing 0x35 to the MD49.
A reading of the voltage of the connected battery is available. It returns the voltage in volts (24 for 24v).
Motor 1 and 2 current
A guide reading of the average current through the motor is available. It reads approx ten times the number of Amps (25 at 2.5A).
Software Revision number
Responds with the revision number of the software in the modules PIC18F2321 controller - currently 1 at the time of writing.
If you require a controlled acceleration period for the attached motors to reach there ultimate speed, the MD49 has the ability to provide this. It works by using a sent acceleration value and incrementing the power by that value. Changing between the current speed of the motors and the new speed. So if the motors were traveling at full speed in the forward direction (255) and were instructed to move at full speed in reverse (0), there would be 255 steps with an acceleration register value of 1, but 128 for a value of 2. The default acceleration value is 5, meaning the speed is changed from full forward to full reverse in 0.816 seconds. The WRITE ACCELERATION command will accept values of 1 up to 10 which equates to a period of only 0.416 seconds to travel from full speed in one direction to full speed in the opposite direction.
So to calculate the time (in seconds) for the acceleration to complete :
if new speed > current speed
steps = (new speed - current speed) / acceleration register
if new speed < current speed
steps = (current speed - new speed) / acceleration register
time = steps * 16ms
For example :
|Acceleration register||Time/step||Current speed||New speed||Steps||Acceleration time|
The mode command changes the way the speed/turn values are used. The options being:
0, (Default Setting) If a value of 0 is written then the speed registers is literal speeds in the range of 0 (full reverse) 128 (stop) 255 (full forward).
1, Mode 1 is similar to mode 0, except that the speed values are interpreted as signed values. The range being -128 (full reverse) 0 (stop) 127 (full forward).
2, Writing a value of 2 to the mode will make speed1 control both motors speed, and speed2 becomes the turn value.
Data is in the range of 0 (full reverse) 128 (stop) 255 (full forward).
3, Mode 3 is similar to mode 2, except that the speed values are interpreted as signed values.
Data is in the range of -128 (full reverse) 0 (stop) 127 (full forward)
This command instructs the MD49 to send the battery volts reading (25 = 25v), then the current being drawn by motor 1 (roughly 1 count per 100mA) and finally the current being drawn by motor 2.
In the event of and error the red LED will be lit and a byte which contains the type of error that the MD49 is experiencing will have the appropriate bit set. The bits are:
|bit 7||bit 6||bit 5||bit 4||bit 3||bit 2||bit 1||bit 0|
|UNDER 16V||OVER 30V||MOTOR 2 SHORT||MOTOR 1 SHORT||MOTOR 2 TRIP||MOTOR 1 TRIP||-||-|
bit 7 - UNDER 16V stops power being switched to the motor when the source has
dropped below the 16V lower threshold. When the supply gets back to 18V the
error will clear and power will be outputted again.
bit 6 - OVER 30V lockout prevents excess voltage being outputted to the motor, the error will be cleared and power outputted when the supply lowers to 28V or below.
bit 5 - MOTOR 2 SHORT indicates a direct short has been detected across motor 2 output. This error will remain until power has been cycled.
bit 4 - MOTOR 1 SHORT indicates a direct short has been detected across motor 1 output. This error will remain until power has been cycled.
bit 3 - MOTOR 2 TRIP is set when the current drawn by motor 2 is greater than 10A. This error will remain until power has been cycled.
bit 2 - MOTOR 1 TRIP is set when the current drawn by motor 1 is greater than 10A. This error will remain until power has been cycled.