Fixed bad step mapping
authorGraham <dev@netlinux.org.uk>
Wed, 6 Sep 2017 21:07:01 +0000 (22:07 +0100)
committerGraham <dev@netlinux.org.uk>
Wed, 6 Sep 2017 21:07:01 +0000 (22:07 +0100)
UnoBLDC.cpp

index 79d4613..191fc33 100644 (file)
@@ -148,25 +148,30 @@ PatternSpec;
 
 void SensorChange()
 {
+    static unsigned char ThisStep = NOSTEP;
+    
     SenseCount++;
 
     Sense = (PIND >> 2) & 0b111111;
     
     if (!Single)
     {
-        StepCount = NOSTEP;
+        ThisStep = NOSTEP;
 
         for (unsigned char StepIndex = 0; StepIndex < StepNumber; StepIndex++)
         {
             if ((Sense & SensePattern[StepIndex]) == 0)
             {
-                StepCount = StepIndex;
+                ThisStep = StepIndex;
                 break;
             }
         }
+        
+        if (ThisStep != NOSTEP)
+            StepCount = ThisStep;
     }
     
-    if (Run && (StepCount != NOSTEP))
+    if (Run && (ThisStep != NOSTEP))
     {
         DDRB = (D[StepCount] << 3); // set the direction
         PORTB = (~P[StepCount] << 3) | 0b111;  // set the bits (including the pullups)