Modified Motor Driver Firmware to include Flash + Thermal

Dependencies:   FastPWM3 mbed-dev-STM-lean

Revision:
52:8e74c22ed89f
Parent:
47:e1196a851f76
--- a/Calibration/calibration.cpp	Wed Jul 17 03:40:12 2019 +0000
+++ b/Calibration/calibration.cpp	Sun Jul 21 21:42:49 2019 +0000
@@ -59,14 +59,18 @@
         printf("%.4f   %.4f\n\r", theta_ref/(NPP), theta_actual);
         }
         sample_counter++;
-       theta_ref += 0.001f;
+       theta_ref += 0.0005f;
         }
     float theta_end = ps->GetMechPositionFixed();
     int direction = (theta_end - theta_start)>0;
+    float ratio = abs(4.0f*PI/(theta_end-theta_start));
+    int pole_pairs = (int) roundf(ratio);
     printf("Theta Start:   %f    Theta End:  %f\n\r", theta_start, theta_end);
     printf("Direction:  %d\n\r", direction);
     if(direction){printf("Phasing correct\n\r");}
     else if(!direction){printf("Phasing incorrect.  Swapping phases V and W\n\r");}
+    printf("Pole Pairs:  %d\n\r", pole_pairs);
+    NPP = pole_pairs;
     PHASE_ORDER = direction;
     }
     
@@ -143,7 +147,7 @@
             TIM1->CCR1 = (PWM_ARR>>1)*(1.0f-dtc_v);
             TIM1->CCR2 = (PWM_ARR>>1)*(1.0f-dtc_w);
             }
-            wait_us(100);
+            wait_us(200);
             ps->Sample(DT);
         }
        ps->Sample(DT);
@@ -168,7 +172,7 @@
             TIM1->CCR1 = (PWM_ARR>>1)*(1.0f-dtc_v);
             TIM1->CCR2 = (PWM_ARR>>1)*(1.0f-dtc_w);
             }
-            wait_us(100);
+            wait_us(200);
             ps->Sample(DT);
         }
        ps->Sample(DT);                                                            // sample position sensor