d

Dependencies:   Debounced TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
salvarear
Date:
Thu Dec 12 20:41:26 2013 +0000
Commit message:
d

Changed in this revision

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Thu Dec 12 20:41:26 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/TextLCD.lib	Thu Dec 12 20:41:26 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 12 20:41:26 2013 +0000
@@ -0,0 +1,175 @@
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "TextLCD.h"
+AnalogIn Vin(PTC2);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7  //documentacion de las librerias y disposicion de pines
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DebouncedIn b1(PTC12);  //boton incrementa.
+DebouncedIn b2(PTC13);  //boton decrementa.
+DebouncedIn b3(PTB8);   //boton cambio menu.    
+DebouncedIn b4(PTB9);   //boton reset.
+     
+
+int C1=0x0E; // solo muestra el cursor
+int C2=0x18; // desplaza el cursor a la  izquierda
+int C3=0x1A; // desplaza el cursor derecha
+int C4=0x0C; // quita el  cursor bajo
+int a; 
+int b;
+int kp, ki, kd, sp, err, med, pid, ap, ai, ad, err_v; //revisar antes de la primera tarear(PID)
+
+int main() {
+    lcd.cls();
+    lcd.printf("Sp%d",sp);      //ubicacion de las variables en la pantalla
+    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);
+    lcd.locate(0,0);
+    lcd.printf("Sp%d",sp);
+  
+    while(1) {              //inicio cliclos del pid
+        if (b1.falling()) { // incrementa
+           led1 =!led1;
+           ++a;
+           lcd.locate(6,0);
+           lcd.printf("%d", a);
+        }
+    if (b2.falling()) { //decrementa
+           led2 =!led2;
+           --a;
+           lcd.locate(6,0);
+           lcd.printf("%d", a);
+            }
+     if (b3.falling()) {      
+                                            //botones
+         if (b==0){
+         lcd.locate(2,0);
+         lcd.printf("%d",sp);
+             if (b1.falling()) {                            
+             ++sp;                
+             }
+             if (b2.falling()) {                            
+             --sp;                
+             } 
+       }
+        if (b==1) {                 
+           lcd.locate(10,0);
+           lcd.printf("%d",kp);
+            if (b1.falling()){
+            ++kp;
+             }
+             if (b2.falling()) {                            
+             --kp;
+              }
+          }
+          if (b==2) {
+            lcd.locate(2,1);
+             lcd.printf("%d",ki);
+                  if (b1.falling()){
+                  ++ki;
+                  }
+                  if (b2.falling()){                            
+                  --ki;
+                  }               
+              }
+           if (b==3) {
+               lcd.locate(10,1);
+               lcd.printf("%d",kd);
+                  if (b1.falling()){
+                  ++kd;
+                  }
+                  if (b2.falling()){                            
+                  --kd
+                  else(b==4) {
+                     b=0;
+               }                          
+            }
+           if (b4.falling()){
+           break;                       
+       }       }
+  }                      
+        
+
+           lcd.writeCommand(C4);
+           lcd.cls();      
+           lcd.printf("    Guardando Datos!"); 
+           wait(2);
+           lcd.printf("     Espere....");
+           wait(2);
+           lcd.cls();
+           lcd.printf("Iniciando PID");
+           wait(2);
+          
+           lcd.cls();
+           lcd.printf("Er%d",err);
+           lcd.locate(8,0);
+           lcd.printf("Me%d",med);
+           lcd.locate(0,1);
+           lcd.printf("Sp%d",sp);
+           lcd.locate(8,1);
+           lcd.printf("Co%d",pid);
+           wait(5);
+           
+           void star_patch(void){  //funcion que imprime los caracteres que no van a variar en el display
+            lcd.printf("SP=");
+            lcd.locate(7,0);
+            lcd.printf("Kp=");
+            lcd.locate(0,1);
+            lcd.printf("Ki=");
+            lcd.locate(7,1);
+            lcd.printf("Kd=");
+            lcd.locate(3,0);
+            }
+
+        int main(){
+        star_patch();
+         while(1){
+            if(k==3)k=0;
+            if(salto.read()==0){    
+             def_posicion(k);
+              k++;
+                 }
+             else if(mas.read()==0){
+             incremento(k); 
+             }
+             else if(menos.read()==0){
+              decremento(k);
+             }
+        }
+      }   
+           
+          //calculo del pid
+           
+           while(1) {
+                              
+           err = (sp-med);
+           ap = kp*err;
+           ai =(ki*err)+ai;    
+           
+           ad = kd*(err-err_v); 
+           pid = (ap+ai+ad);
+          
+           if (pid > 999){
+           pid=1000;
+           } 
+           
+           wait(.5);
+           lcd.locate(2,0);
+           lcd.printf("%d",err);
+           lcd.locate(10,0);
+           lcd.printf("%d",med);
+           lcd.locate(2,1);
+           lcd.printf("%d",sp);
+           lcd.locate(10,1);
+           lcd.printf("%d",pid);
+           err_v = err;           
+          
+           }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 12 20:41:26 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file