Amplitude Modulation Code

Dependencies:   HIDScope mbed

Fork of SymbitronValves by First Last

Revision:
3:28efa5d4ebe2
Parent:
2:e7421003d1c9
Child:
4:e69e2983bb6e
--- a/main.cpp	Mon Jun 29 14:47:36 2015 +0000
+++ b/main.cpp	Tue Jun 30 07:00:35 2015 +0000
@@ -152,27 +152,37 @@
     while(1) {
         float pid_out;
         float setpoint;
+        float meas;
         static float time = 0;
-        wait(0.1);
+        wait(0.01);
         time +=0.2;
-        setpoint = slider.readPercentage()*10000;
+        setpoint = slider.readPercentage()*20000;
         pid_out = pid.control(setpoint, getPressure_Pa());
         //if(pid_out > 0.1)
         //    v1.write(0.1);
         //if(pid_out < -0.1)
          //   v1.write(-0.1);
-        if(abs(setpoint - getPressure_Pa())<3000)
-        {
-            
-            if(setpoint - getPressure_Pa()  < 0)
+        meas = getPressure_Pa();
+        if(abs(setpoint - meas)>4000)
+        {   
+            int32_t count = 0;
+            if(meas < setpoint )
             {
-                while(setpoint< getPressure_Pa())
+                while( (getPressure_Pa() < setpoint) && count < 100)
+                {
+                    wait(0.001);
                     v1open = 1;
+                    count++;
+                }
             }
             else
             {
-                while(setpoint > getPressure_Pa())
-                    v1close = 1;
+                while( (getPressure_Pa() > setpoint) && count < 100)
+                {
+                        v1close = 1;
+                    wait(0.001);
+                    count++;
+                }
             }
             v1open = v1close = 0;