Juan Salvador Payares Ernesto Guevara

Dependencies:   DebouncedIn FPointer TextLCD keypad mbed

Files at this revision

API Documentation at this revision

Comitter:
payarito32
Date:
Sat Apr 05 02:31:01 2014 +0000
Commit message:
Juan Salvador Payares; Ernesto Guevara

Changed in this revision

DebouncedIn.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/DebouncedIn.lib	Sat Apr 05 02:31:01 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/cmorab/code/DebouncedIn/#dc1131de43e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FPointer.lib	Sat Apr 05 02:31:01 2014 +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	Sat Apr 05 02:31:01 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lcorralesc1/code/TextLCD/#0e0132807662
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keypad.lib	Sat Apr 05 02:31:01 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/yoonghm/code/keypad/#e48ba5b4c497
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 05 02:31:01 2014 +0000
@@ -0,0 +1,284 @@
+//Programa para hacer control PID simple, ingresa parámetros con teclado 4x4. Imprime resultados en LCD 16x2
+
+#include "mbed.h"
+#include "TextLCD.h" 
+#include"keypad.h" //Librería del teclado 4x4
+#include"FPointer.h"  //Librería complementaria para libreria keypad
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5);  // rs, e, d4-d7
+Keypad keypad(PTA2,PTD4,PTD3,PTD7,PTA13,PTD5,PTD0,PTD2); //Entradas del teclado(4r,3r,2r,1r,8,7,6,5)
+
+AnalogIn Vin(PTB0);  //Voltaje de alimentación
+DigitalOut sound(PTC5); //Salida de Audio Digital
+AnalogOut Vout(PTE30); //Marcar la salida analógica
+
+//ASIGNACION DE  VARIABLES
+Timer t;
+int cero;
+int flag;
+int q;
+int k;
+int C1=0x0E;    //configurar el lcd para mostrar el guin bajo
+int C2=0x0C;    //configurar el lcd para QUITAR el guion bajo
+float sp=0;       //set point
+float kp=0;       //ganancia proporcional
+float ki=0;       //ganancia integral
+float kd=0;       //ganancia derivativa
+int ind=0;      //vector de caracteres.
+float err, med, yr, ap, ai, ad, err_v, cycle; //Variable de control PID
+float pid;
+int i;
+
+//MATRIZ DEL TECLADO
+float  Keytable[] = {1,2,3,11,
+                   4,5,6,12,
+                   7,8,9,13,
+                   15,0,16,14};
+                   
+//Se crea una función que incremente los valores
+
+void increment(int j){             
+if(j==0){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+        if (q!=1 && sp<10){
+        sp=ind;
+        q=1;
+        }
+        else{
+         sp=10*sp+ind;
+         }
+         if(sp>999)sp=999;
+        lcd.locate(3,0); lcd.printf("   ");
+        lcd.locate(3,0); lcd.printf("%.0f",sp);
+    }
+else if(j==1){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                }
+        if (q!=1 && kp<10){
+        kp=ind;
+        q=1;
+        }
+        else{
+         kp=10*kp+ind;
+         }
+         if(kp>999)kp=999;
+        lcd.locate(11,0); lcd.printf("   ");
+        lcd.locate(11,0); lcd.printf("%.0f",kp);
+      }
+else if(j==2){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+        if (q!=1 && ki<10){
+        ki=ind;
+        q=1;
+        }
+        else{
+         ki=10*ki+ind;
+         }
+         if(ki>999)ki=999;
+        lcd.locate(3,1); lcd.printf("   ");
+        lcd.locate(3,1); lcd.printf("%.0f",ki);  
+      }
+else{
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+        if (q!=1 && kd<10){
+        kd=ind;
+        q=1;
+        }
+        else{
+         kd=10*kd+ind;
+         }
+         if(kd>999)kd=999;
+        lcd.locate(11,1); lcd.printf("   ");
+        lcd.locate(11,1); lcd.printf("%.0f",kd);
+    }
+    ind=0; cero=0;
+}
+
+uint32_t cbAfterInput(uint32_t index) {
+    ind=Keytable[index];
+    cero=index;
+    return 0;
+}
+
+void def_posicion(int j){
+    if (j==0){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+    lcd.locate(3,0); lcd.printf("%.0f",sp);
+    lcd.locate(3,0); 
+    }
+    else if(j==1){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+    lcd.locate(11,0);   lcd.printf("%.0f",kp);
+    lcd.locate(11,0);   
+    }
+    else if (j==2){
+         for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+    lcd.locate(3,1); lcd.printf("%.0f",ki);
+    lcd.locate(3,1); 
+    }
+    else {
+        for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+    lcd.locate(11,1);   lcd.printf("%.0f",kd);
+    lcd.locate(11,1);  
+    }
+}
+
+//Dado que hay parámetros que no varía en el display en esta parte del código, se crea una función que los mantenga.
+void star_patch1(void){ 
+lcd.cls();
+lcd.locate(8,0);
+lcd.printf("Kp=%.0f",kp);
+lcd.locate(0,1);
+lcd.printf("Ki=%.0f",ki);
+lcd.locate(8,1);
+lcd.printf("Kd=%.0f",kd);
+lcd.writeCommand(C1);   //cursor se vea y sea intermitente
+lcd.locate(0,0); 
+lcd.printf("Sp=%.0f",sp);
+}
+
+void star_patch2(void){  // uso nuevamente función que imprime los caracteres que no van a variar en el display
+lcd.writeCommand(C2);
+lcd.cls();
+lcd.printf("Iniciamos el PID |m|"); 
+wait(2);
+lcd.cls();
+lcd.printf("Er%=f",err);
+lcd.locate(8,0);    lcd.printf("Me=%.0f",med); 
+lcd.locate(0,1);    lcd.printf("Sp=%.0f",sp);
+lcd.locate(8,1);    lcd.printf("Co=%.0f",pid);
+wait(3);
+}
+
+int main(){
+//ini:
+ind=0;
+star_patch1();
+    keypad.CallAfterInput(&cbAfterInput);
+    keypad.Start();
+ini1:
+  if(ind==12){
+    if (k<3) k++;
+    else k=0;
+    def_posicion(k);
+    ind=0;
+    q=0;
+  }
+  if(ind==13){
+       for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                }
+  ind=0;
+  //goto PID;
+  }
+    if(ind==14){
+       for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                }
+  ind=0;
+  }
+  if(ind==15){
+       for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                }
+  ind=0;
+  }
+    if(ind==16){
+       for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                }
+  ind=0;
+  }
+  if(ind==11){
+    for(i=1; i<= 100; ++i){ //ONDA CUADRADA, OSCILACIONES A 10 KHZ.... A VER SI FUNCIONA
+                sound = 0;
+                wait(0.00015);  // Medio ciclo de dureza Arriba
+                sound=1;
+                wait(0.0005); // Medio ciclo Abajo
+                
+                }
+    if (k==0){
+    sp=0;
+    lcd.locate(3,0); lcd.printf("   ");
+    lcd.locate(3,0); lcd.printf("%.0f",sp);
+    }
+    else if(k==1){
+    kp=0;
+    lcd.locate(11,0); lcd.printf("   ");  
+    lcd.locate(11,0); lcd.printf("%.0f",kp);
+    }
+    else if (k==2){
+    ki=0;
+    lcd.locate(3,1); lcd.printf("   ");
+    lcd.locate(3,1); lcd.printf("%.0f",ki);
+    }
+    else {
+    kd=0;
+    lcd.locate(11,1);  lcd.printf("   "); 
+    lcd.locate(11,1);  lcd.printf("%.0f",kd);
+    }
+    q=0; ind=0; 
+  }
+  if (ind!=0 && ind!=12 && ind!=13 && ind!=11 || cero==13 ){
+  increment(k);
+  } 
+  goto ini1;
+  }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Apr 05 02:31:01 2014 +0000
@@ -0,0 +1,1 @@
+http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file