This is a library that drives a stepper motor with given parameters for speed and direction.

Dependents:   RaceTimer

About

This is a stepper motor library that is based on the sMotor library by Samuel Matildes (sam.naeec@gmail.com). It was designed to drive specifically a 5718m-05e-05 stepper motor in conjunction with an L293NE quad h-bridge chip. I am not responsible for any damage caused due to the execution of this program on your hardware as I can only confirm that it works for the above specified model. High torque mode is currently not complete.

Files at this revision

API Documentation at this revision

Comitter:
mdu7078
Date:
Mon May 13 16:19:54 2013 +0000
Parent:
0:acf5b8fc382b
Commit message:
First commit of mMotor library

Changed in this revision

mMotor.cpp Show annotated file Show diff for this revision Revisions of this file
mMotor.h Show annotated file Show diff for this revision Revisions of this file
diff -r acf5b8fc382b -r 6e0a307d0f9b mMotor.cpp
--- a/mMotor.cpp	Wed Apr 24 17:39:30 2013 +0000
+++ b/mMotor.cpp	Mon May 13 16:19:54 2013 +0000
@@ -58,6 +58,10 @@
 
         wait_us(motorSpeed); // wait time defines the speed 
     }
+    _M0 = 0;
+    _M1 = 0;
+    _M2 = 0;
+    _M3 = 0;
 }
 
 void mMotor::clockwise() { // rotate the motor 1 step clockwise 
@@ -95,7 +99,87 @@
 
         wait_us(motorSpeed); // wait time defines the speed 
     }
+    _M0 = 0;
+    _M1 = 0;
+    _M2 = 0;
+    _M3 = 1;
 }
+
+void mMotor::ht_clockwise() { // rotate the motor 1 step clockwise 
+    for (int i = 0; i < 4; i++) {
+        switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+            case 0: {
+                _M0=1;
+                _M1=0;
+                _M2=0;
+                _M3=0;
+            }
+            break;
+            case 1: {
+                _M0=0;
+                _M1=1;
+                _M2=0;
+                _M3=0;
+            }
+            break;
+            case 2: {
+                _M0=0;
+                _M1=0;
+                _M2=1;
+                _M3=0;
+            }
+            break;
+            case 3: {
+                _M0=0;
+                _M1=0;
+                _M2=0;
+                _M3=1;
+            }
+            break;
+        }
+
+        wait_us(motorSpeed); // wait time defines the speed 
+    }
+}
+
+void mMotor::ht_counterclockwise() { // rotate the motor 1 step anticlockwise 
+    for (int i = 0; i < 4; i++) {
+        switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+            case 0: {
+                _M0=0;
+                _M1=0;
+                _M2=0;
+                _M3=1;
+            }
+            break;
+            case 1: {
+                _M0=0;
+                _M1=0;
+                _M2=1;
+                _M3=0;
+            }
+            break;
+            case 2: {
+                _M0=0;
+                _M1=1;
+                _M2=0;
+                _M3=0;
+            }
+            break;
+            case 3: {
+                _M0=1;
+                _M1=0;
+                _M2=0;
+                _M3=0;
+            }
+            break;
+        }
+
+        wait_us(motorSpeed); // wait time defines the speed 
+    }
+}
+
+
 void mMotor::step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- right, 1- left), speed (default 1200)
     int count=0; // initalize step count
     motorSpeed=speed; //set motor speed
@@ -110,4 +194,20 @@
             count++;
         } while (count<num_steps);// turn number of steps applied 
 
+}
+
+void mMotor::ht_step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- right, 1- left), speed (default 1200)
+    int count=0; // initalize step count
+    motorSpeed=speed; //set motor speed
+    if (direction==0) // turn clockwise
+        do {
+            ht_clockwise();
+            count++;
+        } while (count<num_steps); // turn number of steps applied 
+    else if (direction==1)// turn anticlockwise
+        do {
+            ht_counterclockwise();
+            count++;
+        } while (count<num_steps);// turn number of steps applied 
+
 }
\ No newline at end of file
diff -r acf5b8fc382b -r 6e0a307d0f9b mMotor.h
--- a/mMotor.h	Wed Apr 24 17:39:30 2013 +0000
+++ b/mMotor.h	Mon May 13 16:19:54 2013 +0000
@@ -20,9 +20,15 @@
 
     mMotor(PinName M0, PinName M1, PinName M2, PinName M3); //motor constructor
 
+    /* Low Torque mode */
     void step(int num_steps, int direction, int speed);
     void counterclockwise();
     void clockwise();
+    
+    /* High Torque mode */
+    void ht_step(int num_steps, int direction, int speed);
+    void ht_counterclockwise();
+    void ht_clockwise();
 
 
 private: