With more robust driving method and calibration routine

Dependents:   Stepper_Motor_Demo Stepper_Motor_Demo_final

Fork of Stepper_Motor_X27168 by Stepper Motor

Revision:
1:406a6e6c4bd7
Parent:
0:c346170974bc
--- a/Stepper_Motor_X27168.cpp	Tue Oct 20 00:36:06 2015 +0000
+++ b/Stepper_Motor_X27168.cpp	Wed Mar 16 18:03:32 2016 +0000
@@ -56,18 +56,18 @@
     else
         return -1;
         
-    switch (cur_state) {
+    switch (cur_state) { //improve 2 phase drive method. Original method commented out
         case 0:
-            motor_control = 0x1;
+            motor_control = 0x9;//0x1;
             break;
         case 1:
-            motor_control = 0x4;
+            motor_control = 0x5;//0x4;
             break;
         case 2:
-            motor_control = 0x2;
+            motor_control = 0x6;//0x2;
             break;
         case 3:
-            motor_control = 0x8;
+            motor_control = 0xA;//0x8;
             break;
         case 4:
             motor_control = 0x0;
@@ -95,4 +95,15 @@
 
 void StepperMotor_X27168::angle_position(float angle) {
     step_position(int(angle*2));
+}
+
+void StepperMotor_X27168::init()
+{
+    set_speed(400); //if too fast(>400) the motor will slip and go weird
+
+    step_position(MAX_POS); //sweep to MAX position
+    wait(0.5);
+
+    step_position(0); //sweep to zero position
+    wait(0.5);
 }
\ No newline at end of file