Stepper dengan driver TB6600 Microstep Driver

Dependents:   StepperTB_Example Lowlevel_function

Files at this revision

API Documentation at this revision

Comitter:
irfantitok
Date:
Fri Nov 09 17:30:00 2018 +0000
Parent:
1:6cbbb5795b9c
Commit message:
Added MoveOneStep

Changed in this revision

StepperTB.cpp Show annotated file Show diff for this revision Revisions of this file
StepperTB.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6cbbb5795b9c -r 787cee5a8dad StepperTB.cpp
--- a/StepperTB.cpp	Thu Nov 01 15:00:05 2018 +0000
+++ b/StepperTB.cpp	Fri Nov 09 17:30:00 2018 +0000
@@ -17,29 +17,48 @@
     }
 
 //Method
+
+void StepperTB::MoveOneStep(bool Direction, int Interval){
+        int Msteps = getMstep();
+        
+        //Gerak sebanyak Mstep Microstep = 1 Step
+        if(Direction == 0){
+            //Arah 0 (Belum dicoba CW/CCW)
+            for(int i=0; i<Msteps; i++){
+                    DIR_=0;
+                    ENA_=1;
+                    PUL_=1;
+                    wait_us(Interval);
+                    PUL_=0;
+                    wait_us(Interval);
+                }
+            }
+        else {
+            //Arah 1
+            for(int i=0; i>Msteps; i--){
+                    DIR_=1;
+                    ENA_=1;
+                    PUL_=1;
+                    wait_us(Interval);
+                    PUL_=0;
+                    wait_us(Interval);
+                }
+            }
+    }
+
 void StepperTB::MoveStep(int StepAmt, int Interval){
-        //Konversi StepAmt ke microstep
-        int MstepAmt = getMstep()*StepAmt;
         
         //Gerak sebanyak MstepAmt microstep
         if(StepAmt>=0){
-            for(int i=0; i<MstepAmt; i++){    
-                DIR_=0;
-                ENA_=1;
-                PUL_=1;
-                wait_us(Interval);
-                PUL_=0;
-                wait_us(Interval);
+            //Arah 0 (Belum dicoba CW/CCW)
+            for(int i=0; i<StepAmt; i++){    
+                    MoveOneStep(0, Interval);
                 }
             }
         else {
-            for(int i=0; i>MstepAmt; i--){
-                DIR_=1;
-                ENA_=1;
-                PUL_=1;
-                wait_us(Interval);
-                PUL_=0;
-                wait_us(Interval);
+            //Arah 1
+            for(int i=0; i>StepAmt; i--){
+                    MoveOneStep(1, Interval);
                 }
             }
     }
diff -r 6cbbb5795b9c -r 787cee5a8dad StepperTB.h
--- a/StepperTB.h	Thu Nov 01 15:00:05 2018 +0000
+++ b/StepperTB.h	Fri Nov 09 17:30:00 2018 +0000
@@ -19,6 +19,12 @@
     *Gerakkan stepper sebanyak StepAmt step dengan
     *Selang waktu antar microstep selama Interval (dalam us)
     */
+    void MoveOneStep(bool Direction, int Interval);
+    
+    /*MoveStep
+    *Gerakkan stepper sebanyak StepAmt step dengan
+    *Selang waktu antar microstep selama Interval (dalam us)
+    */
     void MoveStep(int StepAmt, int Interval);
     
     /*MoveRev