Mbed library to control a motor via DRV8833 H-bridge motor controller. Uses two Pwmouts.

Dependents:   GGHandController

Committer:
xeta05
Date:
Tue Dec 10 11:17:13 2013 +0000
Revision:
3:0aa2cdeb2e2b
Parent:
2:ccc9acaebd38
docs updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xeta05 3:0aa2cdeb2e2b 1 /*
xeta05 3:0aa2cdeb2e2b 2 * @file DRV8833.h
xeta05 3:0aa2cdeb2e2b 3 * @author Oskar Lopez de Gamboa
xeta05 3:0aa2cdeb2e2b 4 *
xeta05 3:0aa2cdeb2e2b 5 * @section LICENSE
xeta05 3:0aa2cdeb2e2b 6 *
xeta05 3:0aa2cdeb2e2b 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
xeta05 3:0aa2cdeb2e2b 8 * and associated documentation files (the "Software"), to deal in the Software without restriction,
xeta05 3:0aa2cdeb2e2b 9 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
xeta05 3:0aa2cdeb2e2b 10 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
xeta05 3:0aa2cdeb2e2b 11 * furnished to do so, subject to the following conditions:
xeta05 3:0aa2cdeb2e2b 12 *
xeta05 3:0aa2cdeb2e2b 13 * The above copyright notice and this permission notice shall be included in all copies or
xeta05 3:0aa2cdeb2e2b 14 * substantial portions of the Software.
xeta05 3:0aa2cdeb2e2b 15 *
xeta05 3:0aa2cdeb2e2b 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
xeta05 3:0aa2cdeb2e2b 17 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
xeta05 3:0aa2cdeb2e2b 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
xeta05 3:0aa2cdeb2e2b 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
xeta05 3:0aa2cdeb2e2b 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
xeta05 3:0aa2cdeb2e2b 21 *
xeta05 3:0aa2cdeb2e2b 22 * @section DESCRIPTION
xeta05 3:0aa2cdeb2e2b 23 *
xeta05 3:0aa2cdeb2e2b 24 * mbed simple DRV8833 H-bridge motor controller
xeta05 0:80e26be59f41 25 *
xeta05 0:80e26be59f41 26 *
xeta05 0:80e26be59f41 27 * PWM a un puente en H(DRV8833) conectado a los motores.
xeta05 1:048f85990e31 28 * El comportamiento del driver es el siguiente:
xeta05 0:80e26be59f41 29 *
xeta05 0:80e26be59f41 30 * x_PWM1 x_PWM2 Mode
xeta05 0:80e26be59f41 31 * 0 0 Coast/Fast decay
xeta05 0:80e26be59f41 32 * 0 1 Reverse
xeta05 0:80e26be59f41 33 * 1 0 Forward
xeta05 0:80e26be59f41 34 * 1 1 Brake/slow decay
xeta05 3:0aa2cdeb2e2b 35 *10/12/2013
xeta05 0:80e26be59f41 36 */
xeta05 0:80e26be59f41 37 #ifndef MBED_DRV8833
xeta05 0:80e26be59f41 38 #define MBED_DRV8833
xeta05 0:80e26be59f41 39
xeta05 0:80e26be59f41 40 #include "mbed.h"
xeta05 0:80e26be59f41 41
xeta05 2:ccc9acaebd38 42 #define COAST 1
xeta05 2:ccc9acaebd38 43 #define BRAKE 0
xeta05 0:80e26be59f41 44
xeta05 0:80e26be59f41 45 /** Interface to control a standard DC motor
xeta05 0:80e26be59f41 46 * with an DRV8833 H-bridge motor controller
xeta05 0:80e26be59f41 47 * using 2 PwmOuts
xeta05 0:80e26be59f41 48 */
xeta05 0:80e26be59f41 49 class DRV8833 {
xeta05 0:80e26be59f41 50 public:
xeta05 0:80e26be59f41 51
xeta05 1:048f85990e31 52 /** Creates a DRV8833(H-bridge motor controller) control interface
xeta05 0:80e26be59f41 53 *
xeta05 1:048f85990e31 54 * @param pwm1 A PwmOut pin, tied to the AIN1 Logic input, controls state of AOUT1
xeta05 1:048f85990e31 55 * @param pwm2 A PwmOut pin, tied to the AIN2 Logic input controls state of AOUT2
xeta05 0:80e26be59f41 56 *
xeta05 0:80e26be59f41 57 */
xeta05 0:80e26be59f41 58 DRV8833(PinName pwm1, PinName pwm2);
xeta05 0:80e26be59f41 59
xeta05 0:80e26be59f41 60 /** Set the speed of the motor
xeta05 0:80e26be59f41 61 *
xeta05 0:80e26be59f41 62 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
xeta05 0:80e26be59f41 63 */
xeta05 0:80e26be59f41 64 void speed(float speed);
xeta05 0:80e26be59f41 65
xeta05 0:80e26be59f41 66 /** Set the period of the pwm duty cycle.
xeta05 0:80e26be59f41 67 *
xeta05 0:80e26be59f41 68 * Wrapper for PwmOut::period()
xeta05 0:80e26be59f41 69 *
xeta05 0:80e26be59f41 70 * @param seconds - Pwm duty cycle in seconds.
xeta05 0:80e26be59f41 71 */
xeta05 0:80e26be59f41 72 void period(float period);
xeta05 0:80e26be59f41 73
xeta05 2:ccc9acaebd38 74 /** Brake the H-bridge coast or brake.
xeta05 0:80e26be59f41 75 *
xeta05 2:ccc9acaebd38 76 * Defaults to coast.
xeta05 3:0aa2cdeb2e2b 77 * @param mode - Braking mode.COAST(default)or BRAKE.
xeta05 3:0aa2cdeb2e2b 78 *
xeta05 0:80e26be59f41 79 */
xeta05 2:ccc9acaebd38 80 void brake(int mode = COAST);
xeta05 0:80e26be59f41 81
xeta05 0:80e26be59f41 82 protected:
xeta05 0:80e26be59f41 83 PwmOut _pwm1;
xeta05 0:80e26be59f41 84 PwmOut _pwm2;
xeta05 0:80e26be59f41 85
xeta05 0:80e26be59f41 86 };
xeta05 0:80e26be59f41 87
xeta05 0:80e26be59f41 88 #endif