Tarea4-Versión1. Uso de un encoder para cambiar los parametros de un PID, cada vez que se presiona el botón del encoder se produce un sonido

Dependencies:   QEI TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
juniorACA
Date:
Mon May 12 05:39:20 2014 +0000
Commit message:
Tarea4-V1

Changed in this revision

QEI.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/QEI.lib	Mon May 12 05:39:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon May 12 05:39:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/avallejopo/code/TextLCD/#aba8ab3dde9d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 12 05:39:20 2014 +0000
@@ -0,0 +1,223 @@
+#include "mbed.h"
+#include "QEI.h"
+#include "TextLCD.h"
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+QEI encoder (PTD6, PTD7, PTA17, 624);
+AnalogIn Vin(PTB0);
+PwmOut sonido(PTA12); 
+AnalogOut Vout(PTE30); 
+DigitalIn button3(PTA17);
+
+int C2=0x18; // Desplazamiento Izquierda
+int C3=0x1A; // Desplazamiento Derecha
+int C4=0x0C; // Quitar cursor bajo
+int C1=0x0F;
+int err, med, yr, pid, ap, ai, ad, err_v, cambio=0, diferencia=0;
+int spnum=0,kinum=0,kpnum=0,kdnum=0,pos=1;
+int flagt=0;
+float Dd=10;
+float pp=30;
+float Fi;
+
+
+int main()
+{
+    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);
+
+    while(1)
+    {   diferencia=encoder.getPulses()-cambio;
+        cambio=encoder.getPulses();
+
+        if (diferencia==0)
+        {
+            //no hace nada
+        }
+        else if(diferencia>0)
+        {
+            if(pos==1)
+            {
+                if(spnum+diferencia>=999)
+                {
+                    spnum=999;
+                    lcd.locate(3,0);
+                    lcd.printf("    ");
+                    lcd.locate(3,0);
+                    lcd.printf("%d", spnum);
+                }
+                else
+                {
+                    spnum+=diferencia;
+                    lcd.locate(3,0);
+                    lcd.printf("%d", spnum);
+                }
+            }
+            else if(pos==2)
+            {
+                if(kpnum+diferencia>=999)
+                {
+                    kpnum=999;
+                    lcd.locate(11,0);
+                    lcd.printf("    ");
+                    lcd.locate(11,0);
+                    lcd.printf("%d", kpnum);
+                }
+                else
+                {
+                    kpnum+=diferencia;
+                    lcd.locate(11,0);
+                    lcd.printf("%d", kpnum);
+                }
+            }
+            else if(pos==3)
+            {
+                if(kinum+diferencia>=999)
+                {
+                    kinum=999;
+                    lcd.locate(3,1);
+                    lcd.printf("    ");
+                    lcd.locate(3,1);
+                    lcd.printf("%d", kinum);
+                }
+                else
+                {
+                    kinum+=diferencia;
+                    lcd.locate(3,1);
+                    lcd.printf("%d", kinum);
+                }
+            }
+            else if(pos==4)
+            {
+                if(kdnum+diferencia>=999)
+                {
+                    kdnum=999;
+                    lcd.locate(11,1);
+                    lcd.printf("    ");
+                    lcd.locate(11,1);
+                    lcd.printf("%d", kdnum);
+                }
+                else
+                {
+                    kdnum+=diferencia;
+                    lcd.locate(11,1);
+                    lcd.printf("%d", kdnum);
+                }
+            }
+        }
+        
+        else if(diferencia<0)
+        {
+            if(pos==1)
+            {
+                if(spnum+diferencia<0)
+                {
+                    //No hace nada
+                }
+                else
+                {
+                    spnum+=diferencia;
+                    lcd.locate(3,0);
+                    lcd.printf("    ");
+                    lcd.locate(3,0);
+                    lcd.printf("%d", spnum);
+                }
+            }
+            else if(pos==2)
+            {
+                if(kpnum+diferencia<0)
+                {
+                    //No hace nada
+                }
+                else
+                {
+                    kpnum+=diferencia;
+                    lcd.locate(11,0);
+                    lcd.printf("    ");
+                    lcd.locate(11,0);
+                    lcd.printf("%d", kpnum);
+                }
+            }
+            else if(pos==3)
+            {
+                if(kinum+diferencia<0)
+                {
+                    //No hace nada
+                }
+                else
+                {
+                    kinum+=diferencia;
+                    lcd.locate(3,1);
+                    lcd.printf("    ");
+                    lcd.locate(3,1);
+                    lcd.printf("%d", kinum);
+                }
+            }
+            else if(pos==4)
+            {
+                if(kdnum+diferencia<0)
+                {
+                    //No hace nada
+                }
+                else
+                {
+                    kdnum+=diferencia;
+                    lcd.locate(11,1);
+                    lcd.printf("    ");
+                    lcd.locate(11,1);
+                    lcd.printf("%d", kdnum);
+                }
+            }
+        }
+
+        if (!button3)
+        { Fi=(Dd)*100;
+        pp=(1/Fi);
+        sonido.period(pp);
+            {
+            
+                sonido.write(0.3);;
+                wait(0.1); 
+                sonido=0.0;
+            
+            }
+            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);
+
+        }
+   
+    }
+  }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 12 05:39:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file