Parametros PID, Incremental (antirebote)

Dependencies:   Debounced TextLCD mbed

Fork of Tarea2 by Alexander Vallejo

Files at this revision

API Documentation at this revision

Comitter:
avallejopo
Date:
Fri Nov 15 17:06:50 2013 +0000
Parent:
0:71c0bb945ae8
Commit message:
Parametros PID Incrementales

Changed in this revision

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
diff -r 71c0bb945ae8 -r d54f06e19277 TextLCD.lib
--- a/TextLCD.lib	Wed Oct 16 06:43:52 2013 +0000
+++ b/TextLCD.lib	Fri Nov 15 17:06:50 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/avallejopo/code/TextLCD_Publi_Metod/#0fdd8e61a7b7
+http://mbed.org/users/avallejopo/code/TextLCD/#aba8ab3dde9d
diff -r 71c0bb945ae8 -r d54f06e19277 main.cpp
--- a/main.cpp	Wed Oct 16 06:43:52 2013 +0000
+++ b/main.cpp	Fri Nov 15 17:06:50 2013 +0000
@@ -23,148 +23,235 @@
 {
     lcd.cls(); // Borrar Pantalla
     lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
-    
-    lcd.locate(8,0);    lcd.printf("Kp=%d",kpnum);
-    //lcd.locate(0,1);    lcd.printf("Ki=%d",kinum);
-    //lcd.locate(8,1);    lcd.printf("Kd=%d",kdnum);
-    //lcd.locate(0,0);    lcd.printf("Sp=%d",spnum);
-    
+
+    lcd.locate(8,0);
+    lcd.printf("Kp=%d",kpnum);
+    lcd.locate(0,1);
+    lcd.printf("Ki=%d",kinum);
+    lcd.locate(8,1);
+    lcd.printf("Kd=%d",kdnum);
+    lcd.locate(0,0);
+    lcd.printf("Sp=%d",spnum);
+
     while(1)
     {
         if (!button1)
         {
-            if(flagt==0){
+            if(flagt==0)
+            {
                 t.start();
                 flagt=1;
             }
-            
+
             led1 =!led1;
             wait(0.50);
             if(!button1)
             {
-                if(t.read()>15){
-                    incremento=1000;
-                }
-                else if(t.read()>10){
+                if(t.read()>10)
+                {
                     incremento=100;
                 }
-                else if(t.read()>5){
+                else if(t.read()>5.5)
+                {
                     incremento=10;
                 }
-                
+
                 if(pos==1)
                 {
-                    spnum+=incremento;
-                    lcd.locate(3,0); lcd.printf("%d", spnum);
+                    if(spnum+incremento>=999)
+                    {
+                        spnum=999;
+                        lcd.locate(3,0);
+                        lcd.printf("    ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d", spnum);
+                    }
+                    else
+                    {
+                        spnum+=incremento;
+                        lcd.locate(3,0);
+                        lcd.printf("%d", spnum);
+                    }                        
                 }
                 else if(pos==2)
                 {
-                    kpnum+=incremento;
-                    lcd.locate(11,0); lcd.printf("%d", kpnum);
+                    if(kpnum+incremento>=999)
+                    {
+                        kpnum=999;
+                        lcd.locate(11,0);
+                        lcd.printf("    ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d", kpnum);
+                    }
+                    else
+                    {
+                        kpnum+=incremento;
+                        lcd.locate(11,0);
+                        lcd.printf("%d", kpnum);
+                    }
                 }
                 else if(pos==3)
                 {
-                    kinum+=incremento;
-                    lcd.locate(3,1); lcd.printf("%d", kinum);
+                    if(kinum+incremento>=999)
+                    {
+                        kinum=999;
+                        lcd.locate(3,1);
+                        lcd.printf("    ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d", kinum);
+                    }
+                    else
+                    {
+                        kinum+=incremento;
+                        lcd.locate(3,1);
+                        lcd.printf("%d", kinum);
+                    }
                 }
                 else if(pos==4)
                 {
-                    kdnum+=incremento;
-                    lcd.locate(11,1); lcd.printf("%d", kdnum);
-                }    
+                    if(kdnum+incremento>=999)
+                    {
+                        kdnum=999;
+                        lcd.locate(11,1);
+                        lcd.printf("    ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d", kdnum);
+                    }
+                    else
+                    {
+                        kdnum+=incremento;
+                        lcd.locate(11,1);
+                        lcd.printf("%d", kdnum);
+                    }
+                }
             }
         }
-        else
+        
+        if (!button2)
+        {
+            if(flagt==0)
+            {
+                //t.reset();
+                t.start();
+                flagt=1;
+            }
+
+            led1 =!led1;
+            wait(0.50);
+
+            if(!button2)
+            {
+                if(t.read()>10)
+                {
+                    incremento=100;
+                }
+                else if(t.read()>5.5)
+                {
+                    incremento=10;
+                }
+
+                led2 =!led2;
+                if(pos==1)
+                {
+                    if(spnum-incremento<0)
+                    {
+                        //No ocurre nada
+                    }
+                    else
+                    {
+                        spnum-=incremento;
+                        lcd.locate(3,0);
+                        lcd.printf("    ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d", spnum);
+                    }
+                }
+                else if(pos==2)
+                {
+                    if(kpnum-incremento<0)
+                    {
+                        //No ocurre nada
+                    }
+                    else
+                    {
+                        kpnum-=incremento;
+                        lcd.locate(11,0);
+                        lcd.printf("    ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d", kpnum);
+                    }
+                }
+                else if(pos==3)
+                {
+                    if(kinum-incremento<0)
+                    {
+                        //No ocurre nada
+                    }
+                    else
+                    {
+                        kinum-=incremento;
+                        lcd.locate(3,1);
+                        lcd.printf("    ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d", kinum);
+                    }
+                }
+                else if(pos==4)
+                {
+                    if(kdnum-incremento<0)
+                    {
+                        //No ocurre nada
+                    }
+                    else
+                    {
+                        kdnum-=incremento;
+                        lcd.locate(11,1);
+                        lcd.printf("    ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d", kdnum);
+                    }
+                }
+            }
+        }
+
+        if (!button3)
+        {
+            led3 =!led3;
+            if(pos==4)
+            {
+                pos=1;
+                lcd.locate(3,0);
+                lcd.printf("%d", spnum);
+            }
+            else if (pos==1)
+            {
+                pos++;
+                lcd.locate(11,0);
+                lcd.printf("%d", kpnum);
+            }
+            else if(pos==2)
+            {
+                pos++;
+                lcd.locate(3,1);
+                lcd.printf("%d", kinum);
+            }
+            else if(pos==3)
+            {
+                pos++;
+                lcd.locate(11,1);
+                lcd.printf("%d", kdnum);
+            }
+            wait(0.25);
+
+        }
+        
+        if (button1 && button2)
         {
             flagt=0;
             t.reset();
             incremento=1;
         }
-/*
-        if (button2.falling())
-        {
-            led2 =!led2;
-            if(pos==1)
-            {
-                if(spnum==0)
-                {
-                    //No ocurre nada
-                }
-                else
-                {
-                    spnum--;
-                    lcd.locate(3,0); lcd.printf("    ");
-                    lcd.locate(3,0);
-                    lcd.printf("%d", spnum);
-                }
-            }
-            else if(pos==2)
-            {
-                if(kpnum==0)
-                {
-                    //No ocurre nada
-                }
-                else
-                {
-                    kpnum--;
-                    lcd.locate(11,0); lcd.printf("    ");
-                    lcd.locate(11,0);
-                    lcd.printf("%d", kpnum);
-                }
-            }
-            else if(pos==3)
-            {
-                if(kinum==0)
-                {
-                    //No ocurre nada
-                }
-                else
-                {
-                    kinum--;
-                    lcd.locate(3,1); lcd.printf("    ");
-                    lcd.locate(3,1);
-                    lcd.printf("%d", kinum);
-                }
-            }
-            else if(pos==4)
-            {
-                if(kdnum==0)
-                {
-                    //No ocurre nada
-                }
-                else
-                {
-                    kdnum--;
-                    lcd.locate(11,1); lcd.printf("    ");
-                    lcd.locate(11,1);
-                    lcd.printf("%d", kdnum);
-                }
-            }
-        }
+       
+    }
+}
 
-        if (button3.falling())
-        {
-            led3 =!led3;
-            if(pos==4)
-            {
-                pos=1;
-                lcd.locate(3,0);lcd.printf("%d", spnum);
-            }
-            else if (pos==1)
-            {
-                pos++;
-                lcd.locate(11,0);lcd.printf("%d", kpnum);
-            }
-            else if(pos==2){
-                pos++;
-                lcd.locate(3,1);lcd.printf("%d", kinum);
-            }
-            else if(pos==3){
-                pos++;
-                lcd.locate(11,1);lcd.printf("%d", kdnum);                
-            }
-
-        }
-        */
-    }
-}
\ No newline at end of file