Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver

Files at this revision

API Documentation at this revision

Comitter:
humlet
Date:
Thu Mar 21 17:06:45 2013 +0000
Parent:
4:5aec3b59fc10
Commit message:
final !?

Changed in this revision

TB6612FNG.cpp Show annotated file Show diff for this revision Revisions of this file
TB6612FNG.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5aec3b59fc10 -r 535c74e61e36 TB6612FNG.cpp
--- a/TB6612FNG.cpp	Thu Mar 14 18:41:55 2013 +0000
+++ b/TB6612FNG.cpp	Thu Mar 21 17:06:45 2013 +0000
@@ -56,4 +56,10 @@
     m_on=false;
     m_ctrl1=1;
     m_ctrl2=1;
+}
+
+void TB6612FNG::setZeroDCReaction(bool brakeOnZeroDC)
+{
+    m_brakeOnZeroDC=brakeOnZeroDC;
+    on();
 }
\ No newline at end of file
diff -r 5aec3b59fc10 -r 535c74e61e36 TB6612FNG.h
--- a/TB6612FNG.h	Thu Mar 14 18:41:55 2013 +0000
+++ b/TB6612FNG.h	Thu Mar 21 17:06:45 2013 +0000
@@ -6,13 +6,13 @@
 /// Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver
 class TB6612FNG
 {
-    PwmOut m_pwm;
+    PwmOut m_pwm;  
     DigitalOut m_ctrl1;
     DigitalOut m_ctrl2;
-    int m_pw;
-    bool m_on;
-    bool m_brakeOnZeroDC;
-    int m_period;
+    int m_pw;  // PWM pulse width setting
+    bool m_on; // motor satus
+    bool m_brakeOnZeroDC; // behaviour for zero duty cycle
+    int m_period;  // PWM period setting
 
 public:
     /** Create TB6612FNG object connected to the specified mbed pins
@@ -25,7 +25,9 @@
     TB6612FNG(PinName pwm, PinName ctrl1, PinName ctrl2, int pwmPeriod=100, bool brakeOnZeroDC=true);
     
     /// Sets the PWM pulse width
-    /// @param pw is the PWM pulse width setting in µs. With the default PWM period of 100µs (f=10kHz) this value is equivalent to the duty cycle.
+    /// @param pw is the PWM pulse width setting in µs.
+    /// The sign of the given pulsewidth defines the direction.
+    /// With the default PWM period of 100µs (f=10kHz) this value is equivalent to the duty cycle.
     void setPulseWidth(int pw);
     
     /// activates the motor at the duty cycle selected with setPulseWidth()
@@ -37,8 +39,14 @@
     /// brakes the motor by shorting it 
     void brake();
     
+    /// set behaviour for zero DC setting
+    /// @param brakeOnZeroDC true: The motor brakes on zero pulse width setting. 
+    ///                      false: The motor output is set to high impedance
+    void setZeroDCReaction(bool brakeOnZeroDC);
+    
     /// pulse width assignment
-    /// @param pw is the PWM pulse width setting in µs
+    /// @param pw is the PWM pulse width setting in µs 
+    /// @see setPulseWidth(int pw)
     void operator=(int pw) {
         setPulseWidth(pw);
     }