motor drive libary to use speed control, coasting and dynamic braking. NOTE, dynamic braking my result in large currents. this may or may not set the motor driver on fire/break it/other undesired effects. so read the data sheet folks.

Dependents:   Test

Fork of Motordriver by Christopher Hasler

Committer:
littlexc
Date:
Thu Nov 11 15:32:55 2010 +0000
Revision:
1:3da7302dc9ae
Parent:
0:edc152f119b7
Child:
2:2dc873322032
this libary prevents throwing the motor from full foward to full reverse. to change direction, the motor must first come to a full stop, ie, coast, break or set speed to = 0.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
littlexc 0:edc152f119b7 1 /*motor driver libary modified from the following libary,
littlexc 0:edc152f119b7 2 *
littlexc 0:edc152f119b7 3 * mbed simple H-bridge motor controller
littlexc 0:edc152f119b7 4 * Copyright (c) 2007-2010, sford
littlexc 0:edc152f119b7 5 *
littlexc 0:edc152f119b7 6 * by Christopher Hasler.
littlexc 0:edc152f119b7 7 *
littlexc 0:edc152f119b7 8 * from sford's libary,
littlexc 0:edc152f119b7 9 *
littlexc 0:edc152f119b7 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
littlexc 0:edc152f119b7 11 * of this software and associated documentation files (the "Software"), to deal
littlexc 0:edc152f119b7 12 * in the Software without restriction, including without limitation the rights
littlexc 0:edc152f119b7 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
littlexc 0:edc152f119b7 14 * copies of the Software, and to permit persons to whom the Software is
littlexc 0:edc152f119b7 15 * furnished to do so, subject to the following conditions:
littlexc 0:edc152f119b7 16 *
littlexc 0:edc152f119b7 17 * The above copyright notice and this permission notice shall be included in
littlexc 0:edc152f119b7 18 * all copies or substantial portions of the Software.
littlexc 0:edc152f119b7 19 *
littlexc 0:edc152f119b7 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
littlexc 0:edc152f119b7 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
littlexc 0:edc152f119b7 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
littlexc 0:edc152f119b7 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
littlexc 0:edc152f119b7 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
littlexc 0:edc152f119b7 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
littlexc 0:edc152f119b7 26 * THE SOFTWARE.
littlexc 0:edc152f119b7 27 */
littlexc 0:edc152f119b7 28
littlexc 0:edc152f119b7 29 #ifndef MBED_MOTOR_H
littlexc 0:edc152f119b7 30 #define MBED_MOTOR_H
littlexc 0:edc152f119b7 31
littlexc 0:edc152f119b7 32 #include "mbed.h"
littlexc 0:edc152f119b7 33
littlexc 0:edc152f119b7 34 /** Interface to control a standard DC motor
littlexc 0:edc152f119b7 35 * with an H-bridge using a PwmOut and 2 DigitalOuts
littlexc 0:edc152f119b7 36 */
littlexc 0:edc152f119b7 37 class Motor {
littlexc 0:edc152f119b7 38 public:
littlexc 0:edc152f119b7 39
littlexc 0:edc152f119b7 40 /** Create a motor control interface
littlexc 0:edc152f119b7 41 *
littlexc 0:edc152f119b7 42 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
littlexc 0:edc152f119b7 43 * @param fwd A DigitalOut, set high when the motor should go forward
littlexc 0:edc152f119b7 44 * @param rev A DigitalOut, set high when the motor should go backwards
littlexc 0:edc152f119b7 45 * @param set if the motor driver is able to do braking 0 false 1 true. (addition)
littlexc 0:edc152f119b7 46 */
littlexc 0:edc152f119b7 47 Motor(PinName pwm, PinName fwd, PinName rev, int brakeable);
littlexc 0:edc152f119b7 48
littlexc 0:edc152f119b7 49 /** Set the speed of the motor (addition)
littlexc 0:edc152f119b7 50 *
littlexc 0:edc152f119b7 51 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
littlexc 0:edc152f119b7 52 */
littlexc 0:edc152f119b7 53 void speed(float speed);
littlexc 0:edc152f119b7 54
littlexc 0:edc152f119b7 55 /** Set the the motor to coast
littlexc 0:edc152f119b7 56 *
littlexc 0:edc152f119b7 57 * @param void motor coasts until another instruction is recived
littlexc 0:edc152f119b7 58 */
littlexc 0:edc152f119b7 59
littlexc 0:edc152f119b7 60 void coast(void);
littlexc 0:edc152f119b7 61
littlexc 0:edc152f119b7 62 /** Set the motor to dynamicaly brake (addition)
littlexc 0:edc152f119b7 63 *
littlexc 0:edc152f119b7 64 * @param void motor dynamicaly brakes until another instruction is recived
littlexc 0:edc152f119b7 65 */
littlexc 0:edc152f119b7 66
littlexc 0:edc152f119b7 67 void stop(void);
littlexc 0:edc152f119b7 68
littlexc 0:edc152f119b7 69 protected:
littlexc 0:edc152f119b7 70 PwmOut _pwm;
littlexc 0:edc152f119b7 71 DigitalOut _fwd;
littlexc 0:edc152f119b7 72 DigitalOut _rev;
littlexc 0:edc152f119b7 73 int Brakeable; // (addition)
littlexc 1:3da7302dc9ae 74 int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
littlexc 0:edc152f119b7 75
littlexc 0:edc152f119b7 76 };
littlexc 0:edc152f119b7 77
littlexc 0:edc152f119b7 78 #endif