STM32F302R8 with Konrad's inverter boards for senior design.

Dependencies:   mbed

Fork of Blue_Board_Ticker by Brad VanderWilp

Revision:
5:6110655353ad
Parent:
4:ab4d51b5b1c8
Child:
6:e401c592d2c3
--- a/main.cpp	Wed Apr 06 20:10:39 2016 +0000
+++ b/main.cpp	Wed Apr 06 20:36:41 2016 +0000
@@ -7,6 +7,8 @@
 PwmOut phaseC(PA_10);   //Out3, White
 DigitalOut phaseCEN(PC_12);
 
+AnalogIn pot(PB_1);
+
 InterruptIn button(USER_BUTTON);
 
 DigitalOut redLed(PB_2);
@@ -17,7 +19,8 @@
 
 Ticker interrupt;
 
-float pwmDuty = 0.5;
+float pwmMax = 0.9;
+float pwmDuty;
 int stall = 0;
 void activate()
 {
@@ -157,6 +160,8 @@
 //    }
 //    interrupt.detach();
 
+    pwmDuty = pot.read() * pwmMax;
+
     phaseA.period_us(10);
     phaseB.period_us(10);
     phaseC.period_us(10);
@@ -210,9 +215,19 @@
         Afall();
         Crise();
     } 
-    
+    float ADCSum = 0;;
+    int ADCCount = 0;
     while(1) {
         led = !led;
-        wait(0.2);
+        ADCSum += pot.read();
+        ADCCount++;
+        if(ADCCount == 20)
+        {
+            pwmDuty = (ADCSum/20) * pwmMax;
+            ADCSum = 0;
+            ADCCount = 0;
+        }
+//        pwmDuty = pot.read() * 0.7;
+        wait(0.05);
     }
 }