WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Generic PWM motor driver

Controls DC motors using pulse width modulation (PWM).
This is a 'catch all' in case your specific motor driver is not specifically listed.
Note that you cannot connect a DC motor directly as they require too much current and you will blow your processor - you must use a motor controller.
This module assumes that your motor controller has three inputs which can be used to achieve the following states:-
MotorPWMtable.png
Motor (3 Pin)
Adding a 'Motor (3 Pin)' to the list means that the signals will be generated directly on the selected pins.
Motor (2 Pin)
If you are short of I/O pins then you can drive each motor with only two I/O pins but you need to add some additional hardware (which I call a 'tri-state switch').
tristate.png
This circuit will take the output of the two pins from your processor and convert it into the three control pins required for the optimum control of your motor driver. The hardware PWM pin is forwarded on to the enable pin of the driver and is used to set the speed of rotation by alternating between 'full speed' and 'coast'. The direction pin is forwarded on to one of the inputs to the driver and is also inverted by the transistor for the second input to the driver.
By making the direction pin into a high impedance input pin then the resistors will guarantee that both of the inputs to the driver have the same value which will result in the brake being applied.
If you want to make your own motor controller board that can be used with this hardware then read http://www.societyofrobots.com/member_tutorials/node/159 for a range of DC and stepper motor boards based on the L293D, L298 or SN754410 which can be driven in this way.
Since we are using hardware PWM then the pulses sent to the motors are very exact. This library can cope with any number of motors and so the only real limitation is the number of PWM channels that your micro controller provides.
Example
Just use the generic example in Actuators
Function Summary

Valid XHTML 1.0 Transitional