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

Dependents:   GGHandController

Committer:
xeta05
Date:
Tue Oct 15 12:25:34 2013 +0000
Revision:
0:80e26be59f41
Child:
1:048f85990e31
First revision!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xeta05 0:80e26be59f41 1 /* mbed simple DRV8833 H-bridge motor controller
xeta05 0:80e26be59f41 2 *
xeta05 0:80e26be59f41 3 *
xeta05 0:80e26be59f41 4 * PWM a un puente en H(DRV8833) conectado a los motores.
xeta05 0:80e26be59f41 5 * El comportamiento del driver es el siguiente
xeta05 0:80e26be59f41 6 *
xeta05 0:80e26be59f41 7 * x_PWM1 x_PWM2 Mode
xeta05 0:80e26be59f41 8 * 0 0 Coast/Fast decay
xeta05 0:80e26be59f41 9 * 0 1 Reverse
xeta05 0:80e26be59f41 10 * 1 0 Forward
xeta05 0:80e26be59f41 11 * 1 1 Brake/slow decay
xeta05 0:80e26be59f41 12 *15/10/2013
xeta05 0:80e26be59f41 13 */
xeta05 0:80e26be59f41 14
xeta05 0:80e26be59f41 15 #ifndef MBED_DRV8833
xeta05 0:80e26be59f41 16 #define MBED_DRV8833
xeta05 0:80e26be59f41 17
xeta05 0:80e26be59f41 18 #include "mbed.h"
xeta05 0:80e26be59f41 19
xeta05 0:80e26be59f41 20 #define BRAKE_FAST 1
xeta05 0:80e26be59f41 21 #define BRAKE_SLOW 0
xeta05 0:80e26be59f41 22
xeta05 0:80e26be59f41 23 /** Interface to control a standard DC motor
xeta05 0:80e26be59f41 24 * with an DRV8833 H-bridge motor controller
xeta05 0:80e26be59f41 25 * using 2 PwmOuts
xeta05 0:80e26be59f41 26 */
xeta05 0:80e26be59f41 27 class DRV8833 {
xeta05 0:80e26be59f41 28 public:
xeta05 0:80e26be59f41 29
xeta05 0:80e26be59f41 30 /** Create a DRV8833 control interface
xeta05 0:80e26be59f41 31 *
xeta05 0:80e26be59f41 32 * @param pwm1 A PwmOut pin, Logic input controls state of AOUT1
xeta05 0:80e26be59f41 33 * @param pwm2 A PwmOut pin, Logic input controls state of AOUT2
xeta05 0:80e26be59f41 34 *
xeta05 0:80e26be59f41 35 */
xeta05 0:80e26be59f41 36 DRV8833(PinName pwm1, PinName pwm2);
xeta05 0:80e26be59f41 37
xeta05 0:80e26be59f41 38 /** Set the speed of the motor
xeta05 0:80e26be59f41 39 *
xeta05 0:80e26be59f41 40 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
xeta05 0:80e26be59f41 41 */
xeta05 0:80e26be59f41 42 void speed(float speed);
xeta05 0:80e26be59f41 43
xeta05 0:80e26be59f41 44 /** Set the period of the pwm duty cycle.
xeta05 0:80e26be59f41 45 *
xeta05 0:80e26be59f41 46 * Wrapper for PwmOut::period()
xeta05 0:80e26be59f41 47 *
xeta05 0:80e26be59f41 48 * @param seconds - Pwm duty cycle in seconds.
xeta05 0:80e26be59f41 49 */
xeta05 0:80e26be59f41 50 void period(float period);
xeta05 0:80e26be59f41 51
xeta05 0:80e26be59f41 52 /** Brake the H-bridge to fast or slow.
xeta05 0:80e26be59f41 53 *
xeta05 0:80e26be59f41 54 * Defaults to breaking fast.
xeta05 0:80e26be59f41 55 *
xeta05 0:80e26be59f41 56 * Brake fast(coast) => pwm1 = pwm2 = 0
xeta05 0:80e26be59f41 57 * Brake slow => pwm1 = pwm2 = 1
xeta05 0:80e26be59f41 58 */
xeta05 0:80e26be59f41 59 void brake(int highLow = BRAKE_FAST);
xeta05 0:80e26be59f41 60
xeta05 0:80e26be59f41 61 protected:
xeta05 0:80e26be59f41 62 PwmOut _pwm1;
xeta05 0:80e26be59f41 63 PwmOut _pwm2;
xeta05 0:80e26be59f41 64
xeta05 0:80e26be59f41 65 };
xeta05 0:80e26be59f41 66
xeta05 0:80e26be59f41 67 #endif