Modificación de parámetros (sp, ki, kp y kd) para un control PID, se realiza por medio de 4 pulsadores teniendo en cuenta la librería antirebote. Los parámetros se visualizan en una pantalla LCD 16x2.

Dependencies:   mbed

Fork of pid-TAREA1 by Wilmar Cr

/media/uploads/Wilmar87/img_4006.jpg

Revision:
3:9c3e142c9896
Parent:
2:88f8bc5d4e65
--- a/main.cpp	Fri Nov 29 21:36:46 2013 +0000
+++ b/main.cpp	Fri Dec 13 03:08:25 2013 +0000
@@ -4,19 +4,19 @@
 
 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); //Puertos LCD rs, e, d4, d5, d6, d7
  
-DigitalOut led1(LED1);//led de cambio de posición
-DigitalOut led2(LED2);// led incremento de parámetros
-DigitalOut led3(LED3);// led decremento de parámetros
-DebouncedIn bot1(PTC12); //cambiar la posición
-DebouncedIn bot2(PTC13); //incrementar variable
-DebouncedIn bot3(PTC16); //decrementar variable
-DebouncedIn bot4(PTC17); //salida de bucle
+DigitalOut led1(LED1);      //led de cambio de posición
+DigitalOut led2(LED2);      // led incremento de parámetros
+DigitalOut led3(LED3);      // led decremento de parámetros
+DebouncedIn bot1(PTC12);    //cambiar la posición
+DebouncedIn bot2(PTC13);    //incrementar variable
+DebouncedIn bot3(PTC16);    //decrementar variable
+DebouncedIn bot4(PTC17);    //salida de bucle
   
    //Códigos LCD
-int C1=0x0E;                // Muestra el cursor
+int C1=0x0E;            // Muestra el cursor
 // 0x18;                // desplazamiento izquierda
 // 0x1A;                // desplazamiento derecha
-int C4=0x0C;                // Quita el cursor
+int C4=0x0C;            // Quita el cursor
                      
                      
 int a,kp, ki, kd, sp;   // indice y variables del PID
@@ -26,24 +26,26 @@
 int main() {
 
     led1=led2=led3=1;
-    lcd.printf("Control PID");
+    lcd.printf("PARAMETROS PID");
     wait(1.5);
     lcd.cls();
-                        // Ubica e imprime nombre de las variables en la LCD
-    lcd.locate(0,0);
-    lcd.printf("Sp=%d",sp);
+    
+    lcd.writeCommand(C1);//comando para mostrar el cursor en el LCD
+                       
+    lcd.locate(0,0);     // Ubica e imprime nombre de las variables en la LCD
+    lcd.printf("Sp=%i",sp);
     lcd.locate(8,0);
-    lcd.printf("Kp=%d",kp);
+    lcd.printf("Kp=%i",kp);
     lcd.locate(0,1);
-    lcd.printf("Ki=%d",ki);
+    lcd.printf("Ki=%i",ki);
     lcd.locate(8,1);
-    lcd.printf("Kd=%d",kd);
-    lcd.writeCommand(C1);//comando para mostrar el cursor en el LCD
+    lcd.printf("Kd=%i",kd);
+    
     
     //Inicio del ciclo
         
     while(1) {
-           if (bot1.falling()) {      //Aumenta de posición el cursor       
+           if (bot1.falling()) {      //Aumenta de posición el cursor para cada línea de menu    
                a++;
                led1=0;
                wait(.15); 
@@ -75,7 +77,7 @@
                }
             }
                
-                        if  (bot2.falling()) {      //Incrementa la variable      
+                        if  (bot2.falling()) {      //Incrementa el valor del parámetro      
                             led2=0;
                             wait(.15);
                             led2=1;
@@ -85,33 +87,33 @@
                             lcd.locate(2,0);
                             lcd.printf("=");
                             lcd.locate(3,0);
-                            lcd.printf("%d",++sp);
+                            lcd.printf("%i",++sp);
                             break;
                
                             case 1:
                             lcd.locate(10,0);
                             lcd.printf("=");
                             lcd.locate(11,0);
-                            lcd.printf("%d",++kp);
+                            lcd.printf("%i",++kp);
                             break;
                
                             case 2:
                             lcd.locate(2,1);
                             lcd.printf("=");
                             lcd.locate(3,1);
-                            lcd.printf("%d",++ki);
+                            lcd.printf("%i",++ki);
                             break;
                             
                             case 3:
                             lcd.locate(10,1);
                             lcd.printf("=");
                             lcd.locate(11,1);
-                            lcd.printf("%d",++kd);
+                            lcd.printf("%i",++kd);
                             break;
                     }
                }
                
-                                     if   (bot3.falling()) {      //Decrementa la variable      
+                                     if   (bot3.falling()) {      //Decrementa el valor del parámetro      
                                      led3=0;
                                      wait(.15);
                                      led3=1;
@@ -122,29 +124,29 @@
                                       sp=0;
                                      }                                                                                                                               
                                      lcd.locate(2,0);
-                                     lcd.printf("=");
+                                     lcd.printf("=    ");
                                      lcd.locate(3,0);
-                                     lcd.printf("%d",sp--);
+                                     lcd.printf("%i",sp--);
                                      break;
                                        
                                      case 1:
-                                     if (kp<0) {                 //No se admite valores negativos
+                                     if (kp<0)  {                 //No se admite valores negativos
                                      kp=0;
                                      }
                                      lcd.locate(10,0);
-                                     lcd.printf("=");
+                                     lcd.printf("=    ");
                                      lcd.locate(11,0);
-                                     lcd.printf("%d",kp--);
+                                     lcd.printf("%i",kp--);
                                      break;
                                        
                                      case 2:
-                                     if (ki<0) {                 //No se admite valores negativos
+                                     if (ki<0)  {                 //No se admite valores negativos
                                      ki=0;
                                      }
                                      lcd.locate(2,1);
-                                     lcd.printf("=");
+                                     lcd.printf("=    ");
                                      lcd.locate(3,1);
-                                     lcd.printf("%d",ki--);
+                                     lcd.printf("%i",ki--);
                                      break;
                                        
                                      case 3:
@@ -152,9 +154,9 @@
                                      kd=0;
                                      }
                                      lcd.locate(10,1);
-                                     lcd.printf("=");
+                                     lcd.printf("=    ");
                                      lcd.locate(11,1);
-                                     lcd.printf("%d",kd--);
+                                     lcd.printf("%i",kd--);
                                      break;
                                 }
                           }