afsd

Fork of a4998 by Keegan Hu

Files at this revision

API Documentation at this revision

Comitter:
Bilybill
Date:
Fri May 11 06:05:21 2018 +0000
Parent:
0:173936452e07
Commit message:
afds

Changed in this revision

a4988.cpp Show annotated file Show diff for this revision Revisions of this file
a4988.h Show annotated file Show diff for this revision Revisions of this file
diff -r 173936452e07 -r 88f743f3e7a7 a4988.cpp
--- a/a4988.cpp	Wed May 02 10:48:23 2018 +0000
+++ b/a4988.cpp	Fri May 11 06:05:21 2018 +0000
@@ -6,8 +6,7 @@
 {
     
 }
- 
-void Stepper::step(int dir, int frequency ,volatile int _remain)
+void Stepper::step(int dir, long long int frequency ,volatile long long int _remain)
 {
     //fun = &Stepper::step_control;
     if (dir == 1) {
@@ -16,7 +15,7 @@
         direction = 1;
     }
     remain = _remain;
-    step_ticker.attach(this, &Stepper::step_control,1.0/frequency);
+    step_ticker.attach(this, &Stepper::step_control,0.5/frequency);
 }
  
 void Stepper::enable()
@@ -35,11 +34,19 @@
         {         
             return;
         }
-        
-                if(stepPin){
-                        stepPin = 0; //STEP 1->0
-                        remain--;
-                }else{
-                        stepPin = 1; //STEP 0->1
-                }
+        if(remain < 0 )
+        {
+            if(stepPin){
+                stepPin = 0; //STEP 1->0
+            }else{
+                stepPin = 1; //STEP 0->1
+            }
+        }
+            
+        if(stepPin){
+            stepPin = 0; //STEP 1->0
+            remain--;
+        }else{
+            stepPin = 1; //STEP 0->1
+        }
 }
diff -r 173936452e07 -r 88f743f3e7a7 a4988.h
--- a/a4988.h	Wed May 02 10:48:23 2018 +0000
+++ b/a4988.h	Fri May 11 06:05:21 2018 +0000
@@ -8,15 +8,15 @@
 class Stepper
 {
 public:
-    Stepper(PinName _en,PinName _stepPin, PinName _direction);
-    void step(int dir, int frequency ,volatile int _remain);
+    Stepper(PinName _en = PB_9,PinName _stepPin = PB_0, PinName _direction = PB_7 );
+    void step(int dir, long long int frequency ,volatile long long int _remain);
     void enable();
     void disable();
 private:
     DigitalOut en;
     DigitalOut stepPin;
     DigitalOut direction;
-    volatile int remain;
+    volatile long long int remain;
     Ticker step_ticker;
     void step_control();
    // pClassFun fun;