ingrese los parámetros para el controlador PID, se pueden ingresar del 0 al 9999 pero para el debido funcionamiento del PID ingrese del 0 al 100 cada parametro

Dependencies:   DebounceIn Debounced TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
caaruizze
Date:
Mon Nov 18 14:14:46 2013 +0000
Commit message:
tareas 2-3 que contienen el aumento y disminuci?n r?pida de los par?metros de un para un PID (en este se encuentra el controlador PID y el ingreso de los par?metros)

Changed in this revision

DebounceIn.lib Show annotated file Show diff for this revision Revisions of this file
Debounced.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 0275ebccd8fe DebounceIn.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIn.lib	Mon Nov 18 14:14:46 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/AjK/code/DebounceIn/#31ae5cfb44a4
diff -r 000000000000 -r 0275ebccd8fe Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Mon Nov 18 14:14:46 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r 0275ebccd8fe TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Nov 18 14:14:46 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/caaruizze/code/TextLCD/#c9de92a922fb
diff -r 000000000000 -r 0275ebccd8fe main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 18 14:14:46 2013 +0000
@@ -0,0 +1,635 @@
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "DebounceIn.h"
+#include "TextLCD.h"
+AnalogIn Vin(PTC2);
+AnalogOut Vo(PTE30);
+int C1=0x0e;
+
+int i=0;
+int k=0,u=0;
+
+int j=0;
+int l=0,g=0;
+
+int m=0;
+int n=0,q=0;
+int o=0; 
+int p=0,h=0;
+
+float kp, ki, kd, sp ,err, med, yr, pid, ap, ai, ad, err_v ,Sp;
+int x=1;
+
+int main() 
+{
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5) ;// declaración de los puertos del lcd
+DebounceIn b1(PTC16); //aumento 
+DebounceIn b3(PTC12);// disminuye
+DebouncedIn b2(PTC13);// ,cambio de posición
+DebounceIn  b4(PTC17);//  Cabio de etiqueta
+lcd.printf("TAREA2:Proc"); // IMPRIMIR 
+wait(1); // espera 1 segundo
+lcd.cls();      // borra lcd
+lcd.writeCommand(C1); // escribe el comando C1
+        // Localiza y escribe los titulos Sp,Kp,Ki,Kd en la patalla
+lcd.locate(0,0);
+lcd.printf("Sp:%d",i);
+lcd.locate(8,0);
+lcd.printf("Kp:%d",j);
+lcd.locate(0,1);
+lcd.printf("Ki:%d",m);
+lcd.locate(8,1);
+lcd.printf("Kd:%d",o);
+// Ciclo infinito
+while (1)
+{
+if(b2.falling())
+{
+  x=x+1;
+ }
+//condicionales para ubicación en pantalla
+        if(x==1)
+        {//a
+lcd.locate(3,0);
+lcd.printf("%d",i);
+                //Ascenso
+        if(b1.read()==1)
+        {
+        k=0;
+        }
+            if(b1.read()==0 && k<25)
+            {//1.1
+                k=k+1;
+                i=i+1;
+                wait(0.2);
+                lcd.locate(3,0);
+                lcd.printf("%d",i);
+             }//1.1    
+                if(b1.read()==0 && k>=25 && k<50)
+                {//1.2
+                    k=k+1;
+                    i=i+5;
+                    wait(0.2);
+                    lcd.locate(3,0);
+                    lcd.printf("%d",i); 
+                }//1.2
+                
+                if(b1.read()==0 && k>=50 && k<75)
+                {//1.3
+                    k=k+1;
+                    i=i+10;
+                    wait(0.2);
+                    lcd.locate(3,0);
+                    lcd.printf("%d",i); 
+                }//1.3
+                
+                if(b1.read()==0 && k>=75 && k<100)
+                {//1.4
+                    k=k+1;
+                    i=i+100;
+                    wait(0.2);
+                    lcd.locate(3,0);
+                    lcd.printf("%d",i); 
+                }//1.4           
+                if(b1.read()==0 && k>=100 && k<125)
+                {//1.5
+                    k=k+1;
+                    i=i+1000;
+                    wait(0.2);
+                    lcd.locate(3,0);
+                    lcd.printf("%d",i); 
+                    if(i>9999)
+                    {//1.5.1
+                        i=9999;
+                        lcd.locate(3,0);
+                        lcd.printf("     ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d",i); 
+                    }//1.5.1
+                }//1.5  
+                //Descenso
+        if(b3.read()==1)
+        {
+        u=0;
+        }
+                   if(b3.read()==0 && u<25)
+                    {//2.1
+                        u=u+1;
+                        i=i-1;
+                        wait(0.2);
+                        lcd.locate(3,0); 
+                        lcd.printf("     ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d",i);
+                     }//2.1    
+                        if(b3.read()==0 && u>=25 && u<50)
+                        {//2.2
+                            u=u+1;
+                            i=i-5;
+                            wait(0.2);
+                            lcd.locate(3,0);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(3,0);
+                            lcd.printf("%d",i); 
+                        }//2.2
+                        
+                        if(b3.read()==0 && u>=50 && u<75)
+                        {//2.3
+                            u=u+1;
+                            i=i-10;
+                            wait(0.2);
+                            lcd.locate(3,0);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(3,0);
+                            lcd.printf("%d",i); 
+                        }//2.3
+                        
+                        if(b3.read()==0 && u>=75 && u<100)
+                        {//2.4
+                            u=u+1;
+                            i=i-100;
+                            wait(0.2);
+                            lcd.locate(3,0); 
+                            lcd.printf("     ");                                                        
+                            lcd.locate(3,0);
+                            lcd.printf("%d",i); 
+                        }//2.4           
+                        if(b3.read()==0 && u>=100 && u<125)
+                        {//2.5
+                            u=u-1;
+                            i=i-1000;
+                            wait(0.2);
+                            lcd.locate(3,0);
+                            lcd.printf("     ");                                                            
+                            lcd.locate(3,0);
+                            lcd.printf("%d",i); 
+                        }//2.5  
+                        if(i<0)
+                           {//2.6
+                                i=0;
+                                lcd.locate(3,0);
+                                lcd.printf("     ");
+                                lcd.locate(3,0);
+                                lcd.printf("%d",i); 
+                            }//2.6                            
+                     
+        }//a
+           
+    if(x==2)
+    {//b
+    lcd.locate(11,0);
+    lcd.printf("%d",j);
+    //Ascenso
+            if(b1.read()==1)
+        {
+        l=0;
+        }
+            if(b1.read()==0 && l<25)
+            {//1.1
+                l=l+1;
+                j=j+1;
+                wait(0.2);
+                lcd.locate(11,0);
+                lcd.printf("%d",j);
+             }//1.1    
+                if(b1.read()==0 && l>=25 && l<50)
+                {//1.2
+                    l=l+1;
+                    j=j+5;
+                    wait(0.2);
+                    lcd.locate(11,0);
+                    lcd.printf("%d",j); 
+                }//1.2
+                
+                if(b1.read()==0 && l>=50 && l<75)
+                {//1.3
+                    l=l+1;
+                    j=j+10;
+                    wait(0.2);
+                    lcd.locate(11,0);
+                    lcd.printf("%d",j); 
+                }//1.3
+                
+                if(b1.read()==0 && l>=75 && l<100)
+                {//1.4
+                    l=l+1;
+                    j=j+100;
+                    wait(0.2);
+                    lcd.locate(11,0);
+                    lcd.printf("%d",j); 
+                }//1.4           
+                if(b1.read()==0 && l>=100 && l<125)
+                {//1.5
+                    l=l+1;
+                    j=j+1000;
+                    wait(0.2);
+                    lcd.locate(11,0);
+                    lcd.printf("%d",j); 
+                    if(j>9999)
+                    {//1.5.1
+                        j=9999;
+                        lcd.locate(11,0);
+                        lcd.printf("     ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d",j); 
+                    }//1.5.1
+                }//1.5  
+                //Descenso
+        if(b3.read()==1)
+        {
+        g=0;
+        }
+                   if(b3.read()==0 && g<25)
+                    {//2.1
+                        g=g+1;
+                        j=j-1;
+                        wait(0.2);
+                        lcd.locate(11,0); 
+                        lcd.printf("     ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d",j);
+                     }//2.1    
+                        if(b3.read()==0 && g>=25 && g<50)
+                        {//2.2
+                            g=g+1;
+                            j=j-5;
+                            wait(0.2);
+                            lcd.locate(11,0);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(11,0);
+                            lcd.printf("%d",j); 
+                        }//2.2
+                        
+                        if(b3.read()==0 && g>=50 && g<75)
+                        {//2.3
+                            g=g+1;
+                            j=j-10;
+                            wait(0.2);
+                            lcd.locate(11,0);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(11,0);
+                            lcd.printf("%d",j); 
+                        }//2.3
+                        
+                        if(b3.read()==0 && g>=75 && g<100)
+                        {//2.4
+                            g=g+1;
+                            j=j-100;
+                            wait(0.2);
+                            lcd.locate(11,0); 
+                            lcd.printf("     ");                                                        
+                            lcd.locate(11,0);
+                            lcd.printf("%d",j); 
+                        }//2.4           
+                        if(b3.read()==0 && g>=100 && g<125)
+                        {//2.5
+                            g=g-1;
+                            j=j-1000;
+                            wait(0.2);
+                            lcd.locate(11,0);
+                            lcd.printf("     ");                                                            
+                            lcd.locate(11,0);
+                            lcd.printf("%d",j); 
+                        }//2.5  
+                        if(j<0)
+                           {//2.6
+                                j=0;
+                                lcd.locate(11,0);
+                                lcd.printf("     ");
+                                lcd.locate(11,0);
+                                lcd.printf("%d",j); 
+                            }//2.6 
+    
+     
+    }//b
+    
+    if(x==3)
+    {//c
+      lcd.locate(3,1);
+      lcd.printf("%d",m);
+              if(b1.read()==1)
+        {
+        n=0;
+        }
+            if(b1.read()==0 && n<25)
+            {//1.1
+                n=n+1;
+                m=m+1;
+                wait(0.2);
+                lcd.locate(3,1);
+                lcd.printf("%d",m);
+             }//1.1    
+                if(b1.read()==0 && n>=25 && n<50)
+                {//1.2
+                    n=n+1;
+                    m=m+5;
+                    wait(0.2);
+                    lcd.locate(3,1);
+                    lcd.printf("%d",m); 
+                }//1.2
+                
+                if(b1.read()==0 && n>=50 && n<75)
+                {//1.3
+                    n=n+1;
+                    m=m+10;
+                    wait(0.2);
+                    lcd.locate(3,1);
+                    lcd.printf("%d",m); 
+                }//1.3
+                
+                if(b1.read()==0 && n>=75 && n<100)
+                {//1.4
+                    n=n+1;
+                    m=m+100;
+                    wait(0.2);
+                    lcd.locate(3,1);
+                    lcd.printf("%d",m); 
+                }//1.4           
+                if(b1.read()==0 && n>=100 && n<125)
+                {//1.5
+                    n=n+1;
+                    m=m+1000;
+                    wait(0.2);
+                    lcd.locate(3,1);
+                    lcd.printf("%d",m); 
+                    if(m>9999)
+                    {//1.5.1
+                        m=9999;
+                        lcd.locate(3,1);
+                        lcd.printf("     ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d",m); 
+                    }//1.5.1
+                }//1.5  
+                //Descenso
+        if(b3.read()==1)
+        {
+        q=0;
+        }
+                   if(b3.read()==0 && q<25)
+                    {//2.1
+                        q=q+1;
+                        m=m-1;
+                        wait(0.2);
+                        lcd.locate(3,1); 
+                        lcd.printf("     ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d",m);
+                     }//2.1    
+                        if(b3.read()==0 && q>=25 && q<50)
+                        {//2.2
+                            q=q+1;
+                            m=m-5;
+                            wait(0.2);
+                            lcd.locate(3,1);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(3,1);
+                            lcd.printf("%d",m); 
+                        }//2.2
+                        
+                        if(b3.read()==0 && q>=50 && q<75)
+                        {//2.3
+                            q=q+1;
+                            m=m-10;
+                            wait(0.2);
+                            lcd.locate(3,1);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(3,1);
+                            lcd.printf("%d",m); 
+                        }//2.3
+                        
+                        if(b3.read()==0 && q>=75 && q<100)
+                        {//2.4
+                            q=q+1;
+                            m=m-100;
+                            wait(0.2);
+                            lcd.locate(3,1); 
+                            lcd.printf("     ");                                                        
+                            lcd.locate(3,1);
+                            lcd.printf("%d",m); 
+                        }//2.4           
+                        if(b3.read()==0 && q>=100 && q<125)
+                        {//2.5
+                            q=q+1;
+                            m=m-1000;
+                            wait(0.2);
+                            lcd.locate(3,1);
+                            lcd.printf("     ");                                                            
+                            lcd.locate(3,1);
+                            lcd.printf("%d",m); 
+                        }//2.5  
+                        if(m<0)
+                           {//2.6
+                                m=0;
+                                lcd.locate(3,1);
+                                lcd.printf("     ");
+                                lcd.locate(3,1);
+                                lcd.printf("%d",m); 
+                            }//2.6                  
+      
+    }//c
+    
+    if(x==4)
+    {//d
+    lcd.locate(11,1);
+    lcd.printf("%d",o);
+    
+              if(b1.read()==1)
+        {
+        n=0;
+        }
+            if(b1.read()==0 && p<25)
+            {//1.1
+                p=p+1;
+                o=o+1;
+                wait(0.2);
+                lcd.locate(11,1);
+                lcd.printf("%d",o);
+             }//1.1    
+                if(b1.read()==0 && p>=25 && p<50)
+                {//1.2
+                    p=p+1;
+                    o=o+5;
+                    wait(0.2);
+                    lcd.locate(11,1);
+                    lcd.printf("%f",o); 
+                }//1.2
+                
+                if(b1.read()==0 && p>=50 && p<75)
+                {//1.3
+                    p=p+1;
+                    o=o+10;
+                    wait(0.2);
+                    lcd.locate(11,1);
+                    lcd.printf("%d",o); 
+                }//1.3
+                
+                if(b1.read()==0 && p>=75 && p<100)
+                {//1.4
+                    p=p+1;
+                    o=o+100;
+                    wait(0.2);
+                    lcd.locate(11,1);
+                    lcd.printf("%d",o); 
+                }//1.4           
+                if(b1.read()==0 && p>=100 && p<125)
+                {//1.5
+                    p=p+1;
+                    o=o+1000;
+                    wait(0.2);
+                    lcd.locate(11,1);
+                    lcd.printf("%d",o); 
+                    if(o>9999)
+                    {//1.5.1
+                        o=9999;
+                        lcd.locate(11,1);
+                        lcd.printf("     ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d",o); 
+                    }//1.5.1
+                }//1.5  
+                //Descenso
+        if(b3.read()==1)
+        {
+        h=0;
+        }
+                   if(b3.read()==0 && h<25)
+                    {//2.1
+                        h=h+1;
+                        o=o-1;
+                        wait(0.2);
+                        lcd.locate(11,1); 
+                        lcd.printf("     ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d",o);
+                     }//2.1    
+                        if(b3.read()==0 && h>=25 && h<50)
+                        {//2.2
+                            h=h+1;
+                            o=o-5;
+                            wait(0.2);
+                            lcd.locate(11,1);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(11,1);
+                            lcd.printf("%d",o); 
+                        }//2.2
+                        
+                        if(b3.read()==0 && h>=50 && h<75)
+                        {//2.3
+                            h=h+1;
+                            o=o-10;
+                            wait(0.2);
+                            lcd.locate(11,1);
+                            lcd.printf("     ");                                                           
+                            lcd.locate(11,1);
+                            lcd.printf("%d",o); 
+                        }//2.3
+                        
+                        if(b3.read()==0 && h>=75 && h<100)
+                        {//2.4
+                            h=h+1;
+                            o=o-100;
+                            wait(0.2);
+                            lcd.locate(11,1); 
+                            lcd.printf("     ");                                                        
+                            lcd.locate(11,1);
+                            lcd.printf("%d",o); 
+                        }//2.4           
+                        if(b3.read()==0 && h>=100 && h<125)
+                        {//2.5
+                            h=h+1;
+                            o=o-1000;
+                            wait(0.2);
+                            lcd.locate(11,1);
+                            lcd.printf("     ");                                                            
+                            lcd.locate(11,1);
+                            lcd.printf("%d",o); 
+                        }//2.5  
+                        if(o<0)
+                           {//2.6
+                                o=0;
+                                lcd.locate(11,1);
+                                lcd.printf("     ");
+                                lcd.locate(11,1);
+                                lcd.printf("%d",o); 
+                            }//2.6   
+    }//d
+    
+            if(x>4)
+            {
+                   x=1;
+            }
+    if(b4.read()==0)
+    {
+    
+   
+    goto PID;
+    }
+    }//while1
+    
+    PID:
+     
+        wait(0.5); // espera 1 segundo
+        lcd.cls();      // borra lcd
+        wait(0.2);
+        lcd.printf("DATOS GUARDADOS!");
+        wait(1);
+        lcd.cls();
+      
+           lcd.locate(0,0);
+           lcd.printf("Er:");
+           lcd.locate(8,0);
+           lcd.printf("Me:");        
+           lcd.locate(0,1);
+           lcd.printf("Sp:");
+           lcd.locate(8,1);
+           lcd.printf("CO:");  
+           
+    while(1)
+    {//whilePID
+    wait(0.1);         
+                   sp=i;
+                   kp=j;
+                   kd=m;
+                   ki=o;
+           
+           Sp=(sp*3.3)/100;
+               med=Vin*3.3;
+               err = (Sp-med);
+               ap = kp*err;
+               ai =(ki*err)+ai;
+
+               ad = kd*(err-err_v);
+           pid = (ap+ai+ad);
+             if  (pid<0)
+           {
+            pid=0;
+           }
+           if (pid>99)
+           {
+             pid=100;
+           }
+           
+           Vo=pid/100;
+                       
+                                           
+                                lcd.locate(3,0);
+                                lcd.printf("     ");            
+           lcd.locate(3,0);
+           lcd.printf("%.1f",err);
+                                lcd.locate(11,0);
+                                lcd.printf("     ");            
+           lcd.locate(11,0);
+           lcd.printf("%.1f",med);
+                                lcd.locate(3,1);
+                                lcd.printf("     "); 
+           lcd.locate(3,1);
+           lcd.printf("%.1f",Sp);
+                                lcd.locate(11,1);
+                                lcd.printf("     ");            
+           lcd.locate(11,1);
+           lcd.printf("%.1f",pid);
+           
+                err_v = err;
+    }//whilePID
+    }//main   
\ No newline at end of file
diff -r 000000000000 -r 0275ebccd8fe mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 18 14:14:46 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file