Test two motors using pwm with an LMD18200 H-Bridge Driver. Ramps both motors in either direction with a pwm frequency of 20kHz.

Fork of Motor by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
moose
Date:
Thu Nov 08 15:52:42 2012 +0000
Parent:
2:f265e441bcd9
Commit message:
Changed Motor to 2 input - pwm & direction

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
diff -r f265e441bcd9 -r bab4eebbf1a0 Motor.cpp
--- a/Motor.cpp	Tue Nov 23 16:16:43 2010 +0000
+++ b/Motor.cpp	Thu Nov 08 15:52:42 2012 +0000
@@ -24,21 +24,21 @@
 
 #include "mbed.h"
 
-Motor::Motor(PinName pwm, PinName fwd, PinName rev):
-        _pwm(pwm), _fwd(fwd), _rev(rev) {
+Motor::Motor(PinName pwm, PinName dir):
+        _pwm(pwm), _dir(dir) {
 
     // Set initial condition of PWM
-    _pwm.period(0.001);
+    _pwm.period(0.00005);   //20kHz
     _pwm = 0;
 
     // Initial condition of output enables
-    _fwd = 0;
-    _rev = 0;
+    _dir = 1;
+//    _rev = 0;
 }
 
 void Motor::speed(float speed) {
-    _fwd = (speed > 0.0);
-    _rev = (speed < 0.0);
+    _dir = (speed > 0.0);
+//    _rev = (speed < 0.0);
     _pwm = abs(speed);
 }
 
diff -r f265e441bcd9 -r bab4eebbf1a0 Motor.h
--- a/Motor.h	Tue Nov 23 16:16:43 2010 +0000
+++ b/Motor.h	Thu Nov 08 15:52:42 2012 +0000
@@ -38,7 +38,7 @@
      * @param fwd A DigitalOut, set high when the motor should go forward
      * @param rev A DigitalOut, set high when the motor should go backwards
      */
-    Motor(PinName pwm, PinName fwd, PinName rev);
+    Motor(PinName pwm, PinName dir);
     
     /** Set the speed of the motor
      * 
@@ -48,8 +48,8 @@
 
 protected:
     PwmOut _pwm;
-    DigitalOut _fwd;
-    DigitalOut _rev;
+    DigitalOut _dir;
+//    DigitalOut _rev;
 
 };