Oskar Lopez de Gamboa / DRV8833

Dependents:   GGHandController

Files at this revision

API Documentation at this revision

Comitter:
xeta05
Date:
Tue Oct 15 12:25:34 2013 +0000
Child:
1:048f85990e31
Commit message:
First revision!!

Changed in this revision

DRV8833.cpp Show annotated file Show diff for this revision Revisions of this file
DRV8833.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DRV8833.cpp	Tue Oct 15 12:25:34 2013 +0000
@@ -0,0 +1,61 @@
+/* mbed simple DRV8833 H-bridge motor controller
+ * 
+ *
+ * PWM a un puente en H(DRV8833) conectado a los motores.
+ * El comportamiento del driver es el siguiente
+ *  
+ *          x_PWM1 x_PWM2    Mode
+ *            0      0       Coast/Fast decay
+ *            0      1       Reverse
+ *            1      0       Forward
+ *            1      1       Brake/slow decay
+ *15/10/2013
+**/
+
+
+#include "DRV8833.h"
+
+DRV8833::DRV8833(PinName pwm1, PinName pwm2):
+        _pwm1(pwm1), _pwm2(pwm2) 
+{
+
+    // Set initial condition of PWM
+    _pwm1.period(0.001);
+    _pwm1 = 0;
+    _pwm2.period(0.001);
+    _pwm2 = 0;
+     
+}
+
+void DRV8833::speed(float speed) 
+{
+    if (speed > 0.0)
+    {
+        _pwm1 = abs(speed);
+        _pwm2 = 0;
+    }
+    else
+    {
+      _pwm1 = 0;
+      _pwm2 = abs(speed);
+    }
+}
+void DRV8833::period(float period){
+
+    _pwm1.period(period);
+    _pwm2.period(period);
+}
+
+void DRV8833::brake(int highLow){
+
+    if(highLow == BRAKE_FAST)
+    {
+        _pwm1 = 0;
+        _pwm2 = 0;     
+    }
+    else if(highLow == BRAKE_SLOW){
+        _pwm1 = 1;
+        _pwm2 = 1; 
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DRV8833.h	Tue Oct 15 12:25:34 2013 +0000
@@ -0,0 +1,67 @@
+/* mbed simple DRV8833 H-bridge motor controller
+ * 
+ *
+ * PWM a un puente en H(DRV8833) conectado a los motores.
+ * El comportamiento del driver es el siguiente
+ *  
+ *          x_PWM1 x_PWM2    Mode
+ *            0      0       Coast/Fast decay
+ *            0      1       Reverse
+ *            1      0       Forward
+ *            1      1       Brake/slow decay
+ *15/10/2013
+*/
+
+#ifndef MBED_DRV8833
+#define MBED_DRV8833
+
+#include "mbed.h"
+
+#define BRAKE_FAST 1
+#define BRAKE_SLOW  0
+
+/** Interface to control a standard DC motor 
+ *  with an DRV8833 H-bridge motor controller
+ *  using 2 PwmOuts 
+ */
+class DRV8833 {
+public:
+
+    /** Create a DRV8833 control interface    
+     *
+     * @param pwm1 A PwmOut pin, Logic input controls state of AOUT1 
+     * @param pwm2 A PwmOut pin, Logic input controls state of AOUT2
+     * 
+     */
+    DRV8833(PinName pwm1, PinName pwm2);
+    
+    /** Set the speed of the motor
+     * 
+     * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
+     */
+    void speed(float speed);
+    
+    /** Set the period of the pwm duty cycle.
+     *
+     * Wrapper for PwmOut::period()
+     *
+     * @param seconds - Pwm duty cycle in seconds.
+     */
+    void period(float period);
+    
+    /** Brake the H-bridge to fast or slow.
+     * 
+     * Defaults to breaking fast.
+     *
+     * Brake fast(coast) => pwm1 = pwm2 = 0
+     * Brake slow        => pwm1 = pwm2 = 1
+     */
+    void brake(int highLow = BRAKE_FAST);
+
+protected:
+    PwmOut _pwm1;
+    PwmOut _pwm2;
+    
+};
+
+#endif