Added faster sense->step translation
authorGraham <dev@netlinux.org.uk>
Sat, 9 Sep 2017 11:35:48 +0000 (12:35 +0100)
committerGraham <dev@netlinux.org.uk>
Sat, 9 Sep 2017 11:35:48 +0000 (12:35 +0100)
UnoBLDC.cpp

index 6ae0f02..b610fab 100644 (file)
@@ -22,14 +22,21 @@ static const char TrinaryStep[][TRITS + 1] = {
     "+- "
 };
 
+# define SensePattern0 0b000001
+# define SensePattern1 0b000010
+# define SensePattern2 0b000100
+# define SensePattern3 0b001000
+# define SensePattern4 0b010000
+# define SensePattern5 0b100000
+
 static const unsigned char SensePattern[] =
 {
-    0b000001,
-    0b000010,
-    0b000100,
-    0b001000,
-    0b010000,
-    0b100000
+    SensePattern0,
+    SensePattern1,
+    SensePattern2,
+    SensePattern3,
+    SensePattern4,
+    SensePattern5
 };
 
 #elif STEP == 12
@@ -49,20 +56,33 @@ static const char TrinaryStep[][TRITS + 1] = {
     "+-+"
 };
 
+# define SensePattern00 0b000001
+# define SensePattern01 0b000011
+# define SensePattern02 0b000010
+# define SensePattern03 0b000110
+# define SensePattern04 0b000100
+# define SensePattern05 0b001100
+# define SensePattern06 0b001000
+# define SensePattern07 0b011000
+# define SensePattern08 0b010000
+# define SensePattern09 0b110000
+# define SensePattern10 0b100000
+# define SensePattern11 0b100001
+
 static const unsigned char SensePattern[] =
 {
-    0b000001,
-    0b000011,
-    0b000010,
-    0b000110,
-    0b000100,
-    0b001100,
-    0b001000,
-    0b011000,
-    0b010000,
-    0b110000,
-    0b100000,
-    0b100001
+    SensePattern00,
+    SensePattern01,
+    SensePattern02,
+    SensePattern03,
+    SensePattern04,
+    SensePattern05,
+    SensePattern06,
+    SensePattern07,
+    SensePattern08,
+    SensePattern09,
+    SensePattern10,
+    SensePattern11
 };
 
 #endif
@@ -153,7 +173,7 @@ void SensorChange()
     if (!Single)
     {
         ThisStep = NOSTEP;
-
+#if 0
         for (unsigned char StepIndex = 0; StepIndex < StepNumber; StepIndex++)
         {
             if ((Sense & SensePattern[StepIndex]) == 0)
@@ -162,7 +182,37 @@ void SensorChange()
                 break;
             }
         }
-        
+#else
+# if STEP == 6
+        switch (~Sense & 0b111111)
+        {
+            case SensePattern0: ThisStep = 0; break;
+            case SensePattern1: ThisStep = 1; break;
+            case SensePattern2: ThisStep = 2; break;
+            case SensePattern3: ThisStep = 3; break;
+            case SensePattern4: ThisStep = 4; break;
+            case SensePattern5: ThisStep = 5; break;
+            default: return;
+        }
+# elif STEP == 12
+        switch (~Sense & 0b111111)
+        {
+            case SensePattern00: ThisStep =  0; break;
+            case SensePattern01: ThisStep =  1; break;
+            case SensePattern02: ThisStep =  2; break;
+            case SensePattern03: ThisStep =  3; break;
+            case SensePattern04: ThisStep =  4; break;
+            case SensePattern05: ThisStep =  5; break;
+            case SensePattern06: ThisStep =  6; break;
+            case SensePattern07: ThisStep =  7; break;
+            case SensePattern08: ThisStep =  8; break;
+            case SensePattern09: ThisStep =  9; break;
+            case SensePattern10: ThisStep = 10; break;
+            case SensePattern11: ThisStep = 11; break;
+            default: return;
+        }
+# endif
+#endif
         if (ThisStep != NOSTEP)
             StepCount = ThisStep;
     }