Library to use RioRand H Bridge

Files at this revision

API Documentation at this revision

Comitter:
mitchpang
Date:
Thu Dec 03 06:35:58 2015 +0000
Commit message:
First Commit. Base code taken From TB6612FNG library by Robert Abad

Changed in this revision

RioRandHBridge.cpp Show annotated file Show diff for this revision Revisions of this file
RioRandHBridge.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 08d0e159793b RioRandHBridge.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RioRandHBridge.cpp	Thu Dec 03 06:35:58 2015 +0000
@@ -0,0 +1,93 @@
+/* File: RioRandHBridge.h
+ * Author: Mitchell Pang      Copyright (c) 2013
+ *
+ * Desc: driver for RioRandHBridge Motor Driver.  For further details see
+ *       header file, RioRandHBridge.h
+ */
+
+#include "mbed.h"
+#include "RioRandHBridge.h"
+
+#define SIGNAL_HIGH     (1)
+#define SIGNAL_LOW      (0)
+
+RioRandHBridge::RioRandHBridge( PinName pinPwm1, PinName pinDir1,
+                      PinName pinPwm2, PinName pinDir2
+                      ) :
+pwm1(pinPwm1),
+Dir1(pinDir1),
+pwm2(pinPwm2),
+Dir2(pinDir2)
+{
+    Dir1 = SIGNAL_LOW;
+    Dir2 = SIGNAL_LOW;
+    pwm1.period(RioRandHBridge_PWM_PERIOD_DEFAULT);
+    pwm1 = RioRandHBridge_PWM_PULSEWIDTH_DEFAULT;
+    pwm2.period(RioRandHBridge_PWM_PERIOD_DEFAULT);
+    pwm2 = RioRandHBridge_PWM_PULSEWIDTH_DEFAULT;
+}
+
+void RioRandHBridge::setpwm1(float fPeriod, float fPulsewidth)
+{
+    pwm1.period(fPeriod);
+    pwm1 = fPulsewidth;
+}
+
+void RioRandHBridge::setpwm1period(float fPeriod)
+{
+    pwm1.period(fPeriod);
+}
+
+void RioRandHBridge::setpwm1pulsewidth(float fPulsewidth)
+{
+    pwm1 = fPulsewidth;
+}
+
+void RioRandHBridge::setpwm2(float fPeriod, float fPulsewidth)
+{
+    pwm2.period(fPeriod);
+    pwm2 = fPulsewidth;
+}
+
+void RioRandHBridge::setpwm2period(float fPeriod)
+{
+    pwm2.period(fPeriod);
+}
+
+void RioRandHBridge::setpwm2pulsewidth(float fPulsewidth)
+{
+    pwm2 = fPulsewidth;
+}
+
+
+void RioRandHBridge::motor1_stop(void)
+{
+    pwm1 = 0.0;
+}
+
+void RioRandHBridge::motor1_ccw(void)
+{
+    Dir1 = SIGNAL_LOW;
+}
+
+void RioRandHBridge::motor1_cw(void)
+{
+    Dir1 = SIGNAL_HIGH;
+}
+
+void RioRandHBridge::motor2_stop(void)
+{
+    pwm2 = 0.0;
+}
+
+void RioRandHBridge::motor2_ccw(void)
+{
+    Dir2 = SIGNAL_LOW;
+}
+
+void RioRandHBridge::motor2_cw(void)
+{
+    Dir2 = SIGNAL_HIGH;
+}
+
+
diff -r 000000000000 -r 08d0e159793b RioRandHBridge.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RioRandHBridge.h	Thu Dec 03 06:35:58 2015 +0000
@@ -0,0 +1,35 @@
+#ifndef __RRANDHBRIDGE_H__
+#define __RRANDHBridge_H__
+
+#include "mbed.h"
+
+#define RioRandHBridge_PWM_PERIOD_DEFAULT      (0.00002)   // 50KHz
+#define RioRandHBridge_PWM_PULSEWIDTH_DEFAULT  (0.50)      // 50% duty cycle
+ 
+class RioRandHBridge
+{
+public:
+    RioRandHBridge( PinName pinPwm1, PinName pinDir1,
+               PinName pinPwm2, PinName pinDir2
+               );
+    void setpwm1(float fPeriod, float fPulsewidth);
+    void setpwm1period(float fPeriod);
+    void setpwm1pulsewidth(float fPulsewidth);
+    void setpwm2(float fPeriod, float fPulsewidth);
+    void setpwm2period(float fPeriod);
+    void setpwm2pulsewidth(float fPulsewidth);
+    void motor1_stop(void);
+    void motor1_ccw(void);
+    void motor1_cw(void);
+    void motor2_stop(void);
+    void motor2_ccw(void);
+    void motor2_cw(void);
+    
+public:
+    PwmOut pwm1;
+    DigitalOut Dir1;
+    PwmOut pwm2;
+    DigitalOut Dir2;
+};
+
+#endif /* __RRANDHBRIDGE_H__ */
\ No newline at end of file