A fork of a fine man's work. simplified. No microstepping etc, just a work in progress

Fork of BipoarStepperMotor by Harsha vardan

Files at this revision

API Documentation at this revision

Comitter:
InBrewJ
Date:
Tue Feb 03 03:44:45 2015 +0000
Parent:
5:f9404f00deda
Commit message:
changed the names to "lsMotor.h" etc - for "Linear Stepper Motor"

Changed in this revision

lsMotor.cpp Show annotated file Show diff for this revision Revisions of this file
lsMotor.h Show annotated file Show diff for this revision Revisions of this file
sMotor.cpp Show diff for this revision Revisions of this file
sMotor.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lsMotor.cpp	Tue Feb 03 03:44:45 2015 +0000
@@ -0,0 +1,139 @@
+/*
+##############################################
+##    Program Created by Harshavardan61     ##
+##############################################
+        ---- harshavardan61@gmail.com -----
+        
+Extended by Jason Brewer 2015
+
+*/
+
+#include "lsMotor.h"
+#include "mbed.h"
+
+lsMotor::lsMotor(PinName A0, PinName A1, PinName A2, PinName A3, PinName motorEnable, const int maxSteps) : _A0(A0), _A1(A1), 
+                        _A2(A2), _A3(A3), _motorEnable(motorEnable) { 
+    _A0=0;
+    _A1=0;
+    _A2=0;
+    _A3=0;
+    _motorEnable = 0;
+    _maxSteps = maxSteps;
+    _motorPosition = maxSteps;
+}
+
+//UP
+void lsMotor::up(int num_steps) { // rotate the motor num_steps UP
+    short subStep = 0;
+    //printf("In UP\n");
+    for (int i = 0; i < num_steps && _motorPosition < _maxSteps; i++) { 
+        //printf("numsteps: %d Doing UP %d pos: %d\n", num_steps, i, _motorPosition);               
+        switch (subStep) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+            case 0: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            break;
+            case 1: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=1;
+            }
+            break;
+            case 2: {
+                _A0=0;
+                _A1=1;
+                _A2=1;
+                _A3=0;
+            }
+            break;
+            case 3: {
+                _A0=1;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            break;            
+        }
+
+        subStep++;
+        subStep %= 4;        
+        _motorPosition++;
+        wait_ms(_motorSpeed);
+    }
+    /*_A0=0;
+    _A1=0;
+    _A2=0;
+    _A3=0;*/
+    return;
+}
+
+// DOWN
+void lsMotor::down(int num_steps) { // rotate the motor num_steps DOWN
+    short subStep = 0;   
+    //printf("In DOWN\n"); 
+    for (int i = 0; i < num_steps && _motorPosition > 0; i++) { 
+        //printf("numsteps: %d Doing DOWN %d pos: %d\n", num_steps, i, _motorPosition);           
+        switch (subStep) {
+            case 0: {
+                _A0=1;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            break;
+            case 1: {
+                _A0=0;
+                _A1=1;
+                _A2=1;
+                _A3=0;
+            }
+            break;
+            case 2: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=1;
+            }
+            break;
+            case 3: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            break;            
+        }
+    
+        subStep++;
+        subStep %= 4;
+        _motorPosition--;
+        wait_ms(_motorSpeed); // wait time defines the speed 
+    }
+    /*_A0=0;
+    _A1=0;
+    _A2=0;
+    _A3=0;*/
+    return;
+}
+
+void lsMotor::setMotorPosition(int position) {
+    _motorPosition = position;
+    return;
+}
+
+void lsMotor::step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- down, 1- up), speed in ms
+    _motorSpeed = speed; //set motor speed
+    if (!direction){ // shaft DOWN
+            _motorEnable = 1;
+            down(num_steps);
+            _motorEnable = 0;
+    }else if (direction){// Shaft UP
+            _motorEnable = 1;
+            up(num_steps);
+            _motorEnable = 0; 
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lsMotor.h	Tue Feb 03 03:44:45 2015 +0000
@@ -0,0 +1,45 @@
+/*
+##############################################
+##Original Program Created by Harshavardan61##
+##############################################
+        ---- harshavardan61@gmail.com -----
+Extended by Jason Brewer 2015
+to adapt to the stepper motor + linear actuator
+supplied by Selim Yilmaz
+
+Now includes functional stepper pulses, a motor enable pin
+(motor and l293D were getting very warm if the enable pin was
+always HIGH)
+
+*/
+#ifndef MBED_LSMOTOR_H
+#define MBED_LSMOTOR_H
+
+#include "mbed.h"
+
+class lsMotor {
+public:
+
+    lsMotor(PinName A0, PinName A1, PinName A2, PinName A3, PinName motorEnable, const int maxSteps); //motor constructor
+
+    void setMotorPosition(int position); // for use ONLY if the stepper init is skipped
+    int getMotorPosition(void){ return _motorPosition; }; 
+    void step(int num_steps, int direction, int speed);
+    void up(int num_steps);
+    void down(int num_steps);
+
+
+private:
+
+    DigitalOut _A0;
+    DigitalOut _A1;
+    DigitalOut _A2;
+    DigitalOut _A3;
+    DigitalOut _motorEnable;
+    int _motorPosition;
+    int _maxSteps;
+    int _motorSpeed; 
+
+};
+
+#endif
\ No newline at end of file
--- a/sMotor.cpp	Tue Feb 03 03:41:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
-##############################################
-##    Program Created by Harshavardan61     ##
-##############################################
-        ---- harshavardan61@gmail.com -----
-        
-Extended by Jason Brewer 2015
-
-*/
-
-#include "sMotor.h"
-#include "mbed.h"
-
-sMotor::sMotor(PinName A0, PinName A1, PinName A2, PinName A3, PinName motorEnable, const int maxSteps) : _A0(A0), _A1(A1), 
-                        _A2(A2), _A3(A3), _motorEnable(motorEnable) { 
-    _A0=0;
-    _A1=0;
-    _A2=0;
-    _A3=0;
-    _motorEnable = 0;
-    _maxSteps = maxSteps;
-    _motorPosition = maxSteps;
-}
-
-//UP
-void sMotor::up(int num_steps) { // rotate the motor num_steps UP
-    short subStep = 0;
-    //printf("In UP\n");
-    for (int i = 0; i < num_steps && _motorPosition < _maxSteps; i++) { 
-        //printf("numsteps: %d Doing UP %d pos: %d\n", num_steps, i, _motorPosition);               
-        switch (subStep) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
-            case 0: {
-                _A0=1;
-                _A1=0;
-                _A2=0;
-                _A3=1;
-            }
-            break;
-            case 1: {
-                _A0=0;
-                _A1=0;
-                _A2=1;
-                _A3=1;
-            }
-            break;
-            case 2: {
-                _A0=0;
-                _A1=1;
-                _A2=1;
-                _A3=0;
-            }
-            break;
-            case 3: {
-                _A0=1;
-                _A1=1;
-                _A2=0;
-                _A3=0;
-            }
-            break;            
-        }
-
-        subStep++;
-        subStep %= 4;        
-        _motorPosition++;
-        wait_ms(_motorSpeed);
-    }
-    /*_A0=0;
-    _A1=0;
-    _A2=0;
-    _A3=0;*/
-    return;
-}
-
-// DOWN
-void sMotor::down(int num_steps) { // rotate the motor num_steps DOWN
-    short subStep = 0;   
-    //printf("In DOWN\n"); 
-    for (int i = 0; i < num_steps && _motorPosition > 0; i++) { 
-        //printf("numsteps: %d Doing DOWN %d pos: %d\n", num_steps, i, _motorPosition);           
-        switch (subStep) {
-            case 0: {
-                _A0=1;
-                _A1=1;
-                _A2=0;
-                _A3=0;
-            }
-            break;
-            case 1: {
-                _A0=0;
-                _A1=1;
-                _A2=1;
-                _A3=0;
-            }
-            break;
-            case 2: {
-                _A0=0;
-                _A1=0;
-                _A2=1;
-                _A3=1;
-            }
-            break;
-            case 3: {
-                _A0=1;
-                _A1=0;
-                _A2=0;
-                _A3=1;
-            }
-            break;            
-        }
-    
-        subStep++;
-        subStep %= 4;
-        _motorPosition--;
-        wait_ms(_motorSpeed); // wait time defines the speed 
-    }
-    /*_A0=0;
-    _A1=0;
-    _A2=0;
-    _A3=0;*/
-    return;
-}
-
-void sMotor::setMotorPosition(int position) {
-    _motorPosition = position;
-    return;
-}
-
-void sMotor::step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- down, 1- up), speed in ms
-    _motorSpeed = speed; //set motor speed
-    if (!direction){ // shaft DOWN
-            _motorEnable = 1;
-            down(num_steps);
-            _motorEnable = 0;
-    }else if (direction){// Shaft UP
-            _motorEnable = 1;
-            up(num_steps);
-            _motorEnable = 0; 
-    }
-}
\ No newline at end of file
--- a/sMotor.h	Tue Feb 03 03:41:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
-##############################################
-##Original Program Created by Harshavardan61##
-##############################################
-        ---- harshavardan61@gmail.com -----
-Extended by Jason Brewer 2015
-to adapt to the stepper motor + linear actuator
-supplied by Selim Yilmaz
-
-Now includes functional stepper pulses, a motor enable pin
-(motor and l293D were getting very warm if the enable pin was
-always HIGH)
-
-*/
-#ifndef MBED_SMOTOR_H
-#define MBED_SMOTOR_H
-
-#include "mbed.h"
-
-class sMotor {
-public:
-
-    sMotor(PinName A0, PinName A1, PinName A2, PinName A3, PinName motorEnable, const int maxSteps); //motor constructor
-
-    void setMotorPosition(int position); // for use ONLY if the stepper init is skipped
-    int getMotorPosition(void){ return _motorPosition; }; 
-    void step(int num_steps, int direction, int speed);
-    void up(int num_steps);
-    void down(int num_steps);
-
-
-private:
-
-    DigitalOut _A0;
-    DigitalOut _A1;
-    DigitalOut _A2;
-    DigitalOut _A3;
-    DigitalOut _motorEnable;
-    int _motorPosition;
-    int _maxSteps;
-    int _motorSpeed; 
-
-};
-
-#endif
\ No newline at end of file