Teclado para control PID

Dependencies:   Debounced FPointer TextLCD11 keypad mbed

/media/uploads/mandres7/img_0151.jpg /media/uploads/mandres7/img_0153.jpg /media/uploads/mandres7/img_0155.jpg /media/uploads/mandres7/img_0154.jpg

Files at this revision

API Documentation at this revision

Comitter:
mandres7
Date:
Wed Dec 04 19:29:51 2013 +0000
Child:
1:f578cd888e48
Commit message:
Tarea Numero 5

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
FPointer.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
keypad.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FPointer.lib	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/FPointer/#56e309e76c19
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mandres7/code/TextLCD11/#a4a7576c3795
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keypad.lib	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yoonghm/code/keypad/#e48ba5b4c497
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,237 @@
+#include "mbed.h"
+#include "keypad.h"
+#include "TextLCD.h"
+  
+  
+  TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7
+ 
+  AnalogIn Ain(PTC2);
+  AnalogOut Aout(PTE30);
+  
+  int C4=0x0C;
+  int C1=0x0E;
+  int p=0;
+
+int c=0;
+int y=0;  
+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 ap,ai,ad; 
+int sp=0;
+int kp=0;
+int ki=0;
+int kd=0;
+
+
+
+
+  // Define your own keypad values
+  char Keytable[] = { '1', '2', '3', '*',
+                     '4', '5', '6', '0',
+                      '7', '8', '9', '#',
+                      'A', 'B', 'C', 'D'
+                    };
+                    
+ int Teclado[] = { 1, 4, 7, 13,
+                   2, 5, 8, 0,
+                   3, 6, 9, 14,
+                   10,11,12, 15
+                    };
+ 
+    uint32_t cbAfterInput(uint32_t key)
+    {
+
+        if (Keytable[key]=='A') {
+        Teclado[key]=0;              
+            ++c;
+                         } 
+        
+        if(Keytable[key]=='B') {
+        Teclado[key]=0;
+            sp=0;
+            kp=0;
+            ki=0;
+            kd=0;
+                          }
+
+                          
+        if(Keytable[key]=='D'){
+        Teclado[key]=0;
+           p=1;
+                             }   
+
+////////////
+
+            if (c==0){
+                                         
+               sp=sp+Teclado[key];
+                  
+              }
+              
+           if (c==1) {         
+
+               kp=kp+Teclado[key];
+               
+              }
+           if (c==2) {        
+
+               ki=ki+Teclado[key];
+                  
+              }
+           if (c==3) {   
+               
+               kd=kd+Teclado[key];
+                  
+              } 
+
+////////////
+       
+        
+        return 0;
+    }//fin unit32_t
+       
+
+ 
+  int main() {
+      Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13);
+      keypad.CallAfterInput(&cbAfterInput);
+      keypad.Start();
+      
+    lcd.cls();
+    lcd.printf("Sp: %d",sp);
+    lcd.locate(8,0);
+    lcd.printf("Kp: %d",kp);
+    lcd.locate(0,1);
+    lcd.printf("Ki: %d",ki);
+    lcd.locate(8,1);
+    lcd.printf("Kd: %d",kd);
+    lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
+    lcd.locate(0,0);
+    lcd.printf("Sp: %d",sp);
+      
+      while (1) {                                     
+         
+   
+           if (c==0){
+           
+               lcd.locate(3,0);
+               lcd.putc(0xFE);           
+               lcd.locate(4,0);
+               lcd.printf("%d",sp);                           
+                 
+              }
+              
+           if (c==1){
+           
+               lcd.locate(11,0);
+               lcd.putc(0xFE);           
+               lcd.locate(12,0);
+               lcd.printf("%d",kp);                                         
+                             
+              }
+              
+           if (c==2) {   
+                
+               lcd.locate(3,1);
+               lcd.putc(0xFE);               
+               lcd.locate(4,1);
+               lcd.printf("%d",ki);
+
+              }
+           if (c==3) {   
+               
+               lcd.locate(11,1);
+               lcd.putc(0xFE);           
+               lcd.locate(12,1);
+               lcd.printf("%d",kd);
+
+              } 
+                              
+           if(c==4 || c>4){
+                c=0;
+                          } 
+                          
+           if(p==1){
+           c=0;
+           break;     
+               }
+                        
+                                        }
+        
+           
+           lcd.writeCommand(C4);//escribimos un comando segun el manual del modulo LCD para quitar cursor bajo
+           lcd.cls(); //borra la pantalla
+           lcd.printf("   GUARDADOS!"); 
+           wait(2);
+           lcd.cls();
+           lcd.printf(" INICIA EL PID");
+           wait(2);
+           // se imprimen los parches del control  *****************************************
+           
+           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;
+        ji=j*3.3;
+        m=(spi-ji);
+        //n=m*100;
+        ap=kp*m;
+        ai=(ki*m)+ai;
+        
+        ad=kd*(m-mv);
+        h=ap+ai+ad;
+   
+        if (h>999){
+        h=999;
+                   }
+        if (h<0){
+        h=0;
+                   }
+                              
+        g=(h/999);
+                                                       
+        Aout=g;
+        wait(0.22);
+ 
+        
+        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);
+        }
+
+
+        mv=m;
+    } //While           
+           //
+
+          }//int main 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 04 19:29:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file