PID, tarea 3, procesadores

Dependencies:   Debounced TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
mandres7
Date:
Wed Dec 04 19:45:39 2013 +0000
Parent:
0:6ef000c1b903
Commit message:
PID con parametros KP, KI, KD, SP definidos desde la programaci?n

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6ef000c1b903 -r 80f82aa3d0ec main.cpp
--- a/main.cpp	Sun Nov 10 20:31:02 2013 +0000
+++ b/main.cpp	Wed Dec 04 19:45:39 2013 +0000
@@ -12,13 +12,16 @@
 DebouncedIn Gain(PTE2);
 int ap,n,ai,ad; 
 
-float i=0.7; // set point
+float i; // set point
 float j=0; // salida planta
+float ji=0; //variable proceso interno
+float spi=0; //variable proceso interno
 float h=0; // entrada planta
 float m=0; // Error
 float mv=0;
 float g=0;
-float x=0;
+
+int sp=500;
 int kp=3;
 int ki=15;
 int kd=1;
@@ -28,49 +31,61 @@
 
 //float Setpoint=0.6;
 
-    while(1) {
-
-        wait(0.3);
-              
-        if(i<0.999){
+           i=sp/999;
+           lcd.cls();
+           lcd.printf("Er:%.2f",m);
+           lcd.locate(8,0);
+           lcd.printf("Me:%.2f",j);
+           lcd.locate(0,1);
+           lcd.printf("Sp:%d",sp);
+           lcd.locate(8,1);
+           lcd.printf("Co:%.1f",h);
+           wait(2);
+           
+           //
+        while(1) {
+        
+            spi=sp*(3.3/999);
+            
+        //wait(0.3);
+              i=sp/999;
+        if(i<=1){
        
         j=Ain;
-        m=(i-j);
+        ji=j*3.3;
+        m=(spi-ji);
         //n=m*100;
         ap=kp*m;
         ai=(ki*m)+ai;
         
-        if (ai>999){
-        ai=998;
-                   }
-        
         ad=kd*(m-mv);
         h=ap+ai+ad;
-        x=h/100;
-        g=(h*3.3/100);
-        
+   
+        if (h>999){
+        h=999;
+                   }
         if (h<0){
-            h=0;
-                }
-                
-
-                        
+        h=0;
+                   }
+                              
+        g=(h/999);
+                                                       
         Aout=g;
         wait(0.22);
  
         
         lcd.cls();
-        lcd.printf("Er:%.3f",m);
+        lcd.printf("Er:%.2f",m);
         lcd.locate(8,0);
-        lcd.printf("Me:%.3f",j);
+        lcd.printf("Me:%.2f",j);
         lcd.locate(0,1);
-        lcd.printf("Sp:%.2f",i);
+        lcd.printf("Sp:%d",sp);
         lcd.locate(8,1);
-        lcd.printf("Co:%.3f",x);
+        lcd.printf("Co:%.1f",h);
         }
 
 
         mv=m;
-    }
+    } //While
     
 }
\ No newline at end of file