Basic DC motor control test, rpm feedback by simple impulse signal, PID speed control.

Dependencies:   FastPWM mbed FastIO MODSERIAL

Revision:
1:70c514e10598
Parent:
0:bd186184ef2a
Child:
2:70918f7f8451
--- a/main.cpp	Fri Mar 16 14:41:06 2018 +0000
+++ b/main.cpp	Thu Mar 22 11:23:31 2018 +0000
@@ -1,18 +1,35 @@
 #include "mbed.h"
+#include "FastPWM.h"
 
-PwmOut mypwm(PWM_OUT);
+FastPWM mypwm(PWM_OUT);
 
 DigitalOut myled(LED1);
 
 int main() {
     
-    mypwm.period_ms(10);
-    mypwm.pulsewidth_ms(1);
+    mypwm.period_us(100);
+    mypwm.write(0.0);
   
     printf("pwm set to %.2f %%\n", mypwm.read() * 100);
     
     while(1) {
+        int iCnt = 0;
+        double dPwmDuty = 0.0;
+        
+        mypwm.write(dPwmDuty);
+
+        if (10 < iCnt++) {        
+            iCnt = 0;
+
+            dPwmDuty += 0.1;
+        
+            if (1.0 < dPwmDuty) {
+                dPwmDuty = 0.0;
+            }
+        }
+
         myled = !myled;
+
         wait(1);
     }
 }