MD25 - Dual 12Volt 2.8Amp H Bridge Motor
I2C mode documentation
(Click here for Serial Mode)
Automatic Speed regulation
By using feedback from the encoders the MD25 is able to dynamically increase power as required. If the required speed is not being achieved, the MD25 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 in the command register.
Automatic Motor Timeout
The MD25 will automatically stop the motors if there is no I2C communications within 2 seconds. This is to prevent your robot running wild if the controller fails. The feature can be turned off, if not required. See the command register.
Controlling the MD25
The MD25 is designed to operate in a standard I2C bus system on addresses from 0xB0 to 0xBE (last bit of address is read/write bit, so even numbers only), with its default address being 0xB0. This is easily changed by removing the Address Jumper or in the software see Changing the I2C Bus Address.
I2C mode allows the MD25 to be connected to popular controllers such as the PICAXE, OOPic and BS2p, and a wide range of micro-controllers like PIC's, AVR's, 8051's etc.
I2C communication protocol with the MD25 module is the same as popular EPROM's such as the 24C04. To read one or more of the MD25 registers, first send a start bit, the module address (0XB0 for example) with the read/write bit low, then the register number you wish to read. This is followed by a repeated start and the module address again with the read/write bit high (0XB1 in this example). You are now able to read one or more registers. The MD25 has 17 registers numbered 0 to 16 as follows;
|R/W||Motor1 speed (mode 0,1) or speed (mode 2,3)|
Motor2 speed (mode 0,1) or turn (mode 2,3)
|Read only||Encoder 1 position, 1st byte (highest), capture count when read|
|Enc1b||Read only||Encoder 1 position, 2nd byte|
|Enc1c||Read only||Encoder 1 position, 3rd byte|
|Enc1d||Read only||Encoder 1 position, 4th (lowest byte)|
|6||Enc2a||Read only||Encoder 2 position, 1st byte (highest), capture count when read|
|Enc2b||Read only||Encoder 2 position, 2nd byte|
|8||Enc2c||Read only||Encoder 2 position, 3rd byte|
|9||Enc2d||Read only||Encoder 2 position, 4th byte (lowest byte)|
|10||Battery volts||Read only||
The supply battery voltage
|11||Motor 1 current||Read only||The current through motor 1|
|12||Motor 2 current||Read only||The current through motor 2|
|13||Software Revision||Read only||Software Revision Number|
|14||Acceleration rate||R/W||Optional Acceleration register|
|15||Mode||R/W||Mode of operation (see below)|
|16||Command||Write only||Used for reset of encoder counts and module address changes|
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 register operates the speed and direction of motor 2. When in mode 2 or 3 Speed2 becomes a Turn register, and any value in this register is combined with the contents of Speed1 to steer the device (see below).
Turn mode looks at the speed register 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 = speed - turn
motor speed2 = speed + turn
else the direction is reverse so
motor speed1 = speed + turn
motor speed2 = speed - 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.
Each motor has its encoder count stored in an array of four bytes, together the bytes form a signed 32 bit number, the encoder count is captured on a read of the highest byte (registers 2, 6) and the subsequent lower bytes will be held until another read of the highest byte takes place. The count is stored with the highest byte in the lowest numbered register. The registers can be zeroed at any time by writing 32 (0x20) to the command register.
A reading of the voltage of the connected battery is available in this register. It reads as 10 times the voltage (121 for 12.1v).
Motor 1 and 2 current
A guide reading of the average current through the motor is available in this register. It reads approx ten times the number of Amps (25 at 2.5A).
Software Revision number
This register contains the revision number of the software in the modules PIC16F873 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 MD25 has a register to provide this. It works by using a value into the acceleration register and incrementing the power by that value. Changing between the current speed of the motors and the new speed (from speed 1 and 2 registers). 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 1.25 seconds. The register will accept values of 1 up to 10 which equates to a period of only 0.65 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 * 25ms
For example :
|Acceleration register||Time/step||Current speed||New speed||Steps||Acceleration time|
The mode register selects which mode of operation and I2C data input type the user requires. The options being:
0, (default setting) If a value of 0 is written to the mode register then the meaning of 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 registers are interpreted as signed values. The meaning of the speed registers is literal speeds in the range of -128 (full reverse) 0 (Stop) 127 (full forward).
2, Writing a value of 2 to the mode register 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 registers are interpreted as signed values.
Data is in the range of -128 (full reverse) 0 (stop) 127 (full forward)
|32||20||Resets the encoder registers to zero|
|48||30||Disables automatic speed regulation|
|49||31||Enables automatic speed regulation (default)|
|50||32||Disables 2 second timeout of motors (version 2 onwards only)|
|51||33||Enables 2 second timeout of motors when no I2C comms (default) (version 2 onwards only)|
|160||A0||1st in sequence to change I2C address|
|170||AA||2nd in sequence to change I2C address|
|165||A5||3rd in sequence to change I2C address|
Changing the I2C Bus Address
To change the I2C address of the MD25 by writing a new address you must have only one module on the bus. Write the 3 sequence commands in the correct order followed by the address. Example; to change the address of an MD25 currently at 0xB0 (the default shipped address) to 0xB4, write the following to address 0xB0; (0xA0, 0xAA, 0xA5, 0xB4 ). These commands must be sent in the correct sequence to change the I2C address, additionally, no other command may be issued in the middle of the sequence. The sequence must be sent to the command register at location 16, which means 4 separate write transactions on the I2C bus. Because of the way the MD25 works internally, there MUST be a delay of at least 5mS between the writing of each of these 4 transactions. When done, you should label the MD25 with its address, however if you do forget, just power it up without sending any commands. The MD25 will flash its address out on the green communication LED. One long flash followed by a number of shorter flashes indicating its address. Any command sent to the MD25 during this period will still be received and writing new speeds or a write to the command register will terminate the flashing.
|Address||Long Flash||Short Flashes|
Take care not to set more than one MD25 to the same address, there will be a bus collision and very unpredictable results.